mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
jsonrpc: Add parsers for routehint-arrays
We'll start passing routehints manually to keysend to reach non-public nodes as well.
This commit is contained in:
parent
ce66466cfb
commit
415c2bfe3c
@ -584,3 +584,73 @@ struct command_result *param_extra_tlvs(struct command *cmd, const char *name,
|
||||
*fields = temp;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct command_result *param_routehint(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
struct route_info **ri)
|
||||
{
|
||||
size_t i;
|
||||
const jsmntok_t *curr;
|
||||
const char *err;
|
||||
|
||||
if (tok->type != JSMN_ARRAY) {
|
||||
return command_fail(
|
||||
cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"Routehint %s (\"%s\") is not an array of hop objects",
|
||||
name, json_strdup(tmpctx, buffer, tok));
|
||||
}
|
||||
|
||||
*ri = tal_arr(cmd, struct route_info, tok->size);
|
||||
json_for_each_arr(i, curr, tok) {
|
||||
struct route_info *e = &(*ri)[i];
|
||||
struct amount_msat temp;
|
||||
|
||||
err = json_scan(tmpctx, buffer, curr,
|
||||
"{id:%,scid:%,feebase:%,feeprop:%,expirydelta:%}",
|
||||
JSON_SCAN(json_to_node_id, &e->pubkey),
|
||||
JSON_SCAN(json_to_short_channel_id, &e->short_channel_id),
|
||||
JSON_SCAN(json_to_msat, &temp),
|
||||
JSON_SCAN(json_to_u32, &e->fee_proportional_millionths),
|
||||
JSON_SCAN(json_to_u16, &e->cltv_expiry_delta)
|
||||
);
|
||||
e->fee_base_msat =
|
||||
temp.millisatoshis; /* Raw: internal conversion. */
|
||||
if (err != NULL) {
|
||||
return command_fail(
|
||||
cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"Error parsing routehint %s[%zu]: %s", name, i,
|
||||
err);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct command_result *
|
||||
param_routehint_array(struct command *cmd, const char *name, const char *buffer,
|
||||
const jsmntok_t *tok, struct route_info ***ris)
|
||||
{
|
||||
size_t i;
|
||||
const jsmntok_t *curr;
|
||||
char *element_name;
|
||||
struct command_result *err;
|
||||
if (tok->type != JSMN_ARRAY) {
|
||||
return command_fail(
|
||||
cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"Routehint array %s (\"%s\") is not an array",
|
||||
name, json_strdup(tmpctx, buffer, tok));
|
||||
}
|
||||
|
||||
*ris = tal_arr(cmd, struct route_info *, 0);
|
||||
json_for_each_arr(i, curr, tok) {
|
||||
struct route_info *element;
|
||||
element_name = tal_fmt(cmd, "%s[%zu]", name, i);
|
||||
err = param_routehint(cmd, element_name, buffer, curr, &element);
|
||||
if (err != NULL) {
|
||||
return err;
|
||||
}
|
||||
tal_arr_expand(ris, element);
|
||||
|
||||
tal_free(element_name);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#define LIGHTNING_COMMON_JSON_TOK_H
|
||||
#include "config.h"
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <common/bolt11.h>
|
||||
#include <common/json.h>
|
||||
#include <common/node_id.h>
|
||||
#include <common/sphinx.h>
|
||||
@ -194,4 +195,13 @@ struct command_result *param_extra_tlvs(struct command *cmd, const char *name,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
struct tlv_field **fields);
|
||||
|
||||
struct command_result *param_routehint(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
struct route_info **ri);
|
||||
|
||||
struct command_result *
|
||||
param_routehint_array(struct command *cmd, const char *name, const char *buffer,
|
||||
const jsmntok_t *tok, struct route_info ***ris);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_JSON_TOK_H */
|
||||
|
@ -49,6 +49,10 @@ bool fromwire_tlv(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
|
||||
bool json_to_channel_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
struct channel_id *cid UNNEEDED)
|
||||
{ fprintf(stderr, "json_to_channel_id called!\n"); abort(); }
|
||||
/* Generated stub for json_to_msat */
|
||||
bool json_to_msat(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
struct amount_msat *msat UNNEEDED)
|
||||
{ fprintf(stderr, "json_to_msat called!\n"); abort(); }
|
||||
/* Generated stub for json_to_node_id */
|
||||
bool json_to_node_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
struct node_id *id UNNEEDED)
|
||||
|
Loading…
Reference in New Issue
Block a user