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


Golang RPCClient.GetTxOut方法代碼示例

本文整理匯總了Golang中github.com/decred/dcrwallet/chain.RPCClient.GetTxOut方法的典型用法代碼示例。如果您正苦於以下問題:Golang RPCClient.GetTxOut方法的具體用法?Golang RPCClient.GetTxOut怎麽用?Golang RPCClient.GetTxOut使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/decred/dcrwallet/chain.RPCClient的用法示例。


在下文中一共展示了RPCClient.GetTxOut方法的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
}
開發者ID:jcvernaleo,項目名稱:btcwallet,代碼行數:71,代碼來源:tickets.go


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