Skip to content

Commit

Permalink
Merge bitcoin#12278: Add special error for genesis coinbase to getraw…
Browse files Browse the repository at this point in the history
…transaction

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
  • Loading branch information
laanwj authored and PastaPastaPasta committed Jan 22, 2020
1 parent db98906 commit 49a11f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/rpc/rawtransaction.cpp
Expand Up @@ -179,6 +179,11 @@ UniValue getrawtransaction(const JSONRPCRequest& request)

uint256 hash = ParseHashV(request.params[0], "parameter 1");

if (hash == Params().GenesisBlock().hashMerkleRoot) {
// Special exception for the genesis block coinbase transaction
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "The genesis block coinbase is not considered an ordinary transaction and cannot be retrieved");
}

// Accept either a bool (true) or a num (>=1) to indicate verbose output.
bool fVerbose = false;
if (!request.params[1].isNull()) {
Expand Down
4 changes: 4 additions & 0 deletions test/functional/rawtransactions.py
Expand Up @@ -58,6 +58,10 @@ def run_test(self):
self.nodes[0].generate(5)
self.sync_all()

# Test getrawtransaction on genesis block coinbase returns an error
block = self.nodes[0].getblock(self.nodes[0].getblockhash(0))
assert_raises_rpc_error(-5, "The genesis block coinbase is not considered an ordinary transaction", self.nodes[0].getrawtransaction, block['merkleroot'])

# Test `createrawtransaction` required parameters
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction)
assert_raises_rpc_error(-1, "createrawtransaction", self.nodes[0].createrawtransaction, [])
Expand Down

0 comments on commit 49a11f5

Please sign in to comment.