本文整理汇总了Golang中github.com/conformal/btcwire.MsgTx.AddTxOut方法的典型用法代码示例。如果您正苦于以下问题:Golang MsgTx.AddTxOut方法的具体用法?Golang MsgTx.AddTxOut怎么用?Golang MsgTx.AddTxOut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/conformal/btcwire.MsgTx
的用法示例。
在下文中一共展示了MsgTx.AddTxOut方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_dupTx
//.........这里部分代码省略.........
}
newheight, err := db.InsertBlock(block)
if err != nil {
t.Errorf("failed to insert block %v err %v", height, err)
break out
}
if newheight != height {
t.Errorf("height mismatch expect %v returned %v", height, newheight)
break out
}
newSha, blkid, err := db.NewestSha()
if err != nil {
t.Errorf("failed to obtain latest sha %v %v", height, err)
}
if blkid != height {
t.Errorf("height doe not match latest block height %v %v %v", blkid, height, err)
}
blkSha, _ := block.Sha()
if *newSha != *blkSha {
t.Errorf("Newest block sha does not match freshly inserted one %v %v %v ", newSha, blkSha, err)
}
lastSha = blkSha
}
// genrate a new block based on the last sha
// these block are not verified, so there are a bunch of garbage fields
// in the 'generated' block.
var bh btcwire.BlockHeader
bh.Version = 2
bh.PrevBlock = *lastSha
// Bits, Nonce are not filled in
mblk := btcwire.NewMsgBlock(&bh)
hash, _ := btcwire.NewShaHashFromStr("df2b060fa2e5e9c8ed5eaf6a45c13753ec8c63282b2688322eba40cd98ea067a")
po := btcwire.NewOutPoint(hash, 0)
txI := btcwire.NewTxIn(po, []byte("garbage"))
txO := btcwire.NewTxOut(50000000, []byte("garbageout"))
var tx btcwire.MsgTx
tx.AddTxIn(txI)
tx.AddTxOut(txO)
mblk.AddTransaction(&tx)
blk := btcutil.NewBlock(mblk)
fetchList := []*btcwire.ShaHash{hash}
listReply := db.FetchUnSpentTxByShaList(fetchList)
for _, lr := range listReply {
if lr.Err != nil {
t.Errorf("sha %v spent %v err %v\n", lr.Sha,
lr.TxSpent, lr.Err)
}
}
_, err = db.InsertBlock(blk)
if err != nil {
t.Errorf("failed to insert phony block %v", err)
}
// ok, did it 'spend' the tx ?
listReply = db.FetchUnSpentTxByShaList(fetchList)
for _, lr := range listReply {
if lr.Err != btcdb.TxShaMissing {
t.Errorf("sha %v spent %v err %v\n", lr.Sha,
lr.TxSpent, lr.Err)
}
}
txshalist, _ := blk.TxShas()
for _, txsha := range txshalist {
txReply, err := db.FetchTxBySha(txsha)
if err != nil {
t.Errorf("fully spent lookup %v err %v\n", hash, err)
} else {
for _, lr := range txReply {
if lr.Err != nil {
fmt.Errorf("stx %v spent %v err %v\n", lr.Sha,
lr.TxSpent, lr.Err)
}
}
}
}
t.Logf("Dropping block")
err = db.DropAfterBlockBySha(lastSha)
if err != nil {
t.Errorf("failed to drop spending block %v", err)
}
}