Skip to content

API: txprepare for multiple outputs#2964

Merged
niftynei merged 8 commits into
ElementsProject:masterfrom
trueptolemy:withdraw-multi
Sep 5, 2019
Merged

API: txprepare for multiple outputs#2964
niftynei merged 8 commits into
ElementsProject:masterfrom
trueptolemy:withdraw-multi

Conversation

@trueptolemy
Copy link
Copy Markdown
Contributor

@trueptolemy trueptolemy commented Aug 16, 2019

Fix #2679

  • Change the paramaters of withdraw and txprepare :

withdraw 'output' ['feerate'] ['minconf']
txprepare 'output' ['feerate'] ['minconf']

The 'output' is the array of outputs that must specify 'destination' and 'satoshi'.
Its format is like:
[{'destination': address1, 'satoshi': satoshi1}, {'destination': address2, 'satoshi': satoshi2}, ...]
or
[{'destination': address, 'satoshi': "all"}]).

There's also 2 related questions:
1. Do you think this output array is suitable?
2. About the test test_mutiple_withdraw, it looks a bit duplicative with test_withdraw. Should I merge these two tests?

EDIT: Remove the change of withdraw, only make txprepare support mutiple outputs.


  • Add CHANGELOG

@trueptolemy trueptolemy requested a review from cdecker as a code owner August 16, 2019 20:14
@ZmnSCPxj
Copy link
Copy Markdown
Contributor

withdraw is an old, user-facing command, whereas txprepare is a relatively new and arguably low-level command. I would be fine with changing txprepare interface but not withdraw interface. Others might have different opinions.

@trueptolemy
Copy link
Copy Markdown
Contributor Author

I would be fine with changing txprepare interface but not withdraw interface. Others might have different opinions.

Thank you, I'll restore withdraw to its original.

@trueptolemy trueptolemy force-pushed the withdraw-multi branch 2 times, most recently from 65974ea to 749cc8f Compare August 17, 2019 10:53
@trueptolemy trueptolemy changed the title API: withdraw/txprepare for multiple addresses API: txprepare for multiple outputs Aug 17, 2019
@trueptolemy trueptolemy force-pushed the withdraw-multi branch 2 times, most recently from 42658a2 to b349554 Compare August 17, 2019 11:28
@cdecker cdecker requested a review from niftynei August 18, 2019 13:07
@trueptolemy trueptolemy force-pushed the withdraw-multi branch 2 times, most recently from 84690ed to 5f56928 Compare August 22, 2019 19:20
Copy link
Copy Markdown
Collaborator

@niftynei niftynei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! A few nits about naming conventions, otherwise it's a nice improvement.

Comment thread bitcoin/tx.c
Comment thread doc/lightning-txprepare.7.md Outdated
Comment thread CHANGELOG.md Outdated
Comment thread doc/lightning-txprepare.7.md Outdated
@trueptolemy trueptolemy force-pushed the withdraw-multi branch 3 times, most recently from 5205197 to 0cbd560 Compare August 28, 2019 14:12
Comment thread wallet/walletrpc.c Outdated
Comment thread wallet/walletrpc.c Outdated
@trueptolemy trueptolemy force-pushed the withdraw-multi branch 3 times, most recently from 7eb4503 to 77883f2 Compare September 1, 2019 16:34
Comment thread wallet/walletrpc.c Outdated
}

if (i == 0)
(*utx)->wtx->amount = AMOUNT_SAT(0);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should do this before the loop, right after we initialize all_funds = false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you. Corrected.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here shouldn't be changed:
At the beginning, we initial the (*utx)->wtx->amount as AMOUNT_SAT(-1ULL).
This is the max permissible for wallet_select_all.

	if (amount_sat_eq(*amount, AMOUNT_SAT(-1ULL))) {
		if (outputstok->size > 1)
			return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
					    "outputs[%zi]: this destination wants"
					    " all satoshi. The count of outputs"
					    " can't be more than 1. ", i);
		(*utx)->wtx->all_funds = true;
		break;
	}

	if (i == 0)
		(*utx)->wtx->amount = AMOUNT_SAT(0);

After handling the all case, we can initial (*utx)->wtx->amount again.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we're in a split mode, because you've initialized all_funds to be false, but left the wtx->amount pegged at what basically signifies all_funds. this is not ideal.

the wtx amount should be set to zero at the loop start along with the all_funds flag. in the case that the *amount is the max, then set (utx)->wtx->amount to be *amount before breaking. this keeps the state fields of the wtx in sync.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I got your idea. It's better 👍

Comment thread wallet/walletrpc.c Outdated
Comment thread wallet/walletrpc.c Outdated
Comment thread CHANGELOG.md Outdated
@niftynei
Copy link
Copy Markdown
Collaborator

niftynei commented Sep 3, 2019

Few minor nits, otherwise lgtm

@niftynei
Copy link
Copy Markdown
Collaborator

niftynei commented Sep 4, 2019

Travis shows that test_txprepare and test_txprepare_restart in test_wallet.py are failing with this error

E           lightning.lightning.RpcError: RPC call failed: method: txprepare, payload: {'outputs': [{'bcrt1qeyyk6sl5pr49ycpqyckvmttus5ttj25pd0zpvg': 'all'}]}, error: {'code': 302, 'message': 'Output 0sat would be dust'}

@trueptolemy
Copy link
Copy Markdown
Contributor Author

Rebased and solved the bug.(The reason is here ).
Wait for Travis-CI to pass.

@trueptolemy trueptolemy force-pushed the withdraw-multi branch 2 times, most recently from 5a8a507 to a2b9486 Compare September 5, 2019 15:04
@niftynei
Copy link
Copy Markdown
Collaborator

niftynei commented Sep 5, 2019

ACK 08882c7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: withdraw to multiple addresses

3 participants