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

Function hook_extract_amount

lightningd/dual_open_control.c:432–472  ·  view source on GitHub ↗

The field is *always* assumed msats, as that's the unit * amount we're transitioning our API over to. A 'xxxsat' * unit will be interpreted correctly, but a value given * without a unit will always be interpreted as msats */

Source from the content-addressed store, hash-verified

430 * unit will be interpreted correctly, but a value given
431 * without a unit will always be interpreted as msats */
432static bool
433hook_extract_amount(struct subd *dualopend,
434 const char *buffer,
435 const jsmntok_t *toks,
436 char *field_name,
437 struct amount_sat *amount)
438{
439 struct amount_msat msats;
440
441 if (!buffer)
442 return false;
443
444 const jsmntok_t *t = json_get_member(buffer, toks, "result");
445 if (!t)
446 fatal("Plugin must return a 'result' "
447 " %.*s", toks[0].end - toks[0].start,
448 buffer + toks[0].start);
449
450 if (!json_tok_streq(buffer, t, "continue")) {
451 char *errmsg = "Client error. Unable to continue";
452 subd_send_msg(dualopend,
453 take(towire_dualopend_fail(NULL, errmsg)));
454 return false;
455 }
456
457 /* If there's no amount_sat field, that's ok */
458 const jsmntok_t *amt_tok = json_get_member(buffer, toks, field_name);
459 if (!amt_tok) {
460 *amount = AMOUNT_SAT(0);
461 return true;
462 }
463
464 if (!json_to_msat(buffer, amt_tok, &msats))
465 fatal("Plugin must return a valid '%s' to a 'continue'd"
466 " %.*s", field_name,
467 toks[0].end - toks[0].start,
468 buffer + toks[0].start);
469
470 *amount = amount_msat_to_sat_round_down(msats);
471 return true;
472}
473
474static void rbf_channel_remove_dualopend(struct subd *dualopend,
475 struct rbf_channel_payload *payload)

Callers 2

Calls 6

fatalFunction · 0.70
subd_send_msgFunction · 0.70
json_get_memberFunction · 0.50
json_tok_streqFunction · 0.50
json_to_msatFunction · 0.50

Tested by

no test coverage detected