| 418 | }; |
| 419 | |
| 420 | static void |
| 421 | getrawblockbyheight_callback(const char *buf, const jsmntok_t *toks, |
| 422 | const jsmntok_t *idtok, |
| 423 | struct getrawblockbyheight_call *call) |
| 424 | { |
| 425 | const jsmntok_t *resulttok; |
| 426 | const char *block_str, *err; |
| 427 | struct bitcoin_blkid blkid; |
| 428 | struct bitcoin_block *blk; |
| 429 | const tal_t *ctx; |
| 430 | trace_span_resume(call); |
| 431 | trace_span_end(call); |
| 432 | |
| 433 | resulttok = get_bitcoin_result(call->bitcoind, buf, toks, "getrawblockbyheight"); |
| 434 | |
| 435 | /* Callback may free parent of call, so steal onto context to |
| 436 | * free if it doesn't */ |
| 437 | ctx = tal(NULL, char); |
| 438 | tal_steal(ctx, call); |
| 439 | |
| 440 | /* If block hash is `null`, this means not found! Call the callback |
| 441 | * with NULL values. */ |
| 442 | err = json_scan(tmpctx, buf, resulttok, "{blockhash:null}"); |
| 443 | if (!err) { |
| 444 | call->cb(call->bitcoind, call->height, NULL, NULL, call->cb_arg); |
| 445 | goto clean; |
| 446 | } |
| 447 | |
| 448 | err = json_scan(tmpctx, buf, resulttok, "{blockhash:%,block:%}", |
| 449 | JSON_SCAN(json_to_sha256, &blkid.shad.sha), |
| 450 | JSON_SCAN_TAL(tmpctx, json_strdup, &block_str)); |
| 451 | if (err) |
| 452 | bitcoin_plugin_error(call->bitcoind, buf, resulttok, |
| 453 | "getrawblockbyheight", |
| 454 | "bad 'result' field: %s", err); |
| 455 | |
| 456 | blk = bitcoin_block_from_hex(tmpctx, chainparams, block_str, |
| 457 | strlen(block_str)); |
| 458 | if (!blk) |
| 459 | bitcoin_plugin_error(call->bitcoind, buf, resulttok, |
| 460 | "getrawblockbyheight", |
| 461 | "bad block"); |
| 462 | |
| 463 | call->cb(call->bitcoind, call->height, &blkid, blk, call->cb_arg); |
| 464 | |
| 465 | clean: |
| 466 | tal_free(ctx); |
| 467 | } |
| 468 | |
| 469 | void bitcoind_getrawblockbyheight_(const tal_t *ctx, |
| 470 | struct bitcoind *bitcoind, |
nothing calls this directly
no test coverage detected