When using bitcoin-cli
command gettxout
, the program does not return an error if the utxo queried doesn’t exist. I initially found this behavior a bit confusing, as in command line contexts a command not returning anything usually means “it worked”. Similar calls like getmempoolentry
will return Transaction not in mempool
errors, so I expected something like that from gettxout
.
Expected behavior
(maybe this is more like “desired” behavior) How about something like:
0user@computer:~$ bitcoin-cli gettxout 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098 1
1error code: -5
2error message:
3Transaction output not found
4user@computer:~$
Actual behavior
0user@computer:~$ bitcoin-cli gettxout 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098 0
1{
2 "bestblock": "00000000000000000000b2320e348d60a5eb0532a1fe67bddd197077f7782637",
3 "confirmations": 623664,
4 "value": 50.00000000,
5 "scriptPubKey": {
6 "asm": "0496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858ee OP_CHECKSIG",
7 "hex": "410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac",
8 "type": "pubkey"
9 },
10 "coinbase": true
11}
12user@computer:~$ bitcoin-cli gettxout 0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098 1
13user@computer:~$
To reproduce
Query any non-exsistent utxo with gettxout
. Nothing happens, and the program returns with no error.
System information
Ubuntu 18.04.3 LTS, Bitcoin Core 0.19.01
Fix?
Is there a reason why either the RPC call itself or bitcoin-cli
doesn’t return an error in this case? If so, or if it’s complicated to fix, then the lack of an error message isn’t not a big deal, and I can close this or leave it around as a “yeah maybe should fix that someday”. If it’s just an omission however, I’d be happy to open a PR changing it to return some kind of error message.