本文整理匯總了Golang中github.com/decred/dcrwallet/chain.RPCClient.GetRawTransactionVerbose方法的典型用法代碼示例。如果您正苦於以下問題:Golang RPCClient.GetRawTransactionVerbose方法的具體用法?Golang RPCClient.GetRawTransactionVerbose怎麽用?Golang RPCClient.GetRawTransactionVerbose使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/decred/dcrwallet/chain.RPCClient
的用法示例。
在下文中一共展示了RPCClient.GetRawTransactionVerbose方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: LiveTicketHashes
// LiveTicketHashes returns the hashes of live tickets that have been purchased
// by the wallet.
func (w *Wallet) LiveTicketHashes(rpcClient *chain.RPCClient, includeImmature bool) ([]chainhash.Hash, error) {
// This was mostly copied from an older version of the legacy RPC server
// implementation, hence the overall weirdness, inefficiencies, and the
// direct dependency on the consensus server RPC client.
var blk waddrmgr.BlockStamp
var ticketHashes []chainhash.Hash
var stakeMgrTickets []chainhash.Hash
err := walletdb.View(w.db, func(tx walletdb.ReadTx) error {
txmgrNs := tx.ReadBucket(wtxmgrNamespaceKey)
blk = w.Manager.SyncedTo()
// UnspentTickets collects all the tickets that pay out to a
// public key hash for a public key owned by this wallet.
var err error
ticketHashes, err = w.TxStore.UnspentTickets(txmgrNs, blk.Height,
includeImmature)
if err != nil {
return err
}
// Access the stake manager and see if there are any extra tickets
// there. Likely they were either pruned because they failed to get
// into the blockchain or they are P2SH for some script we own.
stakeMgrTickets, err = w.StakeMgr.DumpSStxHashes()
return err
})
if err != nil {
return nil, err
}
for _, h := range stakeMgrTickets {
if sliceContainsHash(ticketHashes, h) {
continue
}
// Get the raw transaction information from daemon and add
// any relevant tickets. The ticket output is always the
// zeroeth output.
spent, err := rpcClient.GetTxOut(&h, 0, true)
if err != nil {
continue
}
// This returns nil if the output is spent.
if spent == nil {
continue
}
ticketTx, err := rpcClient.GetRawTransactionVerbose(&h)
if err != nil {
continue
}
txHeight := ticketTx.BlockHeight
unconfirmed := (txHeight == 0)
immature := (blk.Height-int32(txHeight) <
int32(w.ChainParams().TicketMaturity))
if includeImmature {
ticketHashes = append(ticketHashes, h)
} else {
if !(unconfirmed || immature) {
ticketHashes = append(ticketHashes, h)
}
}
}
return ticketHashes, nil
}