| 501 | } |
| 502 | |
| 503 | bool 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 | |
| 531 | bool json_to_node_id(const char *buffer, const jsmntok_t *tok, |
| 532 | struct node_id *id) |
no outgoing calls