mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-21 14:24:09 +01:00
wire: serialize the amounts for a bitcoin tx over the wire
we'll need this for calculating fees etc in onchaind
This commit is contained in:
parent
e8d10edbe5
commit
15e4e922c9
2 changed files with 35 additions and 1 deletions
|
@ -368,7 +368,24 @@ void derive_channel_id(struct channel_id *channel_id,
|
|||
struct bitcoin_tx *fromwire_bitcoin_tx(const tal_t *ctx,
|
||||
const u8 **cursor, size_t *max)
|
||||
{
|
||||
return pull_bitcoin_tx(ctx, cursor, max);
|
||||
struct bitcoin_tx *tx;
|
||||
u16 input_amts_len;
|
||||
size_t i;
|
||||
|
||||
tx = pull_bitcoin_tx(ctx, cursor, max);
|
||||
input_amts_len = fromwire_u16(cursor, max);
|
||||
/* We don't serialize the amounts if they're not *all* populated */
|
||||
if (input_amts_len != tal_count(tx->input_amounts))
|
||||
return tx;
|
||||
|
||||
for (i = 0; i < input_amts_len; i++) {
|
||||
struct amount_sat sat;
|
||||
sat = fromwire_amount_sat(cursor, max);
|
||||
tx->input_amounts[i] =
|
||||
tal_dup(tx, struct amount_sat, &sat);
|
||||
}
|
||||
|
||||
return tx;
|
||||
}
|
||||
|
||||
void fromwire_siphash_seed(const u8 **cursor, size_t *max,
|
||||
|
|
|
@ -226,8 +226,25 @@ void towire_wirestring(u8 **pptr, const char *str)
|
|||
|
||||
void towire_bitcoin_tx(u8 **pptr, const struct bitcoin_tx *tx)
|
||||
{
|
||||
size_t i;
|
||||
u8 *lin = linearize_tx(tmpctx, tx);
|
||||
towire_u8_array(pptr, lin, tal_count(lin));
|
||||
|
||||
/* We only want to 'save' the amounts if every amount
|
||||
* has been populated */
|
||||
for (i = 0; i < tal_count(tx->input_amounts); i++) {
|
||||
if (!tx->input_amounts[i]) {
|
||||
towire_u16(pptr, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Otherwise, we include the input amount set */
|
||||
towire_u16(pptr, tal_count(tx->input_amounts));
|
||||
for (i = 0; i < tal_count(tx->input_amounts); i++) {
|
||||
assert(tx->input_amounts[i]);
|
||||
towire_amount_sat(pptr, *tx->input_amounts[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void towire_siphash_seed(u8 **pptr, const struct siphash_seed *seed)
|
||||
|
|
Loading…
Add table
Reference in a new issue