| 584 | } |
| 585 | |
| 586 | static struct command_result *process_getblockhash(struct bitcoin_cli *bcli) |
| 587 | { |
| 588 | struct getrawblock_stash *stash = bcli->stash; |
| 589 | |
| 590 | /* If it failed with error 8, give an empty response. */ |
| 591 | if (bcli->exitstatus && *bcli->exitstatus != 0) { |
| 592 | /* Other error means we have to retry. */ |
| 593 | if (*bcli->exitstatus != 8) |
| 594 | return NULL; |
| 595 | return getrawblockbyheight_notfound(bcli); |
| 596 | } |
| 597 | |
| 598 | strip_trailing_whitespace(bcli->output, bcli->output_bytes); |
| 599 | stash->block_hash = tal_strdup(stash, bcli->output); |
| 600 | if (!stash->block_hash || strlen(stash->block_hash) != 64) { |
| 601 | return command_err_bcli_badjson(bcli, "bad blockhash"); |
| 602 | } |
| 603 | |
| 604 | start_bitcoin_cli(NULL, bcli->cmd, process_getrawblock, false, |
| 605 | BITCOIND_HIGH_PRIO, stash, |
| 606 | "getblock", |
| 607 | stash->block_hash, |
| 608 | /* Non-verbose: raw block. */ |
| 609 | "0", |
| 610 | NULL); |
| 611 | |
| 612 | return command_still_pending(bcli->cmd); |
| 613 | } |
| 614 | |
| 615 | /* Get a raw block given its height. |
| 616 | * Calls `getblockhash` then `getblock` to retrieve it from bitcoin_cli. |
nothing calls this directly
no test coverage detected