// TstCreateCreditsOnStore inserts a new credit in the given store for // every item in the amounts slice. func TstCreateCreditsOnStore(t *testing.T, s *wtxmgr.Store, pkScript []byte, amounts []int64) []wtxmgr.Credit { msgTx := createMsgTx(pkScript, amounts) meta := &wtxmgr.BlockMeta{ Block: wtxmgr.Block{Height: TstInputsBlock}, } rec, err := wtxmgr.NewTxRecordFromMsgTx(msgTx, time.Now()) if err != nil { t.Fatal(err) } if err := s.InsertTx(rec, meta); err != nil { t.Fatal("Failed to create inputs: ", err) } credits := make([]wtxmgr.Credit, len(msgTx.TxOut)) for i := range msgTx.TxOut { if err := s.AddCredit(rec, meta, uint32(i), false); err != nil { t.Fatal("Failed to create inputs: ", err) } credits[i] = wtxmgr.Credit{ OutPoint: wire.OutPoint{ Hash: rec.Hash, Index: uint32(i), }, BlockMeta: *meta, Amount: btcutil.Amount(msgTx.TxOut[i].Value), PkScript: msgTx.TxOut[i].PkScript, } } return credits }
func (tx *changeAwareTx) addSelfToStore(store *wtxmgr.Store) error { rec, err := wtxmgr.NewTxRecordFromMsgTx(tx.MsgTx, time.Now()) if err != nil { return newError(ErrWithdrawalTxStorage, "error constructing TxRecord for storing", err) } if err := store.InsertTx(rec, nil); err != nil { return newError(ErrWithdrawalTxStorage, "error adding tx to store", err) } if tx.changeIdx != -1 { if err = store.AddCredit(rec, nil, uint32(tx.changeIdx), true); err != nil { return newError(ErrWithdrawalTxStorage, "error adding tx credits to store", err) } } return nil }