• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Revision3c99f69fe2631cc0c8063db1a58f5bcbd8c62e6e (tree)
Time2019-06-25 03:44:53
AuthorChengcheng Zhang <943420582@qq.c...>
CommiterChengcheng Zhang

Log Message

update

Change Summary

Incremental Difference

--- a/database/wallet_store.go
+++ b/database/wallet_store.go
@@ -69,19 +69,27 @@ type WalletStore struct {
6969 // NewWalletStore create new WalletStore struct
7070 func NewWalletStore(db dbm.DB) *WalletStore {
7171 return &WalletStore{
72- DB: db,
72+ DB: db,
73+ batch: nil,
7374 }
7475 }
7576
7677 // InitBatch initial batch
7778 func (store *WalletStore) InitBatch() {
79+ // if store.batch == nil {
7880 store.batch = store.DB.NewBatch()
81+
82+ fmt.Println("InitBatch store.batch: ", store.batch)
83+ // }
7984 }
8085
8186 // CommitBatch commit batch
8287 func (store *WalletStore) CommitBatch() {
88+ fmt.Println("CommitBatch...")
8389 if store.batch != nil {
90+ fmt.Println("CommitBatch not nil...")
8491 store.batch.Write()
92+ // store.batch = store.DB.NewBatch()
8593 }
8694 }
8795
@@ -146,10 +154,8 @@ func (store *WalletStore) GetAssetDefinition(assetID *bc.AssetID) []byte {
146154 // SetAssetDefinition set assetID and definition
147155 func (store *WalletStore) SetAssetDefinition(assetID *bc.AssetID, definition []byte) {
148156 if store.batch == nil {
149- fmt.Println("SetAssetDefinition... nil")
150157 store.DB.Set(asset.ExtAssetKey(assetID), definition)
151158 } else {
152- fmt.Println("SetAssetDefinition... not nil")
153159 store.batch.Set(asset.ExtAssetKey(assetID), definition)
154160 }
155161 }
@@ -226,6 +232,7 @@ func (store *WalletStore) GetStandardUTXO(outid bc.Hash) []byte {
226232
227233 // GetTransaction get tx by tx index
228234 func (store *WalletStore) GetTransaction(txID string) ([]byte, error) {
235+ fmt.Println("GetTransaction... txID: ", txID)
229236 formatKey := store.DB.Get(calcTxIndexKey(txID))
230237 if formatKey == nil {
231238 return nil, errAccntTxIDNotFound
--- a/wallet/indexer.go
+++ b/wallet/indexer.go
@@ -31,8 +31,10 @@ func parseGlobalTxIdx(globalTxIdx []byte) (*bc.Hash, uint64) {
3131 // when query ,query local first and if have no then query external
3232 // details see getAliasDefinition
3333 func saveExternalAssetDefinition(b *types.Block, store database.WalletStorer) {
34- // store.InitBatch()
35- // defer store.CommitBatch()
34+ store.InitBatch()
35+ defer store.CommitBatch()
36+
37+ fmt.Println("save asset definition...")
3638
3739 for _, tx := range b.Transactions {
3840 for _, orig := range tx.Inputs {
@@ -44,6 +46,8 @@ func saveExternalAssetDefinition(b *types.Block, store database.WalletStorer) {
4446 }
4547 }
4648 }
49+
50+ // store.CommitBatch()
4751 }
4852
4953 // Summary is the struct of transaction's input and output summary
--- a/wallet/wallet.go
+++ b/wallet/wallet.go
@@ -209,6 +209,9 @@ func (w *Wallet) AttachBlock(block *types.Block) error {
209209 w.status.BestHash = w.status.WorkHash
210210 }
211211 err = w.commitWalletInfo()
212+
213+ // w.store.CommitBatch()
214+
212215 return err
213216 }
214217
--- a/wallet/wallet_test.go
+++ b/wallet/wallet_test.go
@@ -119,13 +119,13 @@ func TestWalletUpdate(t *testing.T) {
119119
120120 config.CommonConfig = config.DefaultConfig()
121121 testDB := dbm.NewDB("testdb", "leveldb", "temp")
122- testStore := database.NewWalletStore(testDB)
123122 defer func() {
124123 testDB.Close()
125124 os.RemoveAll("temp")
126125 }()
127126
128127 store := database.NewStore(testDB)
128+ testStore := database.NewWalletStore(testDB)
129129 dispatcher := event.NewDispatcher()
130130 txPool := protocol.NewTxPool(store, dispatcher)
131131
Show on old repository browser