本文整理汇总了Golang中github.com/conformal/btcdb.Db.FetchTxBySha方法的典型用法代码示例。如果您正苦于以下问题:Golang Db.FetchTxBySha方法的具体用法?Golang Db.FetchTxBySha怎么用?Golang Db.FetchTxBySha使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/conformal/btcdb.Db
的用法示例。
在下文中一共展示了Db.FetchTxBySha方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: fetch
func fetch(db btcdb.Db, rd *rData) error {
sha, err := db.FetchBlockShaByHeight(rd.in.H)
if err != nil {
return fmt.Errorf("failed FetchBlockShaByHeight(%v): %v\n", rd.in.H, err)
}
blk, err := db.FetchBlockBySha(sha)
if err != nil {
return fmt.Errorf("failed FetchBlockBySha(%v) - h %v: %v\n", sha, rd.in.H, err)
}
tx := blk.Transactions()[rd.in.Tx]
rd.blkSha = sha
rd.blk = blk
rd.tx = tx
rd.txInIndex = rd.in.TxIn
rd.txIn = tx.MsgTx().TxIn[rd.in.TxIn]
txPrevList, err := db.FetchTxBySha(&rd.txIn.PreviousOutPoint.Hash)
if err != nil {
return fmt.Errorf("failed FetchTxBySha(%v) - h %v: %v\n",
rd.txIn.PreviousOutPoint.Hash, rd.in.H, err)
}
if len(txPrevList) != 1 {
return fmt.Errorf("not single FetchTxBySha(%v) - h %v: %v\n",
rd.txIn.PreviousOutPoint.Hash, rd.in.H, len(txPrevList))
}
blkPrev, err := db.FetchBlockBySha(txPrevList[0].BlkSha)
if err != nil {
return fmt.Errorf("failed prev FetchBlockBySha(%v) - h %v: %v\n",
txPrevList[0].BlkSha, rd.in.H, err)
}
rd.txPrev = txPrevList[0]
rd.txPrevOutIndex = rd.txIn.PreviousOutPoint.Index
rd.txPrevOut = rd.txPrev.Tx.TxOut[rd.txPrevOutIndex]
rd.blkPrev = blkPrev
return nil
}
示例2: FindSender
func FindSender(txIns []*btcwire.TxIn, btcdb btcdb.Db) (Address, error) {
inputs := make(map[string]int64)
for _, txIn := range txIns {
op := txIn.PreviousOutpoint
hash := op.Hash
index := op.Index
transactions, err := btcdb.FetchTxBySha(&hash)
if err != nil {
return Address{}, err
}
// TODO: During initial sync unconfirmed transactions might be picked up
// We should prevent that from showing up but this is a work around
// When a transaction is not in the database yet
if len(transactions) == 0 {
continue
}
previousOutput := transactions[0].Tx.TxOut[index]
// The largest contributor receives the Mastercoins, so add multiple address values together
address, _ := GetAddrs(previousOutput.PkScript)
inputs[address[0].Addr] += previousOutput.Value
}
// Decide which input has the most value so we know who is sending this transaction
var highest int64
var highestAddress string
for k, v := range inputs {
if v > highest {
highest = v
highestAddress = k
}
}
return Address{Addr: highestAddress}, nil
}