本文整理汇总了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
}
开发者ID:FactomProject,项目名称:FactomCode,代码行数:33,代码来源:anchor.go
示例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
}
开发者ID:jakeporter,项目名称:FactomCode,代码行数:31,代码来源:anchor.go
示例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
}
开发者ID:FactomProject,项目名称:FactomCode,代码行数:17,代码来源:anchor.go
注:本文中的github.com/btcsuitereleases/btcd/wire.MsgTx类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论