mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
wally: Migrate version and locktime to libwally tx
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
9609d762c8
commit
16f72cb160
18
bitcoin/tx.c
18
bitcoin/tx.c
@ -98,7 +98,7 @@ static void push_tx(const struct bitcoin_tx *tx,
|
||||
varint_t i;
|
||||
u8 flag = 0;
|
||||
|
||||
push_le32(tx->version, push, pushp);
|
||||
push_le32(tx->wtx->version, push, pushp);
|
||||
|
||||
if (bip144 && uses_witness(tx))
|
||||
flag |= SEGREGATED_WITNESS_FLAG;
|
||||
@ -133,7 +133,7 @@ static void push_tx(const struct bitcoin_tx *tx,
|
||||
if (flag & SEGREGATED_WITNESS_FLAG)
|
||||
push_witnesses(tx, push, pushp);
|
||||
|
||||
push_le32(tx->lock_time, push, pushp);
|
||||
push_le32(tx->wtx->locktime, push, pushp);
|
||||
}
|
||||
|
||||
static void push_sha(const void *data, size_t len, void *shactx_)
|
||||
@ -224,7 +224,7 @@ static void hash_for_segwit(struct sha256_ctx *ctx,
|
||||
* Double SHA256 of the serialization of:
|
||||
* 1. nVersion of the transaction (4-byte little endian)
|
||||
*/
|
||||
push_le32(tx->version, push_sha, ctx);
|
||||
push_le32(tx->wtx->version, push_sha, ctx);
|
||||
|
||||
/* 2. hashPrevouts (32-byte hash) */
|
||||
hash_prevouts(&h, tx, sighash_type);
|
||||
@ -253,7 +253,7 @@ static void hash_for_segwit(struct sha256_ctx *ctx,
|
||||
push_sha(&h, sizeof(h), ctx);
|
||||
|
||||
/* 9. nLocktime of the transaction (4-byte little endian) */
|
||||
push_le32(tx->lock_time, push_sha, ctx);
|
||||
push_le32(tx->wtx->locktime, push_sha, ctx);
|
||||
}
|
||||
|
||||
void sha256_tx_for_sig(struct sha256_double *h, const struct bitcoin_tx *tx,
|
||||
@ -349,12 +349,12 @@ struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, varint_t input_count,
|
||||
for (i = 0; i < tal_count(tx->input); i++) {
|
||||
/* We assume NULL is a zero bitmap */
|
||||
assert(tx->input[i].script == NULL);
|
||||
tx->input[i].sequence_number = 0xFFFFFFFF;
|
||||
tx->input[i].sequence_number = BITCOIN_TX_DEFAULT_SEQUENCE;
|
||||
tx->input[i].amount = NULL;
|
||||
tx->input[i].witness = NULL;
|
||||
}
|
||||
tx->lock_time = 0;
|
||||
tx->version = 2;
|
||||
tx->wtx->locktime = 0;
|
||||
tx->wtx->version = 2;
|
||||
return tx;
|
||||
}
|
||||
|
||||
@ -457,7 +457,7 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor,
|
||||
}
|
||||
tal_add_destructor(tx, bitcoin_tx_destroy);
|
||||
|
||||
tx->version = pull_le32(cursor, max);
|
||||
assert(pull_le32(cursor, max) == tx->wtx->version);
|
||||
count = pull_length(cursor, max, 32 + 4 + 4 + 1);
|
||||
/* BIP 144 marker is 0 (impossible to have tx with 0 inputs) */
|
||||
if (count == 0) {
|
||||
@ -483,7 +483,7 @@ struct bitcoin_tx *pull_bitcoin_tx(const tal_t *ctx, const u8 **cursor,
|
||||
for (i = 0; i < tal_count(tx->input); i++)
|
||||
tx->input[i].witness = NULL;
|
||||
}
|
||||
tx->lock_time = pull_le32(cursor, max);
|
||||
assert(pull_le32(cursor, max) == tx->wtx->locktime);
|
||||
|
||||
/* If we ran short, fail. */
|
||||
if (!*cursor)
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <common/amount.h>
|
||||
#include <wally_transaction.h>
|
||||
|
||||
#define BITCOIN_TX_DEFAULT_SEQUENCE 0xFFFFFFFF
|
||||
|
||||
struct bitcoin_txid {
|
||||
struct sha256_double shad;
|
||||
};
|
||||
@ -17,10 +19,8 @@ struct bitcoin_txid {
|
||||
STRUCTEQ_DEF(bitcoin_txid, 0, shad.sha.u);
|
||||
|
||||
struct bitcoin_tx {
|
||||
u32 version;
|
||||
struct bitcoin_tx_input *input;
|
||||
struct bitcoin_tx_output *output;
|
||||
u32 lock_time;
|
||||
struct wally_tx *wtx;
|
||||
};
|
||||
|
||||
|
@ -280,13 +280,13 @@ struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
||||
*
|
||||
* * version: 2
|
||||
*/
|
||||
assert(tx->version == 2);
|
||||
assert(tx->wtx->version == 2);
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
* * locktime: upper 8 bits are 0x20, lower 24 bits are the lower 24 bits of the obscured commitment number
|
||||
*/
|
||||
tx->lock_time
|
||||
tx->wtx->locktime
|
||||
= (0x20000000 | (obscured_commitment_number & 0xFFFFFF));
|
||||
|
||||
/* BOLT #3:
|
||||
|
@ -31,12 +31,12 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
|
||||
/* BOLT #3:
|
||||
* * version: 2
|
||||
*/
|
||||
assert(tx->version == 2);
|
||||
assert(tx->wtx->version == 2);
|
||||
|
||||
/* BOLT #3:
|
||||
* * locktime: `0` for HTLC-success, `cltv_expiry` for HTLC-timeout
|
||||
*/
|
||||
tx->lock_time = locktime;
|
||||
tx->wtx->locktime = locktime;
|
||||
|
||||
/* BOLT #3:
|
||||
* * txin count: 1
|
||||
|
@ -207,14 +207,14 @@ struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
*
|
||||
* * version: 2
|
||||
*/
|
||||
assert(tx->version == 2);
|
||||
assert(tx->wtx->version == 2);
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
* * locktime: upper 8 bits are 0x20, lower 24 bits are the
|
||||
* lower 24 bits of the obscured commitment number
|
||||
*/
|
||||
tx->lock_time
|
||||
tx->wtx->locktime
|
||||
= (0x20000000 | (obscured_commitment_number & 0xFFFFFF));
|
||||
|
||||
/* BOLT #3:
|
||||
|
@ -298,7 +298,7 @@ static struct bitcoin_tx *tx_to_us(const tal_t *ctx,
|
||||
u8 *msg;
|
||||
|
||||
tx = bitcoin_tx(ctx, 1, 1);
|
||||
tx->lock_time = locktime;
|
||||
tx->wtx->locktime = locktime;
|
||||
tx->input[0].sequence_number = to_self_delay;
|
||||
tx->input[0].txid = out->txid;
|
||||
tx->input[0].index = out->outnum;
|
||||
@ -647,7 +647,7 @@ static u64 unmask_commit_number(const struct bitcoin_tx *tx,
|
||||
*...
|
||||
* * `txin[0]` sequence: upper 8 bits are 0x80, lower 24 bits are upper 24 bits of the obscured commitment number
|
||||
*/
|
||||
return ((tx->lock_time & 0x00FFFFFF)
|
||||
return ((tx->wtx->locktime & 0x00FFFFFF)
|
||||
| (tx->input[0].sequence_number & (u64)0x00FFFFFF) << 24)
|
||||
^ obscurer;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user