mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-23 15:04:19 +01:00
tools/generate_wire.py: make varlen structs self-allocate.
If we tell it a struct is variable length, make fromwire() allocate and return it off ctx. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
committed by
Christian Decker
parent
6ca0c6e0ec
commit
ad8dfaca1c
@@ -78,16 +78,18 @@ void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
|
||||
fromwire_preimage(cursor, max, &fulfilled->payment_preimage);
|
||||
}
|
||||
|
||||
void fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, size_t *max,
|
||||
struct failed_htlc *failed)
|
||||
struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, size_t *max)
|
||||
{
|
||||
u16 failreason_len;
|
||||
struct failed_htlc *failed = tal(ctx, struct failed_htlc);
|
||||
|
||||
failed->id = fromwire_u64(cursor, max);
|
||||
failed->malformed = fromwire_u16(cursor, max);
|
||||
failreason_len = fromwire_u16(cursor, max);
|
||||
failed->failreason = tal_arr(ctx, u8, failreason_len);
|
||||
failed->failreason = tal_arr(failed, u8, failreason_len);
|
||||
fromwire_u8_array(cursor, max, failed->failreason, failreason_len);
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
enum htlc_state fromwire_htlc_state(const u8 **cursor, size_t *max)
|
||||
|
||||
@@ -47,8 +47,8 @@ void fromwire_added_htlc(const u8 **cursor, size_t *max,
|
||||
struct added_htlc *added);
|
||||
void fromwire_fulfilled_htlc(const u8 **cursor, size_t *max,
|
||||
struct fulfilled_htlc *fulfilled);
|
||||
void fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor, size_t *max,
|
||||
struct failed_htlc *failed);
|
||||
struct failed_htlc *fromwire_failed_htlc(const tal_t *ctx, const u8 **cursor,
|
||||
size_t *max);
|
||||
void fromwire_changed_htlc(const u8 **cursor, size_t *max,
|
||||
struct changed_htlc *changed);
|
||||
enum htlc_state fromwire_htlc_state(const u8 **cursor, size_t *max);
|
||||
|
||||
@@ -20,21 +20,24 @@ void towire_utxo(u8 **pptr, const struct utxo *utxo)
|
||||
}
|
||||
}
|
||||
|
||||
void fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max, struct utxo *utxo)
|
||||
struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max)
|
||||
{
|
||||
struct utxo *utxo = tal(ctx, struct utxo);
|
||||
|
||||
fromwire_bitcoin_txid(ptr, max, &utxo->txid);
|
||||
utxo->outnum = fromwire_u32(ptr, max);
|
||||
utxo->amount = fromwire_u64(ptr, max);
|
||||
utxo->keyindex = fromwire_u32(ptr, max);
|
||||
utxo->is_p2sh = fromwire_bool(ptr, max);
|
||||
if (fromwire_bool(ptr, max)) {
|
||||
utxo->close_info = tal(ctx, struct unilateral_close_info);
|
||||
utxo->close_info = tal(utxo, struct unilateral_close_info);
|
||||
utxo->close_info->channel_id = fromwire_u64(ptr, max);
|
||||
fromwire_pubkey(ptr, max, &utxo->close_info->peer_id);
|
||||
fromwire_pubkey(ptr, max, &utxo->close_info->commitment_point);
|
||||
} else {
|
||||
utxo->close_info = NULL;
|
||||
}
|
||||
return utxo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ struct utxo {
|
||||
};
|
||||
|
||||
void towire_utxo(u8 **pptr, const struct utxo *utxo);
|
||||
void fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max, struct utxo *utxo);
|
||||
struct utxo *fromwire_utxo(const tal_t *ctx, const u8 **ptr, size_t *max);
|
||||
|
||||
/* build_utxos/funding_tx use array of pointers, but marshall code
|
||||
* wants arr of structs */
|
||||
|
||||
Reference in New Issue
Block a user