mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 05:12:45 +01:00
dev-forget-channel: accept passing in channel_id
This patch adds a channel_id parameter to allow for specifying channels that are lacking a short_channel_id. Useful in the case where a peer has 1) multiple channels (ONCHAIN etc) and 2) a channel where the funding transaction hasn't been broadcast/mined.
This commit is contained in:
parent
cbfa045f91
commit
af4ffe5fcd
@ -1,5 +1,6 @@
|
||||
#include <bitcoin/pubkey.h>
|
||||
#include <bitcoin/short_channel_id.h>
|
||||
#include <ccan/ccan/str/hex/hex.h>
|
||||
#include <common/amount.h>
|
||||
#include <common/json_helpers.h>
|
||||
#include <common/node_id.h>
|
||||
@ -84,6 +85,13 @@ bool json_to_txid(const char *buffer, const jsmntok_t *tok,
|
||||
tok->end - tok->start, txid);
|
||||
}
|
||||
|
||||
bool json_to_channel_id(const char *buffer, const jsmntok_t *tok,
|
||||
struct channel_id *cid)
|
||||
{
|
||||
return hex_decode(buffer + tok->start, tok->end - tok->start,
|
||||
cid, sizeof(*cid));
|
||||
}
|
||||
|
||||
bool split_tok(const char *buffer, const jsmntok_t *tok,
|
||||
char split,
|
||||
jsmntok_t *a,
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "config.h"
|
||||
#include <bitcoin/tx.h>
|
||||
#include <common/json.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
struct amount_msat;
|
||||
struct amount_sat;
|
||||
@ -44,6 +45,10 @@ bool json_to_msat(const char *buffer, const jsmntok_t *tok,
|
||||
bool json_to_txid(const char *buffer, const jsmntok_t *tok,
|
||||
struct bitcoin_txid *txid);
|
||||
|
||||
/* Extract a channel id from this */
|
||||
bool json_to_channel_id(const char *buffer, const jsmntok_t *tok,
|
||||
struct channel_id *cid);
|
||||
|
||||
/* Split a json token into 2 tokens given a splitting character */
|
||||
bool split_tok(const char *buffer, const jsmntok_t *tok,
|
||||
char split,
|
||||
|
@ -214,3 +214,17 @@ struct command_result *param_node_id(struct command *cmd, const char *name,
|
||||
name, json_tok_full_len(tok),
|
||||
json_tok_full(buffer, tok));
|
||||
}
|
||||
|
||||
struct command_result *param_channel_id(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
struct channel_id **cid)
|
||||
{
|
||||
*cid = tal(cmd, struct channel_id);
|
||||
if (json_to_channel_id(buffer, tok, *cid))
|
||||
return NULL;
|
||||
|
||||
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||
"'%s' should be a channel id, not '%.*s'",
|
||||
name, json_tok_full_len(tok),
|
||||
json_tok_full(buffer, tok));
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <common/json.h>
|
||||
#include <common/node_id.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
struct amount_msat;
|
||||
struct amount_sat;
|
||||
@ -89,6 +90,11 @@ struct command_result *param_node_id(struct command *cmd,
|
||||
const jsmntok_t *tok,
|
||||
struct node_id **id);
|
||||
|
||||
struct command_result *param_channel_id(struct command *cmd,
|
||||
const char *name,
|
||||
const char *buffer,
|
||||
const jsmntok_t *tok,
|
||||
struct channel_id **cid);
|
||||
/*
|
||||
* Set the address of @out to @tok. Used as a callback by handlers that
|
||||
* want to unmarshal @tok themselves.
|
||||
@ -104,4 +110,5 @@ struct command_result *param_tok(struct command *cmd, const char *name,
|
||||
struct command_result *param_ignore(struct command *cmd, const char *name,
|
||||
const char *buffer, const jsmntok_t *tok,
|
||||
const void *unused);
|
||||
|
||||
#endif /* LIGHTNING_COMMON_JSON_TOK_H */
|
||||
|
@ -42,6 +42,10 @@ struct command_result *command_fail(struct command *cmd,
|
||||
/* Generated stub for fromwire_fail */
|
||||
const void *fromwire_fail(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
|
||||
{ fprintf(stderr, "fromwire_fail called!\n"); abort(); }
|
||||
/* Generated stub for json_to_channel_id */
|
||||
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_node_id */
|
||||
bool json_to_node_id(const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
struct node_id *id UNNEEDED)
|
||||
|
@ -2106,6 +2106,7 @@ static struct command_result *json_dev_forget_channel(struct command *cmd,
|
||||
struct peer *peer;
|
||||
struct channel *channel;
|
||||
struct short_channel_id *scid;
|
||||
struct channel_id *find_cid, cid;
|
||||
struct dev_forget_channel_cmd *forget = tal(cmd, struct dev_forget_channel_cmd);
|
||||
forget->cmd = cmd;
|
||||
|
||||
@ -2113,6 +2114,7 @@ static struct command_result *json_dev_forget_channel(struct command *cmd,
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("id", param_node_id, &peerid),
|
||||
p_opt("short_channel_id", param_short_channel_id, &scid),
|
||||
p_opt("channel_id", param_channel_id, &find_cid),
|
||||
p_opt_def("force", param_bool, &force, false),
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
@ -2126,6 +2128,14 @@ static struct command_result *json_dev_forget_channel(struct command *cmd,
|
||||
|
||||
forget->channel = NULL;
|
||||
list_for_each(&peer->channels, channel, list) {
|
||||
/* Check for channel id first */
|
||||
if (find_cid) {
|
||||
derive_channel_id(&cid, &channel->funding_txid,
|
||||
channel->funding_outnum);
|
||||
|
||||
if (!channel_id_eq(find_cid, &cid))
|
||||
continue;
|
||||
}
|
||||
if (scid) {
|
||||
if (!channel->scid)
|
||||
continue;
|
||||
|
@ -319,6 +319,13 @@ struct command_result *param_bool(struct command *cmd UNNEEDED, const char *name
|
||||
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
bool **b UNNEEDED)
|
||||
{ fprintf(stderr, "param_bool called!\n"); abort(); }
|
||||
/* Generated stub for param_channel_id */
|
||||
struct command_result *param_channel_id(struct command *cmd UNNEEDED,
|
||||
const char *name UNNEEDED,
|
||||
const char *buffer UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
struct channel_id **cid UNNEEDED)
|
||||
{ fprintf(stderr, "param_channel_id called!\n"); abort(); }
|
||||
/* Generated stub for param_escaped_string */
|
||||
struct command_result *param_escaped_string(struct command *cmd UNNEEDED,
|
||||
const char *name UNNEEDED,
|
||||
|
@ -417,6 +417,13 @@ struct command_result *param_bool(struct command *cmd UNNEEDED, const char *name
|
||||
const char *buffer UNNEEDED, const jsmntok_t *tok UNNEEDED,
|
||||
bool **b UNNEEDED)
|
||||
{ fprintf(stderr, "param_bool called!\n"); abort(); }
|
||||
/* Generated stub for param_channel_id */
|
||||
struct command_result *param_channel_id(struct command *cmd UNNEEDED,
|
||||
const char *name UNNEEDED,
|
||||
const char *buffer UNNEEDED,
|
||||
const jsmntok_t *tok UNNEEDED,
|
||||
struct channel_id **cid UNNEEDED)
|
||||
{ fprintf(stderr, "param_channel_id called!\n"); abort(); }
|
||||
/* Generated stub for param_loglevel */
|
||||
struct command_result *param_loglevel(struct command *cmd UNNEEDED,
|
||||
const char *name UNNEEDED,
|
||||
|
Loading…
Reference in New Issue
Block a user