OSDN Git Service

update wallet-store-interface-batch-dev
authorChengcheng Zhang <943420582@qq.com>
Mon, 24 Jun 2019 18:44:53 +0000 (02:44 +0800)
committerChengcheng Zhang <943420582@qq.com>
Mon, 24 Jun 2019 18:44:53 +0000 (02:44 +0800)
database/wallet_store.go
wallet/indexer.go
wallet/wallet.go
wallet/wallet_test.go

index 59da494..2585d87 100644 (file)
@@ -69,19 +69,27 @@ type WalletStore struct {
 // NewWalletStore create new WalletStore struct
 func NewWalletStore(db dbm.DB) *WalletStore {
        return &WalletStore{
-               DB: db,
+               DB:    db,
+               batch: nil,
        }
 }
 
 // InitBatch initial batch
 func (store *WalletStore) InitBatch() {
+       // if store.batch == nil {
        store.batch = store.DB.NewBatch()
+
+       fmt.Println("InitBatch store.batch: ", store.batch)
+       // }
 }
 
 // CommitBatch commit batch
 func (store *WalletStore) CommitBatch() {
+       fmt.Println("CommitBatch...")
        if store.batch != nil {
+               fmt.Println("CommitBatch not nil...")
                store.batch.Write()
+               // store.batch = store.DB.NewBatch()
        }
 }
 
@@ -146,10 +154,8 @@ func (store *WalletStore) GetAssetDefinition(assetID *bc.AssetID) []byte {
 // SetAssetDefinition set assetID and definition
 func (store *WalletStore) SetAssetDefinition(assetID *bc.AssetID, definition []byte) {
        if store.batch == nil {
-               fmt.Println("SetAssetDefinition... nil")
                store.DB.Set(asset.ExtAssetKey(assetID), definition)
        } else {
-               fmt.Println("SetAssetDefinition... not nil")
                store.batch.Set(asset.ExtAssetKey(assetID), definition)
        }
 }
@@ -226,6 +232,7 @@ func (store *WalletStore) GetStandardUTXO(outid bc.Hash) []byte {
 
 // GetTransaction get tx by tx index
 func (store *WalletStore) GetTransaction(txID string) ([]byte, error) {
+       fmt.Println("GetTransaction... txID: ", txID)
        formatKey := store.DB.Get(calcTxIndexKey(txID))
        if formatKey == nil {
                return nil, errAccntTxIDNotFound
index 0d5f9f0..7fbd590 100644 (file)
@@ -31,8 +31,10 @@ func parseGlobalTxIdx(globalTxIdx []byte) (*bc.Hash, uint64) {
 // when query ,query local first and if have no then query external
 // details see getAliasDefinition
 func saveExternalAssetDefinition(b *types.Block, store database.WalletStorer) {
-       // store.InitBatch()
-       // defer store.CommitBatch()
+       store.InitBatch()
+       defer store.CommitBatch()
+
+       fmt.Println("save asset definition...")
 
        for _, tx := range b.Transactions {
                for _, orig := range tx.Inputs {
@@ -44,6 +46,8 @@ func saveExternalAssetDefinition(b *types.Block, store database.WalletStorer) {
                        }
                }
        }
+
+       // store.CommitBatch()
 }
 
 // Summary is the struct of transaction's input and output summary
index f2c8c58..4cdc440 100644 (file)
@@ -209,6 +209,9 @@ func (w *Wallet) AttachBlock(block *types.Block) error {
                w.status.BestHash = w.status.WorkHash
        }
        err = w.commitWalletInfo()
+
+       // w.store.CommitBatch()
+
        return err
 }
 
index f0ac513..ae3f009 100644 (file)
@@ -119,13 +119,13 @@ func TestWalletUpdate(t *testing.T) {
 
        config.CommonConfig = config.DefaultConfig()
        testDB := dbm.NewDB("testdb", "leveldb", "temp")
-       testStore := database.NewWalletStore(testDB)
        defer func() {
                testDB.Close()
                os.RemoveAll("temp")
        }()
 
        store := database.NewStore(testDB)
+       testStore := database.NewWalletStore(testDB)
        dispatcher := event.NewDispatcher()
        txPool := protocol.NewTxPool(store, dispatcher)