From f6c145d2dfa80fadfc6df37e7c35b5672881a39e Mon Sep 17 00:00:00 2001
From: ZmnSCPxj jxPCSnmZ <zmnscpxj@protonmail.com>
Date: Fri, 21 Aug 2020 17:31:33 +0800
Subject: [PATCH] plugins/spender/multifundchannel.c: Move multifundchannel to
 the spenderp plugin.

---
 plugins/Makefile                         |  9 ++-----
 plugins/spender/main.c                   |  2 ++
 plugins/{ => spender}/multifundchannel.c | 31 ++----------------------
 plugins/spender/multifundchannel.h       | 10 ++++++++
 4 files changed, 16 insertions(+), 36 deletions(-)
 rename plugins/{ => spender}/multifundchannel.c (98%)
 create mode 100644 plugins/spender/multifundchannel.h

diff --git a/plugins/Makefile b/plugins/Makefile
index 36607ff16..556826810 100644
--- a/plugins/Makefile
+++ b/plugins/Makefile
@@ -24,13 +24,12 @@ PLUGIN_PAY_LIB_SRC := plugins/libplugin-pay.c
 PLUGIN_PAY_LIB_HEADER := plugins/libplugin-pay.h
 PLUGIN_PAY_LIB_OBJS := $(PLUGIN_PAY_LIB_SRC:.c=.o)
 
-PLUGIN_MULTIFUNDCHANNEL_SRC := plugins/multifundchannel.c
-PLUGIN_MULTIFUNDCHANNEL_OBJS := $(PLUGIN_MULTIFUNDCHANNEL_SRC:.c=.o)
-
 PLUGIN_SPENDER_SRC :=				\
 	plugins/spender/main.c			\
+	plugins/spender/multifundchannel.c	\
 	plugins/spender/multiwithdraw.c
 PLUGIN_SPENDER_HEADER :=			\
+	plugins/spender/multifundchannel.h	\
 	plugins/spender/multiwithdraw.h
 PLUGIN_SPENDER_OBJS := $(PLUGIN_SPENDER_SRC:.c=.o)
 
@@ -41,7 +40,6 @@ PLUGIN_ALL_SRC :=				\
 	$(PLUGIN_KEYSEND_SRC)			\
 	$(PLUGIN_TXPREPARE_SRC)			\
 	$(PLUGIN_LIB_SRC)			\
-	$(PLUGIN_MULTIFUNDCHANNEL_SRC)		\
 	$(PLUGIN_PAY_LIB_SRC)			\
 	$(PLUGIN_PAY_SRC)			\
 	$(PLUGIN_SPENDER_SRC)
@@ -57,7 +55,6 @@ PLUGINS :=					\
 	plugins/fundchannel			\
 	plugins/keysend				\
 	plugins/pay				\
-	plugins/multifundchannel		\
 	plugins/txprepare			\
 	plugins/spenderp
 
@@ -120,8 +117,6 @@ plugins/bcli: bitcoin/chainparams.o $(PLUGIN_BCLI_OBJS) $(PLUGIN_LIB_OBJS) $(PLU
 plugins/keysend: bitcoin/chainparams.o wire/tlvstream.o wire/onion$(EXP)_wiregen.o $(PLUGIN_KEYSEND_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_PAY_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
 $(PLUGIN_KEYSEND_OBJS): $(PLUGIN_PAY_LIB_HEADER)
 
-plugins/multifundchannel: bitcoin/chainparams.o common/addr.o $(PLUGIN_MULTIFUNDCHANNEL_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
-
 plugins/spenderp: bitcoin/chainparams.o $(PLUGIN_SPENDER_OBJS) $(PLUGIN_LIB_OBJS) $(PLUGIN_COMMON_OBJS) $(JSMN_OBJS) $(CCAN_OBJS)
 
 $(PLUGIN_ALL_OBJS): $(PLUGIN_LIB_HEADER)
diff --git a/plugins/spender/main.c b/plugins/spender/main.c
index 9a2861e6b..40cbc90ea 100644
--- a/plugins/spender/main.c
+++ b/plugins/spender/main.c
@@ -1,6 +1,7 @@
 #include <common/utils.h>
 #include <plugins/libplugin.h>
 #include <plugins/spender/multiwithdraw.h>
+#include <plugins/spender/multifundchannel.h>
 
 /*~ The spender plugin contains various commands that handle
  * spending from the onchain wallet.  */
@@ -21,6 +22,7 @@ int main(int argc, char **argv)
 	commands = tal_arr(owner, struct plugin_command, 0);
 
 	tal_expand(&commands, multiwithdraw_commands, num_multiwithdraw_commands);
+	tal_expand(&commands, multifundchannel_commands, num_multifundchannel_commands);
 	/* tal_expand(&commands, whatever_commands, num_whatever_commands); */
 
 	plugin_main(argv, &spender_init, PLUGIN_STATIC, true,
diff --git a/plugins/multifundchannel.c b/plugins/spender/multifundchannel.c
similarity index 98%
rename from plugins/multifundchannel.c
rename to plugins/spender/multifundchannel.c
index d1f78a039..20b052051 100644
--- a/plugins/multifundchannel.c
+++ b/plugins/spender/multifundchannel.c
@@ -19,7 +19,7 @@
 #include <common/pseudorand.h>
 #include <common/type_to_string.h>
 #include <common/utils.h>
-#include <plugins/libplugin.h>
+#include <plugins/spender/multifundchannel.h>
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
@@ -2006,7 +2006,6 @@ json_multifundchannel(struct command *cmd,
 	return perform_multifundchannel(mfc);
 }
 
-static
 const struct plugin_command multifundchannel_commands[] = {
 	{
 		"multifundchannel",
@@ -2022,32 +2021,6 @@ const struct plugin_command multifundchannel_commands[] = {
 		json_multifundchannel
 	}
 };
-static
-const unsigned int num_multifundchannel_commands =
+const size_t num_multifundchannel_commands =
 	ARRAY_SIZE(multifundchannel_commands);
 
-static
-void multifundchannel_init(struct plugin *plugin,
-			   const char *buf UNUSED,
-			   const jsmntok_t *config UNUSED)
-{
-	/* Save our chainparams.  */
-	const char *network_name;
-
-	network_name = rpc_delve(tmpctx, plugin, "listconfigs",
-				 take(json_out_obj(NULL, "config",
-						   "network")),
-				 ".network");
-	chainparams = chainparams_for_network(network_name);
-}
-
-int main(int argc, char **argv)
-{
-	setup_locale();
-	plugin_main(argv,
-		    &multifundchannel_init, PLUGIN_RESTARTABLE,
-		    true,
-		    NULL,
-		    multifundchannel_commands, num_multifundchannel_commands,
-		    NULL, 0, NULL, 0, NULL);
-}
diff --git a/plugins/spender/multifundchannel.h b/plugins/spender/multifundchannel.h
new file mode 100644
index 000000000..abb6c964b
--- /dev/null
+++ b/plugins/spender/multifundchannel.h
@@ -0,0 +1,10 @@
+#ifndef LIGHTNING_PLUGINS_SPENDER_MULTIFUNDCHANNEL_H
+#define LIGHTNING_PLUGINS_SPENDER_MULTIFUNDCHANNEL_H
+#include "config.h"
+
+#include <plugins/libplugin.h>
+
+extern const struct plugin_command multifundchannel_commands[];
+extern const size_t num_multifundchannel_commands;
+
+#endif /* LIGHTNING_PLUGINS_SPENDER_MULTIFUNDCHANNEL_H */