rpc: improve error message in submitblock

split previous conditional statement into 2
check that block both starts with and contains a coinbase transaction
This commit is contained in:
Dakoda Greaves 2021-10-31 16:58:19 -07:00
parent 097d87df2f
commit 27ac4a1e79
No known key found for this signature in database
GPG key ID: E9E1D8252D569306

View file

@ -787,8 +787,14 @@ UniValue submitblock(const JSONRPCRequest& request)
if (!DecodeHexBlk(block, request.params[0].get_str())) if (!DecodeHexBlk(block, request.params[0].get_str()))
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed"); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
if (block.vtx.empty() || !block.vtx[0]->IsCoinBase()) { if (block.vtx.empty())
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block does not start with a coinbase"); {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block does not contain a coinbase transaction");
}
if (!block.vtx[0]->IsCoinBase())
{
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block does not start with a valid coinbase transaction");
} }
uint256 hash = block.GetHash(); uint256 hash = block.GetHash();