當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Db.FetchTxBySha方法代碼示例

本文整理匯總了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
}
開發者ID:stoiclabs,項目名稱:blockchainr,代碼行數:42,代碼來源:main.go

示例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
}
開發者ID:Nevtep,項目名稱:mscutil,代碼行數:37,代碼來源:address.go


注:本文中的github.com/conformal/btcdb.Db.FetchTxBySha方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。