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

Function find_close_account_name

plugins/bkpr/recorder.c:245–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243}
244
245const char *find_close_account_name(const tal_t *ctx,
246 const struct bkpr *bkpr,
247 struct command *cmd,
248 const struct bitcoin_txid *txid)
249{
250 const char *buf;
251 const jsmntok_t *result, *rows, *row;
252 size_t i;
253 const char *acct_name = NULL;
254
255 /* We look for a CHANNEL_CLOSE spend, but ignore “spliced” close events. */
256 result = sql_req(ctx, cmd, &buf,
257 "SELECT account_id"
258 " FROM chainmoves cm"
259 " WHERE cm.primary_tag = '%s'"
260 " AND cm.spending_txid = X'%s'"
261 " AND NOT EXISTS ("
262 " SELECT 1 FROM chainmoves_extra_tags et"
263 " WHERE et.row = cm.created_index"
264 " AND et.extra_tags = 'spliced'"
265 " )"
266 " AND"
267 " cm.created_index <= %"PRIu64
268 " LIMIT 1",
269 sql_string(tmpctx, mvt_tag_str(MVT_CHANNEL_CLOSE)),
270 fmt_bitcoin_txid(tmpctx, txid),
271 bkpr->chainmoves_index);
272
273 rows = json_get_member(buf, result, "rows");
274 json_for_each_arr(i, row, rows) {
275 /* Single column => row->size == 1; first value token is row+1 */
276 const jsmntok_t *val = row + 1;
277 acct_name = json_strdup(ctx, buf, val);
278 break; /* only need the first row */
279 }
280
281 return acct_name; /* NULL if none found */
282}
283
284u64 account_onchain_closeheight(const struct bkpr *bkpr,
285 struct command *cmd,

Callers 1

do_account_close_checksFunction · 0.70

Calls 6

sql_reqFunction · 0.85
sql_stringFunction · 0.85
mvt_tag_strFunction · 0.85
fmt_bitcoin_txidFunction · 0.85
json_get_memberFunction · 0.85
json_strdupFunction · 0.50

Tested by

no test coverage detected