本文整理匯總了Golang中github.com/btcsuitereleases/btcd/wire.MsgTx.AddTxOut方法的典型用法代碼示例。如果您正苦於以下問題:Golang MsgTx.AddTxOut方法的具體用法?Golang MsgTx.AddTxOut怎麽用?Golang MsgTx.AddTxOut使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/btcsuitereleases/btcd/wire.MsgTx
的用法示例。
在下文中一共展示了MsgTx.AddTxOut方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: addTxOuts
func addTxOuts(msgtx *wire.MsgTx, b balance, hash []byte, blockHeight uint32) error {
anchorHash, err := prependBlockHeight(blockHeight, hash)
if err != nil {
anchorLog.Errorf("ScriptBuilder error: %v\n", err)
}
builder := txscript.NewScriptBuilder()
builder.AddOp(txscript.OP_RETURN)
builder.AddData(anchorHash)
// latest routine from Conformal btcsuite returns 2 parameters, not 1... not sure what to do for people with the old conformal libraries :(
opReturn, err := builder.Script()
msgtx.AddTxOut(wire.NewTxOut(0, opReturn))
if err != nil {
anchorLog.Errorf("ScriptBuilder error: %v\n", err)
}
amount, _ := btcutil.NewAmount(b.unspentResult.Amount)
change := amount - fee
// Check if there are leftover unspent outputs, and return coins back to
// a new address we own.
if change > 0 {
// Spend change.
pkScript, err := txscript.PayToAddrScript(b.address)
if err != nil {
return fmt.Errorf("cannot create txout script: %s", err)
}
msgtx.AddTxOut(wire.NewTxOut(int64(change), pkScript))
}
return nil
}