| 436 | }; |
| 437 | |
| 438 | static void |
| 439 | getrawblockbyheight_callback(const char *buf, const jsmntok_t *toks, |
| 440 | const jsmntok_t *idtok, |
| 441 | struct getrawblockbyheight_call *call) |
| 442 | { |
| 443 | const jsmntok_t *resulttok; |
| 444 | const char *block_str, *err; |
| 445 | struct bitcoin_blkid blkid; |
| 446 | struct bitcoin_block *blk; |
| 447 | const tal_t *ctx; |
| 448 | trace_span_resume(call); |
| 449 | trace_span_end(call); |
| 450 | |
| 451 | resulttok = get_bitcoin_result(call->bitcoind, buf, toks, "getrawblockbyheight"); |
| 452 | |
| 453 | /* Callback may free parent of call, so steal onto context to |
| 454 | * free if it doesn't */ |
| 455 | ctx = tal(NULL, char); |
| 456 | tal_steal(ctx, call); |
| 457 | |
| 458 | /* If block hash is `null`, this means not found! Call the callback |
| 459 | * with NULL values. */ |
| 460 | err = json_scan(tmpctx, buf, resulttok, "{blockhash:null}"); |
| 461 | if (!err) { |
| 462 | call->cb(call->bitcoind, call->height, NULL, NULL, call->cb_arg); |
| 463 | goto clean; |
| 464 | } |
| 465 | |
| 466 | err = json_scan(tmpctx, buf, resulttok, "{blockhash:%,block:%}", |
| 467 | JSON_SCAN(json_to_sha256, &blkid.shad.sha), |
| 468 | JSON_SCAN_TAL(tmpctx, json_strdup, &block_str)); |
| 469 | if (err) |
| 470 | bitcoin_plugin_error(call->bitcoind, buf, resulttok, |
| 471 | "getrawblockbyheight", |
| 472 | "bad 'result' field: %s", err); |
| 473 | |
| 474 | blk = bitcoin_block_from_hex(tmpctx, chainparams, block_str, |
| 475 | strlen(block_str)); |
| 476 | if (!blk) |
| 477 | bitcoin_plugin_error(call->bitcoind, buf, resulttok, |
| 478 | "getrawblockbyheight", |
| 479 | "bad block"); |
| 480 | |
| 481 | call->cb(call->bitcoind, call->height, &blkid, blk, call->cb_arg); |
| 482 | |
| 483 | clean: |
| 484 | tal_free(ctx); |
| 485 | } |
| 486 | |
| 487 | void bitcoind_getrawblockbyheight_(const tal_t *ctx, |
| 488 | struct bitcoind *bitcoind, |
nothing calls this directly
no test coverage detected