Skip to content

Commit

Permalink
fundchannel: have address work with any network
Browse files Browse the repository at this point in the history
`txprepare` verifies that you're sending to an address on the
right network, so this builds a placeholder address for the
right network.
  • Loading branch information
niftynei authored and rustyrussell committed Sep 11, 2019
1 parent 7d06923 commit 42ef649
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
7 changes: 3 additions & 4 deletions plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ PLUGIN_LIB_HEADER := plugins/libplugin.h
PLUGIN_LIB_OBJS := $(PLUGIN_LIB_SRC:.c=.o)

PLUGIN_COMMON_OBJS := \
bitcoin/chainparams.o \
bitcoin/pubkey.o \
bitcoin/pullpush.o \
bitcoin/script.o \
Expand Down Expand Up @@ -42,11 +41,11 @@ PLUGIN_COMMON_OBJS := \
wire/fromwire.o \
wire/towire.o

plugins/pay: $(PLUGIN_PAY_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
plugins/pay: bitcoin/chainparams.o $(PLUGIN_PAY_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)

plugins/autoclean: $(PLUGIN_AUTOCLEAN_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
plugins/autoclean: bitcoin/chainparams.o $(PLUGIN_AUTOCLEAN_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)

plugins/fundchannel: $(PLUGIN_FUNDCHANNEL_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
plugins/fundchannel: common/addr.o $(PLUGIN_FUNDCHANNEL_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)

$(PLUGIN_PAY_OBJS) $(PLUGIN_AUTOCLEAN_OBJS) $(PLUGIN_FUNDCHANNEL_OBJS) $(PLUGIN_LIB_OBJS): $(PLUGIN_LIB_HEADER)

Expand Down
18 changes: 16 additions & 2 deletions plugins/fundchannel.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include <bitcoin/chainparams.c>
#include <bitcoin/script.h>
#include <ccan/array_size/array_size.h>
#include <ccan/json_out/json_out.h>
#include <ccan/tal/str/str.h>
#include <common/addr.h>
#include <common/amount.h>
#include <common/json_tok.h>
#include <common/type_to_string.h>
#include <common/utils.h>
#include <lightningd/json.h>
#include <plugins/libplugin.h>

const char *placeholder_funding_addr = "bcrt1qh9vpp7pylppexnaqg2kdp0kt55sg0qf7yc8d4m4ug26uhx47z3jqvgnzrj";
const char *placeholder_script = "0020b95810f824f843934fa042acd0becba52087813e260edaeebc42b5cb9abe1464";
const char *placeholder_funding_addr;

/* FIXME: dynamically query */
const struct amount_sat max_funding = AMOUNT_SAT_INIT((1 << 24) - 1);
Expand Down Expand Up @@ -403,7 +405,19 @@ static struct command_result *json_fundchannel(struct command *cmd,
static void init(struct plugin_conn *rpc,
const char *buf UNUSED, const jsmntok_t *config UNUSED)
{
/* This method left intentionally blank. */
/* Figure out what the 'placeholder' addr is */
const char *network_name;
const struct chainparams *chainparams;
u8 *placeholder = tal_hexdata(tmpctx, placeholder_script, strlen(placeholder_script));

network_name = rpc_delve(tmpctx, "listconfigs",
take(json_out_obj(NULL, "config",
"network")),
rpc, ".network");
chainparams = chainparams_for_network(network_name);
placeholder_funding_addr = encode_scriptpubkey_to_addr(NULL,
chainparams->bip173_name,
placeholder);
}


Expand Down

0 comments on commit 42ef649

Please sign in to comment.