本文整理汇总了Golang中github.com/btcsuitereleases/btcd/wire.MsgTx类的典型用法代码示例。如果您正苦于以下问题:Golang MsgTx类的具体用法?Golang MsgTx怎么用?Golang MsgTx使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MsgTx类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例2: addTxIn
func addTxIn(msgtx *wire.MsgTx, b balance) error {
output := b.unspentResult
anchorLog.Info("unspentResult: %#v\n", output)
prevTxHash, err := wire.NewShaHashFromStr(output.TxID)
if err != nil {
return fmt.Errorf("cannot get sha hash from str: %s", err)
}
outPoint := wire.NewOutPoint(prevTxHash, output.Vout)
msgtx.AddTxIn(wire.NewTxIn(outPoint, nil))
// OnRedeemingTx
err = dclient.NotifySpent([]*wire.OutPoint{outPoint})
if err != nil {
anchorLog.Error("NotifySpent err: ", err.Error())
}
subscript, err := hex.DecodeString(output.ScriptPubKey)
if err != nil {
return fmt.Errorf("cannot decode scriptPubKey: %s", err)
}
sigScript, err := txscript.SignatureScript(msgtx, 0, subscript,
txscript.SigHashAll, b.wif.PrivKey, true) //.ToECDSA(), true)
if err != nil {
return fmt.Errorf("cannot create scriptSig: %s", err)
}
msgtx.TxIn[0].SignatureScript = sigScript
return nil
}
示例3: sendRawTransaction
func sendRawTransaction(msgtx *wire.MsgTx) (*wire.ShaHash, error) {
//anchorLog.Debug("sendRawTransaction: msgTx=", spew.Sdump(msgtx))
buf := bytes.Buffer{}
buf.Grow(msgtx.SerializeSize())
if err := msgtx.BtcEncode(&buf, wire.ProtocolVersion); err != nil {
return nil, err
}
// use rpc client for btcd here for better callback info
// this should not require wallet to be unlocked
shaHash, err := dclient.SendRawTransaction(msgtx, false)
if err != nil {
return nil, fmt.Errorf("failed in rpcclient.SendRawTransaction: %s", err)
}
anchorLog.Info("btc txHash returned: ", shaHash) // new tx hash
return shaHash, nil
}