本文整理汇总了Golang中github.com/btcsuite/btcwallet/wtxmgr.Store.InsertTx方法的典型用法代码示例。如果您正苦于以下问题:Golang Store.InsertTx方法的具体用法?Golang Store.InsertTx怎么用?Golang Store.InsertTx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/btcsuite/btcwallet/wtxmgr.Store
的用法示例。
在下文中一共展示了Store.InsertTx方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TstCreateCreditsOnStore
// 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
}
示例2: addSelfToStore
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
}