diff --git a/bitcoin/tx.c b/bitcoin/tx.c index 72b5e7672..7877615f6 100644 --- a/bitcoin/tx.c +++ b/bitcoin/tx.c @@ -15,14 +15,14 @@ #define SEGREGATED_WITNESS_FLAG 0x1 int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script, - struct amount_sat *amount) + struct amount_sat amount) { size_t i = tx->wtx->num_outputs; struct wally_tx_output *output; assert(i < tx->wtx->outputs_allocation_len); assert(tx->wtx != NULL); - wally_tx_output_init_alloc(amount->satoshis /* Raw: low-level helper */, + wally_tx_output_init_alloc(amount.satoshis /* Raw: low-level helper */, script, tal_bytelen(script), &output); wally_tx_add_output(tx->wtx, output); wally_tx_output_free(output); @@ -32,7 +32,7 @@ int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script, int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid, u32 outnum, u32 sequence, - const struct amount_sat *amount, u8 *script) + struct amount_sat amount, u8 *script) { size_t i = tx->wtx->num_inputs; struct wally_tx_input *input; @@ -48,7 +48,7 @@ int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid, /* Now store the input amount if we know it, so we can sign later */ tx->input_amounts[i] = tal_free(tx->input_amounts[i]); - tx->input_amounts[i] = tal_dup(tx, struct amount_sat, amount); + tx->input_amounts[i] = tal_dup(tx, struct amount_sat, &amount); return i; } @@ -74,10 +74,10 @@ bool bitcoin_tx_check(const struct bitcoin_tx *tx) } void bitcoin_tx_output_set_amount(struct bitcoin_tx *tx, int outnum, - struct amount_sat *amount) + struct amount_sat amount) { assert(outnum < tx->wtx->num_outputs); - tx->wtx->outputs[outnum].satoshi = amount->satoshis; /* Raw: low-level helper */ + tx->wtx->outputs[outnum].satoshi = amount.satoshis; /* Raw: low-level helper */ } const u8 *bitcoin_tx_output_get_script(const tal_t *ctx, diff --git a/bitcoin/tx.h b/bitcoin/tx.h index 358a11520..d8b4c9dc5 100644 --- a/bitcoin/tx.h +++ b/bitcoin/tx.h @@ -76,11 +76,11 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor, size_t *max); int bitcoin_tx_add_output(struct bitcoin_tx *tx, const u8 *script, - struct amount_sat *amount); + struct amount_sat amount); int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid, u32 outnum, u32 sequence, - const struct amount_sat *amount, u8 *script); + struct amount_sat amount, u8 *script); /** @@ -91,7 +91,7 @@ int bitcoin_tx_add_input(struct bitcoin_tx *tx, const struct bitcoin_txid *txid, * existing output. */ void bitcoin_tx_output_set_amount(struct bitcoin_tx *tx, int outnum, - struct amount_sat *amount); + struct amount_sat amount); /** * Helper to get the script of a script's output as a tal_arr diff --git a/channeld/commit_tx.c b/channeld/commit_tx.c index ccc99fd6f..ff3abb0d5 100644 --- a/channeld/commit_tx.c +++ b/channeld/commit_tx.c @@ -45,7 +45,7 @@ static void add_offered_htlc_out(struct bitcoin_tx *tx, size_t n, ripemd160(&ripemd, htlc->rhash.u.u8, sizeof(htlc->rhash.u.u8)); wscript = htlc_offered_wscript(tx, &ripemd, keyset); p2wsh = scriptpubkey_p2wsh(tx, wscript); - bitcoin_tx_add_output(tx, p2wsh, &amount); + bitcoin_tx_add_output(tx, p2wsh, amount); SUPERVERBOSE("# HTLC %" PRIu64 " offered %s wscript %s\n", htlc->id, type_to_string(tmpctx, struct amount_sat, &amount), tal_hex(wscript, wscript)); @@ -65,7 +65,7 @@ static void add_received_htlc_out(struct bitcoin_tx *tx, size_t n, p2wsh = scriptpubkey_p2wsh(tx, wscript); amount = amount_msat_to_sat_round_down(htlc->amount); - bitcoin_tx_add_output(tx, p2wsh, &amount); + bitcoin_tx_add_output(tx, p2wsh, amount); SUPERVERBOSE("# HTLC %"PRIu64" received %s wscript %s\n", htlc->id, @@ -203,7 +203,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, u8 *p2wsh = scriptpubkey_p2wsh(tx, wscript); struct amount_sat amount = amount_msat_to_sat_round_down(self_pay); - bitcoin_tx_add_output(tx, p2wsh, &amount); + bitcoin_tx_add_output(tx, p2wsh, amount); (*htlcmap)[n] = NULL; /* We don't assign cltvs[n]: if we use it, order doesn't matter. * However, valgrind will warn us something wierd is happening */ @@ -230,7 +230,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, * This output sends funds to the other peer and thus is a simple * P2WPKH to `remotepubkey`. */ - int pos = bitcoin_tx_add_output(tx, p2wpkh, &amount); + int pos = bitcoin_tx_add_output(tx, p2wpkh, amount); assert(pos == n); (*htlcmap)[n] = NULL; /* We don't assign cltvs[n]: if we use it, order doesn't matter. @@ -287,7 +287,7 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx, * * `txin[0]` sequence: upper 8 bits are 0x80, lower 24 bits are upper 24 bits of the obscured commitment number */ u32 sequence = (0x80000000 | ((obscured_commitment_number>>24) & 0xFFFFFF)); - bitcoin_tx_add_input(tx, funding_txid, funding_txout, sequence, &funding, NULL); + bitcoin_tx_add_input(tx, funding_txid, funding_txout, sequence, funding, NULL); return tx; } diff --git a/common/close_tx.c b/common/close_tx.c index 9bcd3a153..81949597c 100644 --- a/common/close_tx.c +++ b/common/close_tx.c @@ -38,13 +38,13 @@ struct bitcoin_tx *create_close_tx(const tal_t *ctx, /* Our input spends the anchor tx output. */ bitcoin_tx_add_input(tx, anchor_txid, anchor_index, - BITCOIN_TX_DEFAULT_SEQUENCE, &funding, NULL); + BITCOIN_TX_DEFAULT_SEQUENCE, funding, NULL); if (amount_sat_greater_eq(to_us, dust_limit)) { script = tal_dup_arr(tx, u8, our_script, tal_count(our_script), 0); /* One output is to us. */ - bitcoin_tx_add_output(tx, script, &to_us); + bitcoin_tx_add_output(tx, script, to_us); num_outputs++; } @@ -52,7 +52,7 @@ struct bitcoin_tx *create_close_tx(const tal_t *ctx, script = tal_dup_arr(tx, u8, their_script, tal_count(their_script), 0); /* Other output is to them. */ - bitcoin_tx_add_output(tx, script, &to_them); + bitcoin_tx_add_output(tx, script, to_them); num_outputs++; } diff --git a/common/funding_tx.c b/common/funding_tx.c index 4bd655e5d..bcb93142b 100644 --- a/common/funding_tx.c +++ b/common/funding_tx.c @@ -32,7 +32,7 @@ struct bitcoin_tx *funding_tx(const tal_t *ctx, wscript = bitcoin_redeem_2of2(tx, local_fundingkey, remote_fundingkey); SUPERVERBOSE("# funding witness script = %s\n", tal_hex(wscript, wscript)); - bitcoin_tx_add_output(tx, scriptpubkey_p2wsh(tx, wscript), &funding); + bitcoin_tx_add_output(tx, scriptpubkey_p2wsh(tx, wscript), funding); tal_free(wscript); if (has_change) { @@ -40,7 +40,7 @@ struct bitcoin_tx *funding_tx(const tal_t *ctx, map[0] = int2ptr(0); map[1] = int2ptr(1); bitcoin_tx_add_output(tx, scriptpubkey_p2wpkh(tx, changekey), - &change); + change); permute_outputs(tx, NULL, map); *outnum = (map[0] == int2ptr(0) ? 0 : 1); } else { diff --git a/common/htlc_tx.c b/common/htlc_tx.c index d41044d07..b3f2db006 100644 --- a/common/htlc_tx.c +++ b/common/htlc_tx.c @@ -47,7 +47,7 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx, * * `txin[0]` sequence: `0` */ amount = amount_msat_to_sat_round_down(msat); - bitcoin_tx_add_input(tx, commit_txid, commit_output_number, 0, &amount, + bitcoin_tx_add_input(tx, commit_txid, commit_output_number, 0, amount, NULL); /* BOLT #3: @@ -62,7 +62,7 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx, wscript = bitcoin_wscript_htlc_tx(tx, to_self_delay, revocation_pubkey, local_delayedkey); - bitcoin_tx_add_output(tx, scriptpubkey_p2wsh(tx, wscript), &amount); + bitcoin_tx_add_output(tx, scriptpubkey_p2wsh(tx, wscript), amount); tal_free(wscript); return tx; diff --git a/common/initial_commit_tx.c b/common/initial_commit_tx.c index 7908b79c2..ee928a3ca 100644 --- a/common/initial_commit_tx.c +++ b/common/initial_commit_tx.c @@ -175,7 +175,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, u8 *wscript = to_self_wscript(tmpctx, to_self_delay, keyset); amount = amount_msat_to_sat_round_down(self_pay); int pos = bitcoin_tx_add_output( - tx, scriptpubkey_p2wsh(tx, wscript), &amount); + tx, scriptpubkey_p2wsh(tx, wscript), amount); assert(pos == n); n++; } @@ -197,7 +197,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, amount = amount_msat_to_sat_round_down(other_pay); int pos = bitcoin_tx_add_output( tx, scriptpubkey_p2wpkh(tx, &keyset->other_payment_key), - &amount); + amount); assert(pos == n); n++; } @@ -236,7 +236,7 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx, * * `txin[0]` script bytes: 0 */ sequence = (0x80000000 | ((obscured_commitment_number>>24) & 0xFFFFFF)); - bitcoin_tx_add_input(tx, funding_txid, funding_txout, sequence, &funding, NULL); + bitcoin_tx_add_input(tx, funding_txid, funding_txout, sequence, funding, NULL); assert(bitcoin_tx_check(tx)); diff --git a/common/utxo.c b/common/utxo.c index 16228a091..19ea4d74a 100644 --- a/common/utxo.c +++ b/common/utxo.c @@ -69,7 +69,7 @@ struct bitcoin_tx *tx_spending_utxos(const tal_t *ctx, bitcoin_tx_add_input(tx, &utxos[i]->txid, utxos[i]->outnum, BITCOIN_TX_DEFAULT_SEQUENCE, - &utxos[i]->amount, script); + utxos[i]->amount, script); } return tx; diff --git a/common/withdraw_tx.c b/common/withdraw_tx.c index f9a1203d2..98de861f8 100644 --- a/common/withdraw_tx.c +++ b/common/withdraw_tx.c @@ -23,14 +23,14 @@ struct bitcoin_tx *withdraw_tx(const tal_t *ctx, tx = tx_spending_utxos(ctx, chainparams, utxos, bip32_base, !amount_sat_eq(change, AMOUNT_SAT(0))); - bitcoin_tx_add_output(tx, destination, &withdraw_amount); + bitcoin_tx_add_output(tx, destination, withdraw_amount); if (!amount_sat_eq(change, AMOUNT_SAT(0))) { const void *map[2]; map[0] = int2ptr(0); map[1] = int2ptr(1); bitcoin_tx_add_output(tx, scriptpubkey_p2wpkh(tx, changekey), - &change); + change); permute_outputs(tx, NULL, map); if (change_outnum) *change_outnum = ptr2int(map[1]); diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index 3fb0733ce..5fb93d3ed 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -143,7 +143,7 @@ static bool grind_htlc_tx_fee(struct amount_sat *fee, if (!amount_sat_sub(&out, *tx->input_amounts[0], *fee)) break; - bitcoin_tx_output_set_amount(tx, 0, &out); + bitcoin_tx_output_set_amount(tx, 0, out); if (!check_tx_sig(tx, 0, NULL, wscript, &keyset->other_htlc_key, remotesig)) continue; @@ -185,7 +185,7 @@ static bool set_htlc_timeout_fee(struct bitcoin_tx *tx, type_to_string(tmpctx, struct amount_sat, &fee), type_to_string(tmpctx, struct bitcoin_tx, tx)); - bitcoin_tx_output_set_amount(tx, 0, &amount); + bitcoin_tx_output_set_amount(tx, 0, amount); return check_tx_sig(tx, 0, NULL, wscript, &keyset->other_htlc_key, remotesig); } @@ -223,7 +223,7 @@ static void set_htlc_success_fee(struct bitcoin_tx *tx, "Cannot deduct htlc-success fee %s from tx %s", type_to_string(tmpctx, struct amount_sat, &fee), type_to_string(tmpctx, struct bitcoin_tx, tx)); - bitcoin_tx_output_set_amount(tx, 0, &amt); + bitcoin_tx_output_set_amount(tx, 0, amt); if (check_tx_sig(tx, 0, NULL, wscript, @@ -317,10 +317,10 @@ static struct bitcoin_tx *tx_to_us(const tal_t *ctx, tx = bitcoin_tx(ctx, out->chainparams, 1, 1); tx->wtx->locktime = locktime; bitcoin_tx_add_input(tx, &out->txid, out->outnum, to_self_delay, - &out->sat, NULL); + out->sat, NULL); bitcoin_tx_add_output( - tx, scriptpubkey_p2wpkh(tx, &our_wallet_pubkey), &out->sat); + tx, scriptpubkey_p2wpkh(tx, &our_wallet_pubkey), out->sat); /* Worst-case sig is 73 bytes */ weight = measure_tx_weight(tx) + 1 + 3 + 73 + 0 + tal_count(wscript); @@ -355,7 +355,7 @@ static struct bitcoin_tx *tx_to_us(const tal_t *ctx, type_to_string(tmpctx, struct amount_sat, &amt)); } - bitcoin_tx_output_set_amount(tx, 0, &amt); + bitcoin_tx_output_set_amount(tx, 0, amt); if (!wire_sync_write(HSM_FD, take(hsm_sign_msg(NULL, tx, wscript)))) status_failed(STATUS_FAIL_HSM_IO, "Writing sign request to hsm");