• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Revision609506975308640765915dd01ec39321f0dcdac9 (tree)
Time2019-06-22 01:53:00
AuthorChengcheng Zhang <943420582@qq.c...>
CommiterChengcheng Zhang

Log Message

pass ci

Change Summary

Incremental Difference

--- a/wallet/store.go
+++ b/wallet/store.go
@@ -66,6 +66,7 @@ func (store *LevelDBStore) GetAssetDefinitionByAssetID(assetID *bc.AssetID) []by
6666 func (store *LevelDBStore) SetAssetDefinition(assetID *bc.AssetID, definition []byte) {
6767 batch := store.DB.NewBatch()
6868 batch.Set(asset.ExtAssetKey(assetID), definition)
69+ batch.Write()
6970 }
7071
7172 // GetRawProgramByAccountHash get raw program by account hash
@@ -91,30 +92,35 @@ func (store *LevelDBStore) DeleteTransactionByHeight(height uint64) {
9192 }
9293 batch.Delete(txIter.Key())
9394 }
95+ batch.Write()
9496 }
9597
9698 // SetRawTransaction set raw transaction by block height and tx position
9799 func (store *LevelDBStore) SetRawTransaction(height uint64, position uint32, rawTx []byte) {
98100 batch := store.DB.NewBatch()
99101 batch.Set(calcAnnotatedKey(formatKey(height, position)), rawTx)
102+ batch.Write()
100103 }
101104
102105 // SetHeightAndPostion set block height and tx position according to tx ID
103106 func (store *LevelDBStore) SetHeightAndPostion(txID string, height uint64, position uint32) {
104107 batch := store.DB.NewBatch()
105108 batch.Set(calcTxIndexKey(txID), []byte(formatKey(height, position)))
109+ batch.Write()
106110 }
107111
108112 // DeleteUnconfirmedTxByTxID delete unconfirmed tx by txID
109113 func (store *LevelDBStore) DeleteUnconfirmedTxByTxID(txID string) {
110114 batch := store.DB.NewBatch()
111115 batch.Delete(calcUnconfirmedTxKey(txID))
116+ batch.Write()
112117 }
113118
114119 // SetGlobalTxIndex set global tx index by blockhash and position
115120 func (store *LevelDBStore) SetGlobalTxIndex(globalTxID string, blockHash *bc.Hash, position uint64) {
116121 batch := store.DB.NewBatch()
117122 batch.Set(calcGlobalTxIndexKey(globalTxID), calcGlobalTxIndex(blockHash, position))
123+ batch.Write()
118124 }
119125
120126 // GetStandardUTXOByID get standard utxo by id
@@ -184,24 +190,28 @@ func (store *LevelDBStore) SetUnconfirmedTx(txID string, rawTx []byte) {
184190 func (store *LevelDBStore) DeleteStardardUTXOByOutputID(outputID bc.Hash) {
185191 batch := store.DB.NewBatch()
186192 batch.Delete(account.StandardUTXOKey(outputID))
193+ batch.Write()
187194 }
188195
189196 // DeleteContractUTXOByOutputID delete contract utxo by outputID
190197 func (store *LevelDBStore) DeleteContractUTXOByOutputID(outputID bc.Hash) {
191198 batch := store.DB.NewBatch()
192199 batch.Delete(account.ContractUTXOKey(outputID))
200+ batch.Write()
193201 }
194202
195203 // SetStandardUTXO set standard utxo
196204 func (store *LevelDBStore) SetStandardUTXO(outputID bc.Hash, data []byte) {
197205 batch := store.DB.NewBatch()
198206 batch.Set(account.StandardUTXOKey(outputID), data)
207+ batch.Write()
199208 }
200209
201210 // SetContractUTXO set standard utxo
202211 func (store *LevelDBStore) SetContractUTXO(outputID bc.Hash, data []byte) {
203212 batch := store.DB.NewBatch()
204213 batch.Set(account.ContractUTXOKey(outputID), data)
214+ batch.Write()
205215 }
206216
207217 // GetWalletInfo get wallet information
--- a/wallet/unconfirmed.go
+++ b/wallet/unconfirmed.go
@@ -51,8 +51,6 @@ func (w *Wallet) GetUnconfirmedTxs(accountID string) ([]*query.AnnotatedTx, erro
5151 return nil, err
5252 }
5353
54- fmt.Println("GetUnconfirmedTxs len(annotatedTxs):", len(annotatedTxs))
55-
5654 newAnnotatedTxs := []*query.AnnotatedTx{}
5755 for _, annotatedTx := range annotatedTxs {
5856 if accountID == "" || findTransactionsByAccount(annotatedTx, accountID) {
@@ -62,7 +60,6 @@ func (w *Wallet) GetUnconfirmedTxs(accountID string) ([]*query.AnnotatedTx, erro
6260 }
6361
6462 sort.Sort(SortByTimestamp(newAnnotatedTxs))
65- fmt.Println("GetUnconfirmedTxs:", len(newAnnotatedTxs))
6663 return newAnnotatedTxs, nil
6764 }
6865
@@ -153,7 +150,6 @@ func (w *Wallet) saveUnconfirmedTx(tx *types.Tx) error {
153150 }
154151
155152 func (w *Wallet) delExpiredTxs() error {
156- fmt.Println("delExpiredTxs...")
157153 AnnotatedTx, err := w.GetUnconfirmedTxs("")
158154 if err != nil {
159155 return err
--- a/wallet/wallet_test.go
+++ b/wallet/wallet_test.go
@@ -2,7 +2,6 @@ package wallet
22
33 import (
44 "encoding/json"
5- "fmt"
65 "io/ioutil"
76 "os"
87 "reflect"
@@ -330,10 +329,8 @@ func TestMemPoolTxQueryLoop(t *testing.T) {
330329 go w.memPoolTxQueryLoop()
331330 w.eventDispatcher.Post(protocol.TxMsgEvent{TxMsg: &protocol.TxPoolMsg{TxDesc: &protocol.TxDesc{Tx: tx}, MsgType: protocol.MsgNewTx}})
332331 time.Sleep(time.Millisecond * 10)
333- if txxx, err := w.GetUnconfirmedTxByTxID(tx.ID.String()); err != nil {
332+ if _, err := w.GetUnconfirmedTxByTxID(tx.ID.String()); err != nil {
334333 t.Fatal("dispatch new tx msg error:", err)
335- } else {
336- fmt.Println("txxx:", txxx)
337334 }
338335 w.eventDispatcher.Post(protocol.TxMsgEvent{TxMsg: &protocol.TxPoolMsg{TxDesc: &protocol.TxDesc{Tx: tx}, MsgType: protocol.MsgRemoveTx}})
339336 time.Sleep(time.Millisecond * 10)
@@ -342,8 +339,6 @@ func TestMemPoolTxQueryLoop(t *testing.T) {
342339 t.Fatal("get unconfirmed tx error:", err)
343340 }
344341
345- fmt.Println("len(txs) is:", len(txs))
346-
347342 if len(txs) != 0 {
348343 t.Fatal("dispatch remove tx msg error")
349344 }
Show on old repository browser