Skip to content

Commit 1f346fb

Browse files
committed
bcli: replace magic numbers with constants
1 parent 3a73064 commit 1f346fb

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

plugins/bcli.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@
1313
#include <plugins/libplugin.h>
1414
#include <unistd.h>
1515

16+
/* Bitcoin Core RPC error code for duplicate transaction */
1617
#define RPC_TRANSACTION_ALREADY_IN_CHAIN -27
1718

19+
/* Hex-encoded SHA256 block hash length (32 bytes = 64 hex chars) */
20+
#define BLOCK_HASH_HEX_LEN 64
21+
22+
/* Bitcoin Core version 23.0.0 introduced getblockfrompeer RPC */
23+
#define BITCOIND_VERSION_GETBLOCKFROMPEER 230000
24+
1825
struct bitcoind {
1926
/* eg. "bitcoin-cli" */
2027
char *cli;
@@ -348,7 +355,7 @@ static struct command_result *getrawblockbyheight(struct command *cmd,
348355
}
349356

350357
strip_trailing_whitespace(res->output, res->output_len);
351-
if (strlen(res->output) != 64)
358+
if (strlen(res->output) != BLOCK_HASH_HEX_LEN)
352359
return command_err(cmd, res, "bad JSON: bad blockhash");
353360

354361
block_hash = tal_strdup(cmd, res->output);
@@ -382,7 +389,7 @@ static struct command_result *getrawblockbyheight(struct command *cmd,
382389
}
383390

384391
/* Try fetching from peers if bitcoind >= 23.0.0 */
385-
if (bitcoind->version >= 230000) {
392+
if (bitcoind->version >= BITCOIND_VERSION_GETBLOCKFROMPEER) {
386393
if (!peers)
387394
peers = get_fullnode_peers(cmd, cmd);
388395

0 commit comments

Comments
 (0)