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

Function getrawblockbyheight_callback

lightningd/bitcoind.c:346–386  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

344};
345
346static void
347getrawblockbyheight_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
384clean:
385 tal_free(call);
386}
387
388void bitcoind_getrawblockbyheight_(struct bitcoind *bitcoind,
389 u32 height,

Callers

nothing calls this directly

Calls 5

bitcoin_plugin_errorFunction · 0.85
bitcoin_block_from_hexFunction · 0.85
tal_freeFunction · 0.85
json_scanFunction · 0.50
db_commit_transactionFunction · 0.50

Tested by

no test coverage detected