本文整理汇总了Golang中github.com/piotrnar/gocoin/lib/btc.Tx.GetLegacySigOpCount方法的典型用法代码示例。如果您正苦于以下问题:Golang Tx.GetLegacySigOpCount方法的具体用法?Golang Tx.GetLegacySigOpCount怎么用?Golang Tx.GetLegacySigOpCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/piotrnar/gocoin/lib/btc.Tx
的用法示例。
在下文中一共展示了Tx.GetLegacySigOpCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DecodeTxSops
func DecodeTxSops(tx *btc.Tx) (s string, missinginp bool, totinp, totout uint64, sigops uint, e error) {
s += fmt.Sprintln("Transaction details (for your information):")
s += fmt.Sprintln(len(tx.TxIn), "Input(s):")
sigops = btc.WITNESS_SCALE_FACTOR * tx.GetLegacySigOpCount()
for i := range tx.TxIn {
s += fmt.Sprintf(" %3d %s", i, tx.TxIn[i].Input.String())
var po *btc.TxOut
inpid := btc.NewUint256(tx.TxIn[i].Input.Hash[:])
if txinmem, ok := network.TransactionsToSend[inpid.BIdx()]; ok {
s += fmt.Sprint(" mempool")
if int(tx.TxIn[i].Input.Vout) >= len(txinmem.TxOut) {
s += fmt.Sprintf(" - Vout TOO BIG (%d/%d)!", int(tx.TxIn[i].Input.Vout), len(txinmem.TxOut))
} else {
po = txinmem.TxOut[tx.TxIn[i].Input.Vout]
}
} else {
po, _ = common.BlockChain.Unspent.UnspentGet(&tx.TxIn[i].Input)
if po != nil {
s += fmt.Sprintf("%8d", po.BlockHeight)
}
}
if po != nil {
ok := script.VerifyTxScript(po.Pk_script, po.Value, i, tx, script.VER_P2SH|script.VER_DERSIG|script.VER_CLTV)
if !ok {
s += fmt.Sprintln("\nERROR: The transacion does not have a valid signature.")
e = errors.New("Invalid signature")
return
}
totinp += po.Value
ads := "???"
if ad := btc.NewAddrFromPkScript(po.Pk_script, common.Testnet); ad != nil {
ads = ad.String()
}
s += fmt.Sprintf(" %15.8f BTC @ %s", float64(po.Value)/1e8, ads)
if btc.IsP2SH(po.Pk_script) {
so := btc.WITNESS_SCALE_FACTOR * btc.GetP2SHSigOpCount(tx.TxIn[i].ScriptSig)
s += fmt.Sprintf(" + %d sigops", so)
sigops += so
}
swo := tx.CountWitnessSigOps(i, po.Pk_script)
if swo > 0 {
s += fmt.Sprintf(" + %d segops", swo)
sigops += swo
}
s += "\n"
} else {
s += fmt.Sprintln(" - UNKNOWN INPUT")
missinginp = true
}
}
s += fmt.Sprintln(len(tx.TxOut), "Output(s):")
for i := range tx.TxOut {
totout += tx.TxOut[i].Value
adr := btc.NewAddrFromPkScript(tx.TxOut[i].Pk_script, common.Testnet)
if adr != nil {
s += fmt.Sprintf(" %15.8f BTC to adr %s\n", float64(tx.TxOut[i].Value)/1e8, adr.String())
} else {
s += fmt.Sprintf(" %15.8f BTC to scr %s\n", float64(tx.TxOut[i].Value)/1e8, hex.EncodeToString(tx.TxOut[i].Pk_script))
}
}
if missinginp {
s += fmt.Sprintln("WARNING: There are missing inputs and we cannot calc input BTC amount.")
s += fmt.Sprintln("If there is somethign wrong with this transaction, you can loose money...")
} else {
s += fmt.Sprintf("All OK: %.8f BTC in -> %.8f BTC out, with %.8f BTC fee\n", float64(totinp)/1e8,
float64(totout)/1e8, float64(totinp-totout)/1e8)
}
s += fmt.Sprintln("ECDSA sig operations : ", sigops)
return
}