| 344 | }; |
| 345 | |
| 346 | static void |
| 347 | getrawblockbyheight_callback(const char *buf, const jsmntok_t *toks, |
| 348 | const jsmntok_t *idtok, |
| 349 | struct getrawblockbyheight_call *call) |
| 350 | { |
| 351 | const char *block_str, *err; |
| 352 | struct bitcoin_blkid blkid; |
| 353 | struct bitcoin_block *blk; |
| 354 | |
| 355 | /* If block hash is `null`, this means not found! Call the callback |
| 356 | * with NULL values. */ |
| 357 | err = json_scan(tmpctx, buf, toks, "{result:{blockhash:null}}"); |
| 358 | if (!err) { |
| 359 | db_begin_transaction(call->bitcoind->ld->wallet->db); |
| 360 | call->cb(call->bitcoind, NULL, NULL, call->cb_arg); |
| 361 | db_commit_transaction(call->bitcoind->ld->wallet->db); |
| 362 | goto clean; |
| 363 | } |
| 364 | |
| 365 | err = json_scan(tmpctx, buf, toks, "{result:{blockhash:%,block:%}}", |
| 366 | JSON_SCAN(json_to_sha256, &blkid.shad.sha), |
| 367 | JSON_SCAN_TAL(tmpctx, json_strdup, &block_str)); |
| 368 | if (err) |
| 369 | bitcoin_plugin_error(call->bitcoind, buf, toks, |
| 370 | "getrawblockbyheight", |
| 371 | "bad 'result' field: %s", err); |
| 372 | |
| 373 | blk = bitcoin_block_from_hex(tmpctx, chainparams, block_str, |
| 374 | strlen(block_str)); |
| 375 | if (!blk) |
| 376 | bitcoin_plugin_error(call->bitcoind, buf, toks, |
| 377 | "getrawblockbyheight", |
| 378 | "bad block"); |
| 379 | |
| 380 | db_begin_transaction(call->bitcoind->ld->wallet->db); |
| 381 | call->cb(call->bitcoind, &blkid, blk, call->cb_arg); |
| 382 | db_commit_transaction(call->bitcoind->ld->wallet->db); |
| 383 | |
| 384 | clean: |
| 385 | tal_free(call); |
| 386 | } |
| 387 | |
| 388 | void bitcoind_getrawblockbyheight_(struct bitcoind *bitcoind, |
| 389 | u32 height, |
nothing calls this directly
no test coverage detected