}
// SetTransaction set raw transaction by block height and tx position
-func (store *WalletStore) SetTransaction(height uint64, position uint32, txID string, rawTx []byte) {
+func (store *WalletStore) SetTransaction(height uint64, tx *query.AnnotatedTx) error {
batch := store.walletDB.NewBatch()
if store.batch != nil {
batch = store.batch
}
- batch.Set(calcAnnotatedKey(formatKey(height, position)), rawTx)
- batch.Set(calcTxIndexKey(txID), []byte(formatKey(height, position)))
+ rawTx, err := json.Marshal(tx)
+ if err != nil {
+ return err
+ }
+ batch.Set(calcAnnotatedKey(formatKey(height, tx.Position)), rawTx)
+ batch.Set(calcTxIndexKey(tx.ID.String()), []byte(formatKey(height, tx.Position)))
if store.batch == nil {
batch.Write()
}
+ return nil
}
// DeleteUnconfirmedTransaction delete unconfirmed tx by txID
// indexTransactions saves all annotated transactions to the database.
func (w *Wallet) indexTransactions(b *types.Block, txStatus *bc.TransactionStatus, annotatedTxs []*query.AnnotatedTx) error {
for _, tx := range annotatedTxs {
- rawTx, err := json.Marshal(tx)
- if err != nil {
- log.WithFields(log.Fields{"module": logModule, "err": err}).Error("inserting annotated_txs to db")
+ if err := w.store.SetTransaction(b.Height, tx); err != nil {
return err
}
-
- w.store.SetTransaction(b.Height, tx.Position, tx.ID.String(), rawTx)
w.store.DeleteUnconfirmedTransaction(tx.ID.String())
}
GetControlProgram(common.Hash) (*acc.CtrlProgram, error)
GetAccountByAccountID(string) (*acc.Account, error)
DeleteTransactions(uint64)
- SetTransaction(uint64, uint32, string, []byte)
+ SetTransaction(height uint64, tx *query.AnnotatedTx) error
DeleteUnconfirmedTransaction(string)
SetGlobalTransactionIndex(string, *bc.Hash, uint64)
GetStandardUTXO(bc.Hash) []byte