Transactions

是否有用於檢索給定地址的所有交易的 JSON-RPC 方法?

  • October 30, 2013

我的意思是類似於 listtransactions 方法,但帶有參數。

這會很好,但是,不,沒有辦法做到這一點。積累此資訊的最簡單方法是呼叫listtransactionslistunspent獲取您帳戶中的交易列表。

收到列表後,篩選所需資訊。值得一提的是listunspentRPC 呼叫。如果您只對構成目前餘額的傳入交易感興趣,這可以減少大量返回的數據。

您無法通過 RPC 命令使用 bitcoind 執行此操作,但 Internet 上有可用的工具可以為您執行此操作。例如,blockexplorer有一個專門用於此目的的查詢。如果您想了解它是如何完成的,請查看app_stats.inc的第 724 行:

// This RELIES on the fact that only address transactions will be sent/received
$result = SQL("SELECT encode(blocks.hash, 'hex') AS block, 
                     encode(transactions.hash, 'hex') AS tx, 
                     blocks.number AS blocknum, 
                     blocks.time AT TIME ZONE 'UTC' AS time, 
                     transactions.id AS tid, 
                     transactions.raw AS rawtx

              FROM inputs JOIN transactions ON (inputs.tx = transactions.hash) 
                          JOIN blocks ON (inputs.block = blocks.hash)

              WHERE inputs.type = 'Address' AND 
                    blocks.number>$1 AND inputs.hash160 IN ($addresses)

              UNION 

              SELECT encode(blocks.hash, 'hex') AS block, 
                     encode(transactions.hash, 'hex') AS tx, 
                     blocks.number AS blocknum, 
                     blocks.time AT TIME ZONE 'UTC' AS time, 
                     transactions.id AS tid, 
                     transactions.raw AS rawtx

              FROM outputs JOIN transactions ON (outputs.tx = transactions.hash) 
                           JOIN blocks ON (outputs.block = blocks.hash)

              WHERE outputs.type = 'Address' AND 
                    blocks.number>$1 AND 
                    outputs.hash160 IN ($addresses) 

              ORDER BY tid;", $blocklimit);

引用自:https://bitcoin.stackexchange.com/questions/14170