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

Function param_time

lightningd/invoice.c:1030–1077  ·  view source on GitHub ↗

Parse time with optional suffix, return seconds */

Source from the content-addressed store, hash-verified

1028
1029/* Parse time with optional suffix, return seconds */
1030static struct command_result *param_time(struct command *cmd, const char *name,
1031 const char *buffer,
1032 const jsmntok_t *tok,
1033 uint64_t **secs)
1034{
1035 /* We need to manipulate this, so make copy */
1036 jsmntok_t timetok = *tok;
1037 u64 mul;
1038 char s;
1039 struct {
1040 char suffix;
1041 u64 mul;
1042 } suffixes[] = {
1043 { 's', 1 },
1044 { 'm', 60 },
1045 { 'h', 60*60 },
1046 { 'd', 24*60*60 },
1047 { 'w', 7*24*60*60 } };
1048
1049 if (!deprecated_apis)
1050 return param_u64(cmd, name, buffer, tok, secs);
1051
1052 mul = 1;
1053 if (timetok.end == timetok.start)
1054 s = '\0';
1055 else
1056 s = buffer[timetok.end - 1];
1057 for (size_t i = 0; i < ARRAY_SIZE(suffixes); i++) {
1058 if (s == suffixes[i].suffix) {
1059 mul = suffixes[i].mul;
1060 timetok.end--;
1061 break;
1062 }
1063 }
1064
1065 *secs = tal(cmd, uint64_t);
1066 if (json_to_u64(buffer, &timetok, *secs)) {
1067 if (mul_overflows_u64(**secs, mul)) {
1068 return command_fail_badparam(cmd, name, buffer, tok,
1069 "value too large");
1070 }
1071 **secs *= mul;
1072 return NULL;
1073 }
1074
1075 return command_fail_badparam(cmd, name, buffer, tok,
1076 "should be a number");
1077}
1078
1079static struct command_result *param_chanhints(struct command *cmd,
1080 const char *name,

Callers

nothing calls this directly

Calls 4

mul_overflows_u64Function · 0.85
command_fail_badparamFunction · 0.85
param_u64Function · 0.50
json_to_u64Function · 0.50

Tested by

no test coverage detected