本文整理匯總了Golang中github.com/decred/dcrrpcclient.Client.GetRawTransaction方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.GetRawTransaction方法的具體用法?Golang Client.GetRawTransaction怎麽用?Golang Client.GetRawTransaction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/decred/dcrrpcclient.Client
的用法示例。
在下文中一共展示了Client.GetRawTransaction方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: traceDevPremineOuts
// traceDevPremineOuts returns a list of outpoints that are part of the dev
// premine coins and are ancestors of the inputs to the passed transaction hash.
func traceDevPremineOuts(client *dcrrpcclient.Client, txHash *chainhash.Hash) ([]wire.OutPoint, error) {
// Trace the lineage of all inputs to the provided transaction back to
// the coinbase outputs that generated them and add those outpoints to
// a list. Also, keep track of all of the processed transactions in
// order to avoid processing duplicates.
knownCoinbases := make(map[chainhash.Hash]struct{})
processedHashes := make(map[chainhash.Hash]struct{})
coinbaseOuts := make([]wire.OutPoint, 0, 10)
processOuts := []wire.OutPoint{{Hash: *txHash}}
for len(processOuts) > 0 {
// Grab the first outpoint to process and skip it if it has
// already been traced.
outpoint := processOuts[0]
processOuts = processOuts[1:]
if _, exists := processedHashes[outpoint.Hash]; exists {
if _, exists := knownCoinbases[outpoint.Hash]; exists {
coinbaseOuts = append(coinbaseOuts, outpoint)
}
continue
}
processedHashes[outpoint.Hash] = struct{}{}
// Request the transaction for the outpoint from the server.
tx, err := client.GetRawTransaction(&outpoint.Hash)
if err != nil {
return nil, fmt.Errorf("failed to get transaction %v: %v",
&outpoint.Hash, err)
}
// Add the outpoint to the coinbase outputs list when it is part
// of a coinbase transaction. Also, keep track of the fact the
// transaction is a coinbase to use when avoiding duplicate
// checks.
if blockchain.IsCoinBase(tx) {
knownCoinbases[outpoint.Hash] = struct{}{}
coinbaseOuts = append(coinbaseOuts, outpoint)
continue
}
// Add the inputs to the transaction to the list of transactions
// to load and continue tracing.
//
// However, skip the first input to stake generation txns since
// they are creating new coins. The remaining inputs to a
// stake generation transaction still need to be traced since
// they represent the coins that purchased the ticket.
txIns := tx.MsgTx().TxIn
isSSGen, _ := stake.IsSSGen(tx.MsgTx())
if isSSGen {
txIns = txIns[1:]
}
for _, txIn := range txIns {
processOuts = append(processOuts, txIn.PreviousOutPoint)
}
}
// Add any of the outputs that are dev premine outputs to a list.
var devPremineOuts []wire.OutPoint
for _, coinbaseOut := range coinbaseOuts {
if isDevPremineOut(coinbaseOut) {
devPremineOuts = append(devPremineOuts, coinbaseOut)
}
}
return devPremineOuts, nil
}