Skip to content

Commit ee11121

Browse files
committed
Add special error for genesis coinbase to gettransaction
1 parent 2ae7cf8 commit ee11121

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)