MCPcopy Create free account
hub / github.com/ElementsProject/lightning / getrawblockbyheight_callback

Function getrawblockbyheight_callback

lightningd/bitcoind.c:420–467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

418};
419
420static void
421getrawblockbyheight_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
465clean:
466 tal_free(ctx);
467}
468
469void bitcoind_getrawblockbyheight_(const tal_t *ctx,
470 struct bitcoind *bitcoind,

Callers

nothing calls this directly

Calls 6

trace_span_endFunction · 0.85
get_bitcoin_resultFunction · 0.85
bitcoin_plugin_errorFunction · 0.85
bitcoin_block_from_hexFunction · 0.85
tal_freeFunction · 0.85
json_scanFunction · 0.50

Tested by

no test coverage detected