mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
jsonrpc: Add parsing for parameter of extra parameters
This commit is contained in:
parent
473be0f6e4
commit
45607577b9
@ -543,3 +543,44 @@ struct command_result *param_outpoint_arr(struct command *cmd,
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct command_result *param_extra_tlvs(struct command *cmd, const char *name,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
struct tlv_field **fields)
|
||||
{
|
||||
size_t i;
|
||||
const jsmntok_t *curr;
|
||||
struct tlv_field *f, *temp;
|
||||
|
||||
if (tok->type != JSMN_OBJECT) {
|
||||
return command_fail(
|
||||
cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"Could not decode the TLV object from %s: "
|
||||
"\"%s\" is not a valid JSON object.",
|
||||
name, json_strdup(tmpctx, buffer, tok));
|
||||
}
|
||||
|
||||
temp = tal_arr(cmd, struct tlv_field, tok->size);
|
||||
json_for_each_obj(i, curr, tok) {
|
||||
f = &temp[i];
|
||||
if (!json_to_u64(buffer, curr, &f->numtype)) {
|
||||
return command_fail(
|
||||
cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"\"%s\" is not a valid numeric TLV type.",
|
||||
json_strdup(tmpctx, buffer, curr));
|
||||
}
|
||||
f->value = json_tok_bin_from_hex(temp, buffer, curr + 1);
|
||||
|
||||
if (f->value == NULL) {
|
||||
return command_fail(
|
||||
cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"\"%s\" is not a valid hex encoded TLV value.",
|
||||
json_strdup(tmpctx, buffer, curr));
|
||||
}
|
||||
f->length = tal_bytelen(f->value);
|
||||
f->meta = NULL;
|
||||
}
|
||||
*fields = temp;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -189,4 +189,9 @@ struct command_result *param_outpoint_arr(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
struct bitcoin_outpoint **outpoints);
|
||||
|
||||
struct command_result *param_extra_tlvs(struct command *cmd, const char *name,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
struct tlv_field **fields);
|
||||
#endif /* LIGHTNING_COMMON_JSON_TOK_H */
|
||||
|
Loading…
Reference in New Issue
Block a user