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

Function hook_extract_amount

lightningd/dual_open_control.c:463–503  ·  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

461 * unit will be interpreted correctly, but a value given
462 * without a unit will always be interpreted as msats */
463static bool
464hook_extract_amount(struct subd *dualopend,
465 const char *buffer,
466 const jsmntok_t *toks,
467 char *field_name,
468 struct amount_sat *amount)
469{
470 struct amount_msat msats;
471
472 if (!buffer)
473 return false;
474
475 const jsmntok_t *t = json_get_member(buffer, toks, "result");
476 if (!t)
477 fatal("Plugin must return a 'result' "
478 " %.*s", toks[0].end - toks[0].start,
479 buffer + toks[0].start);
480
481 if (!json_tok_streq(buffer, t, "continue")) {
482 char *errmsg = "Client error. Unable to continue";
483 subd_send_msg(dualopend,
484 take(towire_dualopend_fail(NULL, errmsg)));
485 return false;
486 }
487
488 /* If there's no amount_sat field, that's ok */
489 const jsmntok_t *amt_tok = json_get_member(buffer, toks, field_name);
490 if (!amt_tok) {
491 *amount = AMOUNT_SAT(0);
492 return true;
493 }
494
495 if (!json_to_msat(buffer, amt_tok, &msats))
496 fatal("Plugin must return a valid '%s' to a 'continue'd"
497 " %.*s", field_name,
498 toks[0].end - toks[0].start,
499 buffer + toks[0].start);
500
501 *amount = amount_msat_to_sat_round_down(msats);
502 return true;
503}
504
505static void rbf_channel_remove_dualopend(struct subd *dualopend,
506 struct rbf_channel_payload *payload)

Callers 2

Calls 6

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

Tested by

no test coverage detected