forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed redundancies in withdraw and fundchannel.
No new functionality, just a continuation of my work toward completing ElementsProject#665. I removed the common members of `struct withdrawal` and `struct fund_channel` and placed them in a new `struct wallet_tx`. Then it was fairly straightforward to reimplement the existing code in terms of `wallet_tx`. Since I made some structural changes I wanted to get this approved before I go any farther. Added 'all' to fundchannel help message.
- Loading branch information
Showing
11 changed files
with
161 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <common/wallet_tx.h> | ||
#include <inttypes.h> | ||
#include <lightningd/jsonrpc_errors.h> | ||
#include <wallet/wallet.h> | ||
|
||
void wtx_init(struct command *cmd, struct wallet_tx * wtx) | ||
{ | ||
wtx->cmd = cmd; | ||
wtx->amount = 0; | ||
wtx->change_key_index = 0; | ||
wtx->utxos = NULL; | ||
wtx->all_funds = false; | ||
wtx->desttok = NULL; | ||
} | ||
|
||
bool wtx_select_utxos(struct wallet_tx * tx, u32 fee_rate_per_kw, | ||
size_t out_len) | ||
{ | ||
u64 fee_estimate; | ||
if (tx->all_funds) { | ||
tx->utxos = wallet_select_all(tx->cmd, tx->cmd->ld->wallet, | ||
fee_rate_per_kw, out_len, | ||
&tx->amount, | ||
&fee_estimate); | ||
if (!tx->utxos || tx->amount < 546) { | ||
command_fail(tx->cmd, "Cannot afford fee %"PRIu64, | ||
fee_estimate); | ||
return false; | ||
} | ||
tx->change = 0; | ||
} else { | ||
tx->utxos = wallet_select_coins(tx->cmd, tx->cmd->ld->wallet, | ||
tx->amount, | ||
fee_rate_per_kw, out_len, | ||
&fee_estimate, &tx->change); | ||
if (!tx->utxos || tx->amount < 546) { | ||
command_fail(tx->cmd, | ||
"Cannot afford funding transaction"); | ||
return false; | ||
} | ||
if (tx->change < 546) { | ||
tx->change = 0; | ||
tx->change_key_index = 0; | ||
} else { | ||
tx->change_key_index = wallet_get_newindex(tx->cmd->ld); | ||
} | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef LIGHTNING_COMMON_WALLET_TX_H | ||
#define LIGHTNING_COMMON_WALLET_TX_H | ||
#include "config.h" | ||
#include <ccan/short_types/short_types.h> | ||
#include <lightningd/json.h> | ||
#include <lightningd/jsonrpc.h> | ||
#include <lightningd/lightningd.h> | ||
|
||
/* A specification of funds in the wallet used for funding channels and | ||
* withdrawal. | ||
*/ | ||
struct wallet_tx { | ||
struct command *cmd; | ||
u64 amount; | ||
u64 change; | ||
u32 change_key_index; | ||
const struct utxo **utxos; | ||
|
||
bool all_funds; | ||
const jsmntok_t *desttok; | ||
const jsmntok_t *sattok; | ||
}; | ||
|
||
void wtx_init(struct command *cmd, struct wallet_tx *wtx); | ||
bool wtx_select_utxos(struct wallet_tx * tx, u32 fee_rate_per_kw, | ||
size_t out_len); | ||
#endif /* LIGHTNING_COMMON_WALLET_TX_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.