Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiwithdraw #3812

Merged
merged 4 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bitcoin/psbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ struct wally_psbt_output *psbt_append_output(struct wally_psbt *psbt,
wally_tx_output_free(tx_out);
return out;
}
struct wally_psbt_output *psbt_insert_output(struct wally_psbt *psbt,
const u8 *script,
struct amount_sat amount,
size_t insert_at)
{
struct wally_psbt_output *out;
struct wally_tx_output *tx_out = wally_tx_output(script, amount);

out = psbt_add_output(psbt, tx_out, insert_at);
wally_tx_output_free(tx_out);
return out;
}

void psbt_rm_output(struct wally_psbt *psbt,
size_t remove_at)
Expand Down
4 changes: 4 additions & 0 deletions bitcoin/psbt.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ struct wally_psbt_output *psbt_add_output(struct wally_psbt *psbt,
struct wally_psbt_output *psbt_append_output(struct wally_psbt *psbt,
const u8 *script,
struct amount_sat amount);
struct wally_psbt_output *psbt_insert_output(struct wally_psbt *psbt,
const u8 *script,
struct amount_sat amount,
size_t insert_at);

void psbt_rm_output(struct wally_psbt *psbt,
size_t remove_at);
Expand Down
15 changes: 15 additions & 0 deletions contrib/pyln-client/pyln/client/lightning.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,21 @@ def multifundchannel(self, destinations, feerate=None, minconf=None, utxos=None,
payload.update({k: v for k, v in kwargs.items()})
return self.call("multifundchannel", payload)

def multiwithdraw(self, outputs, feerate=None, minconf=None, utxos=None, **kwargs):
"""
Send to {outputs}
via Bitcoin transaction. Only select outputs
with {minconf} confirmations.
"""
payload = {
"outputs": outputs,
"feerate": feerate,
"minconf": minconf,
"utxos": utxos,
}
payload.update({k: v for k, v in kwargs.items()})
return self.call("multiwithdraw", payload)

def newaddr(self, addresstype=None):
"""Get a new address of type {addresstype} of the internal wallet.
"""
Expand Down
1 change: 1 addition & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ MANPAGES := doc/lightning-cli.1 \
doc/lightning-listpeers.7 \
doc/lightning-listsendpays.7 \
doc/lightning-multifundchannel.7 \
doc/lightning-multiwithdraw.7 \
doc/lightning-newaddr.7 \
doc/lightning-pay.7 \
doc/lightning-plugin.7 \
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ c-lightning Documentation
lightning-listsendpays <lightning-listsendpays.7.md>
lightning-listtransactions <lightning-listtransactions.7.md>
lightning-multifundchannel <lightning-multifundchannel.7.md>
lightning-multiwithdraw <lightning-multiwithdraw.7.md>
lightning-newaddr <lightning-newaddr.7.md>
lightning-pay <lightning-pay.7.md>
lightning-ping <lightning-ping.7.md>
Expand Down
80 changes: 80 additions & 0 deletions doc/lightning-multiwithdraw.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions doc/lightning-multiwithdraw.7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
lightning-multiwithdraw -- Command for withdrawing to multiple addresses
========================================================================

SYNOPSIS
--------

**multiwithdraw** *outputs* \[*feerate*\] \[*minconf*\] \[*utxos*\]

DESCRIPTION
-----------

The **multiwithdraw** RPC command sends funds from c-lightning’s internal
wallet to the addresses specified in *outputs*,
which is an array containing objects of the form `{address: amount}`.
The `amount` may be the string *"all"*, indicating that all onchain funds
be sent to the specified address.
Otherwise, it is in satoshi precision;
it can be
a whole number,
a whole number ending in *sat*,
a whole number ending in *000msat*,
or a number with 1 to 8 decimal places ending in *btc*.

*feerate* is an optional feerate to use. It can be one of the strings
*urgent* (aim for next block), *normal* (next 4 blocks or so) or *slow*
(next 100 blocks or so) to use lightningd’s internal estimates: *normal*
is the default.

Otherwise, *feerate* is a number, with an optional suffix: *perkw* means
the number is interpreted as satoshi-per-kilosipa (weight), and *perkb*
means it is interpreted bitcoind-style as satoshi-per-kilobyte. Omitting
the suffix is equivalent to *perkb*.

*minconf* specifies the minimum number of confirmations that used
outputs should have. Default is 1.

*utxos* specifies the utxos to be used to be withdrawn from, as an array
of "txid:vout". These must be drawn from the node's available UTXO set.

RETURN VALUE
------------

On success, an object with attributes *tx* and *txid* will be returned.

*tx* represents the raw bitcoin, fully signed, transaction and *txid*
represent the bitcoin transaction id.

On failure, an error is reported and the withdrawal transaction is not
created.

The following error codes may occur:
- -1: Catchall nonspecific error.
- 301: There are not enough funds in the internal wallet (including
fees) to create the transaction.
- 302: The dust limit is not met.

AUTHOR
------

ZmnSCPxj < <ZmnSCPxj@protonmail.com> > is mainly responsible.

SEE ALSO
--------

lightning-listfunds(7), lightning-fundchannel(7), lightning-newaddr(7),
lightning-txprepare(7), lightning-withdraw(7).

RESOURCES
---------

Main web site: <https://github.com/ElementsProject/lightning>
1 change: 1 addition & 0 deletions plugins/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ autoclean
bcli
fundchannel
pay
spenderp
multifundchannel
18 changes: 15 additions & 3 deletions plugins/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ 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/multiwithdraw.c
PLUGIN_SPENDER_HEADER := \
plugins/spender/multiwithdraw.h
PLUGIN_SPENDER_OBJS := $(PLUGIN_SPENDER_SRC:.c=.o)

PLUGIN_ALL_SRC := \
$(PLUGIN_AUTOCLEAN_SRC) \
$(PLUGIN_BCLI_SRC) \
Expand All @@ -36,10 +43,12 @@ PLUGIN_ALL_SRC := \
$(PLUGIN_LIB_SRC) \
$(PLUGIN_MULTIFUNDCHANNEL_SRC) \
$(PLUGIN_PAY_LIB_SRC) \
$(PLUGIN_PAY_SRC)
$(PLUGIN_PAY_SRC) \
$(PLUGIN_SPENDER_SRC)
PLUGIN_ALL_HEADER := \
$(PLUGIN_LIB_HEADER) \
$(PLUGIN_PAY_LIB_HEADER)
$(PLUGIN_PAY_LIB_HEADER) \
$(PLUGIN_SPENDER_HEADER)
PLUGIN_ALL_OBJS := $(PLUGIN_ALL_SRC:.c=.o)

PLUGINS := \
Expand All @@ -49,7 +58,8 @@ PLUGINS := \
plugins/keysend \
plugins/pay \
plugins/multifundchannel \
plugins/txprepare
plugins/txprepare \
plugins/spenderp

# Make sure these depend on everything.
ALL_C_SOURCES += $(PLUGIN_ALL_SRC)
Expand Down Expand Up @@ -112,4 +122,6 @@ $(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)
35 changes: 35 additions & 0 deletions plugins/spender/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <common/utils.h>
#include <plugins/libplugin.h>
#include <plugins/spender/multiwithdraw.h>

/*~ The spender plugin contains various commands that handle
* spending from the onchain wallet. */

static
void spender_init(struct plugin *p, const char *b, const jsmntok_t *t)
{
/* whatever_init(p, b, t); */
}

int main(int argc, char **argv)
{
char *owner = tal(NULL, char);
struct plugin_command *commands;

setup_locale();

commands = tal_arr(owner, struct plugin_command, 0);

tal_expand(&commands, multiwithdraw_commands, num_multiwithdraw_commands);
/* tal_expand(&commands, whatever_commands, num_whatever_commands); */

plugin_main(argv, &spender_init, PLUGIN_STATIC, true,
NULL,
commands, tal_count(commands),
NULL, 0,
NULL, 0,
NULL);

tal_free(owner);
return 0;
}
Loading