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

Function json_to_bitcoin_amount

common/json_parse.c:503–529  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

501}
502
503bool json_to_bitcoin_amount(const char *buffer, const jsmntok_t *tok,
504 uint64_t *satoshi)
505{
506 char *end;
507 unsigned long btc, sat;
508
509 btc = strtoul(buffer + tok->start, &end, 10);
510 if (btc == ULONG_MAX && errno == ERANGE)
511 return false;
512 if (end != buffer + tok->end) {
513 /* Expect always 8 decimal places. */
514 if (*end != '.' || buffer + tok->end - end != 9)
515 return false;
516 sat = strtoul(end+1, &end, 10);
517 if (sat == ULONG_MAX && errno == ERANGE)
518 return false;
519 if (end != buffer + tok->end)
520 return false;
521 } else
522 sat = 0;
523
524 *satoshi = btc * (uint64_t)100000000 + sat;
525 if (*satoshi != btc * (uint64_t)100000000 + sat)
526 return false;
527
528 return true;
529}
530
531bool json_to_node_id(const char *buffer, const jsmntok_t *tok,
532 struct node_id *id)

Callers 1

Calls

no outgoing calls

Tested by 1