// 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()
}
}
// 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)
}
}
// 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
// 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 {
}
}
}
+
+ // store.CommitBatch()
}
// Summary is the struct of transaction's input and output summary
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)