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

Function json_to_bitcoin_amount

common/json_parse.c:507–534  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

Calls

no outgoing calls

Tested by 1