From c73ba23eb51e8cc8704645486f9ca5b50490b0c9 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 15 Feb 2012 17:49:04 +0100 Subject: gettransaction RPC for non-wallet transactions Works for wallet transactions, memory-pool transaction and block chain transactions. Available for all: * txid * version * locktime * size * coinbase/inputs/outputs * confirmations Available only for wallet transactions: * amount * fee * details * blockindex Available for wallet transactions and block chain transactions: * blockhash * time --- src/main.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 78d84d906..de5460671 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -733,7 +733,31 @@ int CTxIndex::GetDepthInMainChain() const return 1 + nBestHeight - pindex->nHeight; } - +// Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock +bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock) +{ + { + LOCK(cs_main); + { + LOCK(mempool.cs); + if (mempool.exists(hash)) + { + tx = mempool.lookup(hash); + return true; + } + } + CTxDB txdb("r"); + CTxIndex txindex; + if (tx.ReadFromDisk(txdb, COutPoint(hash, 0), txindex)) + { + CBlock block; + if (block.ReadFromDisk(txindex.pos.nFile, txindex.pos.nBlockPos, false)) + hashBlock = block.GetHash(); + return true; + } + } + return false; +} -- cgit v1.2.3