Skip to content

Commit 288deac

Browse files
committed
Merge #12278: Add special error for genesis coinbase to getrawtransaction
ee11121 Add special error for genesis coinbase to gettransaction (MeshCollider) Pull request description: Suggested by sipa here: https://botbot.me/freenode/bitcoin-core-dev/2018-01-23/?msg=96069825&page=2 Just adds a special error message for the genesis block coinbase transaction when using `getrawtransaction` Tree-SHA512: cd102c7983ec5457b299bff4b6db747d339fda157933a3ac54aec26b1e48b115aa68c1c9e6cb7a916f15c7786273ab558b2b20ab9768544d211e0ae9d1480e34
2 parents 7cf1aea + ee11121 commit 288deac

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
147147
uint256 hash = ParseHashV(request.params[0], "parameter 1");
148148
CBlockIndex* blockindex = nullptr;
149149

150+
if (hash == Params().GenesisBlock().hashMerkleRoot) {
151+
// Special exception for the genesis block coinbase transaction
152+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "The genesis block coinbase is not considered an ordinary transaction and cannot be retrieved");
153+
}
154+
150155
// Accept either a bool (true) or a num (>=1) to indicate verbose output.
151156
bool fVerbose = false;
152157
if (!request.params[1].isNull()) {

test/functional/rpc_rawtransaction.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ def run_test(self):
5959
self.nodes[0].generate(5)
6060
self.sync_all()
6161

62+
# Test getrawtransaction on genesis block coinbase returns an error
63+
block = self.nodes[0].getblock(self.nodes[0].getblockhash(0))
64+
assert_raises_rpc_error(-5, "The genesis block coinbase is not considered an ordinary transaction", self.nodes[0].getrawtransaction, block['merkleroot'])
65+
6266
# Test `createrawtransaction` required parameters
6367
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction)
6468
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction, [])

0 commit comments

Comments
 (0)