mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 07:04:22 +01:00
daemons: use amount_msat/amount_sat in all internal wire transfers.
As a side-effect of using amount_msat in gossipd/routing.c, we explicitly handle overflows and don't need to pre-prune ridiculous-fee channels. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -9,14 +9,17 @@ struct bitcoin_tx *create_close_tx(const tal_t *ctx,
|
||||
const u8 *their_script,
|
||||
const struct bitcoin_txid *anchor_txid,
|
||||
unsigned int anchor_index,
|
||||
u64 anchor_satoshis,
|
||||
uint64_t to_us, uint64_t to_them,
|
||||
uint64_t dust_limit)
|
||||
struct amount_sat funding,
|
||||
struct amount_sat to_us,
|
||||
struct amount_sat to_them,
|
||||
struct amount_sat dust_limit)
|
||||
{
|
||||
struct bitcoin_tx *tx;
|
||||
size_t num_outputs = 0;
|
||||
struct amount_sat total_out;
|
||||
|
||||
assert(to_us + to_them <= anchor_satoshis);
|
||||
assert(amount_sat_add(&total_out, to_us, to_them));
|
||||
assert(amount_sat_less_eq(total_out, funding));
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
@@ -34,19 +37,19 @@ struct bitcoin_tx *create_close_tx(const tal_t *ctx,
|
||||
/* Our input spends the anchor tx output. */
|
||||
tx->input[0].txid = *anchor_txid;
|
||||
tx->input[0].index = anchor_index;
|
||||
tx->input[0].amount = tal_dup(tx->input, u64, &anchor_satoshis);
|
||||
tx->input[0].amount = tal_dup(tx->input, u64, &funding.satoshis);
|
||||
|
||||
if (to_us >= dust_limit) {
|
||||
if (amount_sat_greater_eq(to_us, dust_limit)) {
|
||||
/* One output is to us. */
|
||||
tx->output[num_outputs].amount = to_us;
|
||||
tx->output[num_outputs].amount = to_us.satoshis;
|
||||
tx->output[num_outputs].script = tal_dup_arr(tx, u8,
|
||||
our_script, tal_count(our_script), 0);
|
||||
num_outputs++;
|
||||
}
|
||||
|
||||
if (to_them >= dust_limit) {
|
||||
if (amount_sat_greater_eq(to_them, dust_limit)) {
|
||||
/* Other output is to them. */
|
||||
tx->output[num_outputs].amount = to_them;
|
||||
tx->output[num_outputs].amount = to_them.satoshis;
|
||||
tx->output[num_outputs].script = tal_dup_arr(tx, u8,
|
||||
their_script, tal_count(their_script),
|
||||
0);
|
||||
|
||||
Reference in New Issue
Block a user