mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
bitcoin: create new wrapper type bitcoin_txid, log backward endianness.
It's just a sha256_double, but importantly when we convert it to a string (in type_to_string, which is used in logging) we use bitcoin_txid_to_hex() so it's reversed as people expect. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
ed2158c334
commit
0237e0b28c
@ -41,11 +41,17 @@ struct bitcoin_block *bitcoin_block_from_hex(const tal_t *ctx,
|
||||
bool bitcoin_blkid_from_hex(const char *hexstr, size_t hexstr_len,
|
||||
struct sha256_double *blockid)
|
||||
{
|
||||
return bitcoin_txid_from_hex(hexstr, hexstr_len, blockid);
|
||||
struct bitcoin_txid fake_txid;
|
||||
if (!bitcoin_txid_from_hex(hexstr, hexstr_len, &fake_txid))
|
||||
return false;
|
||||
*blockid = fake_txid.shad;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bitcoin_blkid_to_hex(const struct sha256_double *blockid,
|
||||
char *hexstr, size_t hexstr_len)
|
||||
{
|
||||
return bitcoin_txid_to_hex(blockid, hexstr, hexstr_len);
|
||||
struct bitcoin_txid fake_txid;
|
||||
fake_txid.shad = *blockid;
|
||||
return bitcoin_txid_to_hex(&fake_txid, hexstr, hexstr_len);
|
||||
}
|
||||
|
@ -38,7 +38,8 @@ int main(void)
|
||||
assert(tal_count(tx->input) == 1);
|
||||
assert(tal_count(tx->output) == 1);
|
||||
|
||||
reverse_bytes(tx->input[0].txid.sha.u.u8, sizeof(tx->input[0].txid));
|
||||
reverse_bytes(tx->input[0].txid.shad.sha.u.u8,
|
||||
sizeof(tx->input[0].txid));
|
||||
hexeq(&tx->input[0].txid, sizeof(tx->input[0].txid),
|
||||
"1db36e1306dfc810ea63f0cf866d475cce4e9261a5e8d1581f0d1dc485f4beb5");
|
||||
assert(tx->input[0].index == 0);
|
||||
|
27
bitcoin/tx.c
27
bitcoin/tx.c
@ -276,13 +276,13 @@ size_t measure_tx_cost(const struct bitcoin_tx *tx)
|
||||
return non_witness_len * 4 + witness_len;
|
||||
}
|
||||
|
||||
void bitcoin_txid(const struct bitcoin_tx *tx, struct sha256_double *txid)
|
||||
void bitcoin_txid(const struct bitcoin_tx *tx, struct bitcoin_txid *txid)
|
||||
{
|
||||
struct sha256_ctx ctx = SHA256_INIT;
|
||||
|
||||
/* For TXID, we never use extended form. */
|
||||
push_tx(tx, push_sha, &ctx, false);
|
||||
sha256_double_done(&ctx, txid);
|
||||
sha256_double_done(&ctx, &txid->shad);
|
||||
}
|
||||
|
||||
struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, varint_t input_count,
|
||||
@ -336,7 +336,7 @@ static void pull_input(const tal_t *ctx, const u8 **cursor, size_t *max,
|
||||
struct bitcoin_tx_input *input)
|
||||
{
|
||||
u64 script_len;
|
||||
pull_sha256_double(cursor, max, &input->txid);
|
||||
pull_sha256_double(cursor, max, &input->txid.shad);
|
||||
input->index = pull_le32(cursor, max);
|
||||
script_len = pull_length(cursor, max);
|
||||
if (script_len)
|
||||
@ -460,9 +460,7 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* <sigh>. Bitcoind represents hashes as little-endian for RPC. This didn't
|
||||
* stick for blockids (everyone else uses big-endian, eg. block explorers),
|
||||
* but it did stick for txids. */
|
||||
/* <sigh>. Bitcoind represents hashes as little-endian for RPC. */
|
||||
static void reverse_bytes(u8 *arr, size_t len)
|
||||
{
|
||||
unsigned int i;
|
||||
@ -475,18 +473,18 @@ static void reverse_bytes(u8 *arr, size_t len)
|
||||
}
|
||||
|
||||
bool bitcoin_txid_from_hex(const char *hexstr, size_t hexstr_len,
|
||||
struct sha256_double *txid)
|
||||
struct bitcoin_txid *txid)
|
||||
{
|
||||
if (!hex_decode(hexstr, hexstr_len, txid, sizeof(*txid)))
|
||||
return false;
|
||||
reverse_bytes(txid->sha.u.u8, sizeof(txid->sha.u.u8));
|
||||
reverse_bytes(txid->shad.sha.u.u8, sizeof(txid->shad.sha.u.u8));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bitcoin_txid_to_hex(const struct sha256_double *txid,
|
||||
bool bitcoin_txid_to_hex(const struct bitcoin_txid *txid,
|
||||
char *hexstr, size_t hexstr_len)
|
||||
{
|
||||
struct sha256_double rev = *txid;
|
||||
struct sha256_double rev = txid->shad;
|
||||
reverse_bytes(rev.sha.u.u8, sizeof(rev.sha.u.u8));
|
||||
return hex_encode(&rev, sizeof(rev), hexstr, hexstr_len);
|
||||
}
|
||||
@ -499,4 +497,13 @@ static char *fmt_bitcoin_tx(const tal_t *ctx, const struct bitcoin_tx *tx)
|
||||
return s;
|
||||
}
|
||||
|
||||
static char *fmt_bitcoin_txid(const tal_t *ctx, const struct bitcoin_txid *txid)
|
||||
{
|
||||
char *hexstr = tal_arr(ctx, char, hex_str_size(sizeof(*txid)));
|
||||
|
||||
bitcoin_txid_to_hex(txid, hexstr, hex_str_size(sizeof(*txid)));
|
||||
return hexstr;
|
||||
}
|
||||
|
||||
REGISTER_TYPE_TO_STRING(bitcoin_tx, fmt_bitcoin_tx);
|
||||
REGISTER_TYPE_TO_STRING(bitcoin_txid, fmt_bitcoin_txid);
|
||||
|
12
bitcoin/tx.h
12
bitcoin/tx.h
@ -7,6 +7,10 @@
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
|
||||
struct bitcoin_txid {
|
||||
struct sha256_double shad;
|
||||
};
|
||||
|
||||
struct bitcoin_tx {
|
||||
u32 version;
|
||||
struct bitcoin_tx_input *input;
|
||||
@ -20,7 +24,7 @@ struct bitcoin_tx_output {
|
||||
};
|
||||
|
||||
struct bitcoin_tx_input {
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
u32 index; /* output number referred to by above */
|
||||
u8 *script;
|
||||
u32 sequence_number;
|
||||
@ -34,7 +38,7 @@ struct bitcoin_tx_input {
|
||||
|
||||
|
||||
/* SHA256^2 the tx: simpler than sha256_tx */
|
||||
void bitcoin_txid(const struct bitcoin_tx *tx, struct sha256_double *txid);
|
||||
void bitcoin_txid(const struct bitcoin_tx *tx, struct bitcoin_txid *txid);
|
||||
|
||||
/* Useful for signature code. */
|
||||
void sha256_tx_for_sig(struct sha256_double *h, const struct bitcoin_tx *tx,
|
||||
@ -57,10 +61,10 @@ struct bitcoin_tx *bitcoin_tx_from_hex(const tal_t *ctx, const char *hex,
|
||||
|
||||
/* Parse hex string to get txid (reversed, a-la bitcoind). */
|
||||
bool bitcoin_txid_from_hex(const char *hexstr, size_t hexstr_len,
|
||||
struct sha256_double *txid);
|
||||
struct bitcoin_txid *txid);
|
||||
|
||||
/* Get hex string of txid (reversed, a-la bitcoind). */
|
||||
bool bitcoin_txid_to_hex(const struct sha256_double *txid,
|
||||
bool bitcoin_txid_to_hex(const struct bitcoin_txid *txid,
|
||||
char *hexstr, size_t hexstr_len);
|
||||
|
||||
/* Internal de-linearization functions. */
|
||||
|
@ -2351,7 +2351,7 @@ static void init_channel(struct peer *peer)
|
||||
u16 funding_txout;
|
||||
u64 local_msatoshi;
|
||||
struct pubkey funding_pubkey[NUM_SIDES];
|
||||
struct sha256_double funding_txid;
|
||||
struct bitcoin_txid funding_txid;
|
||||
enum side funder;
|
||||
enum htlc_state *hstates;
|
||||
struct fulfilled_htlc *fulfilled;
|
||||
|
@ -7,7 +7,7 @@ channel_normal_operation,11001
|
||||
# Begin! (passes gossipd-client fd)
|
||||
channel_init,1000
|
||||
channel_init,,chain_hash,struct sha256_double
|
||||
channel_init,,funding_txid,struct sha256_double
|
||||
channel_init,,funding_txid,struct bitcoin_txid
|
||||
channel_init,,funding_txout,u16
|
||||
channel_init,,funding_satoshi,u64
|
||||
channel_init,,our_config,struct channel_config
|
||||
|
|
@ -86,7 +86,7 @@ static void add_received_htlc_out(struct bitcoin_tx *tx, size_t n,
|
||||
}
|
||||
|
||||
struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
||||
const struct sha256_double *funding_txid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u64 funding_satoshis,
|
||||
enum side funder,
|
||||
|
@ -7,7 +7,6 @@
|
||||
#include <common/initial_commit_tx.h>
|
||||
|
||||
struct keyset;
|
||||
struct sha256_double;
|
||||
|
||||
/**
|
||||
* commit_tx_num_untrimmed: how many of these htlc outputs will commit tx have?
|
||||
@ -43,7 +42,7 @@ size_t commit_tx_num_untrimmed(const struct htlc **htlcs,
|
||||
* transaction, so we carefully use the terms "self" and "other" here.
|
||||
*/
|
||||
struct bitcoin_tx *commit_tx(const tal_t *ctx,
|
||||
const struct sha256_double *funding_txid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u64 funding_satoshis,
|
||||
enum side funder,
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include <string.h>
|
||||
|
||||
struct channel *new_channel(const tal_t *ctx,
|
||||
const struct sha256_double *funding_txid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u64 funding_satoshis,
|
||||
u64 local_msatoshi,
|
||||
@ -178,7 +178,7 @@ static void add_htlcs(struct bitcoin_tx ***txs,
|
||||
enum side side)
|
||||
{
|
||||
size_t i, n;
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
u32 feerate_per_kw = channel->view[side].feerate_per_kw;
|
||||
|
||||
/* Get txid of commitment transaction */
|
||||
|
@ -26,7 +26,7 @@
|
||||
* Returns state, or NULL if malformed.
|
||||
*/
|
||||
struct channel *new_channel(const tal_t *ctx,
|
||||
const struct sha256_double *funding_txid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u64 funding_satoshis,
|
||||
u64 local_msatoshi,
|
||||
|
@ -20,26 +20,14 @@
|
||||
|
||||
const void *trc;
|
||||
|
||||
static struct sha256 sha256_from_hex(const char *hex)
|
||||
{
|
||||
struct sha256 sha256;
|
||||
if (strstarts(hex, "0x"))
|
||||
hex += 2;
|
||||
if (!hex_decode(hex, strlen(hex), &sha256, sizeof(sha256)))
|
||||
abort();
|
||||
return sha256;
|
||||
}
|
||||
|
||||
/* bitcoind loves its backwards txids! */
|
||||
static struct sha256_double txid_from_hex(const char *hex)
|
||||
static struct bitcoin_txid txid_from_hex(const char *hex)
|
||||
{
|
||||
struct sha256_double sha256;
|
||||
struct sha256 rev = sha256_from_hex(hex);
|
||||
size_t i;
|
||||
struct bitcoin_txid txid;
|
||||
|
||||
for (i = 0; i < sizeof(rev); i++)
|
||||
sha256.sha.u.u8[sizeof(sha256) - 1 - i] = rev.u.u8[i];
|
||||
return sha256;
|
||||
if (!bitcoin_txid_from_hex(hex, strlen(hex), &txid))
|
||||
abort();
|
||||
return txid;
|
||||
}
|
||||
|
||||
static struct bitcoin_tx *tx_from_hex(const tal_t *ctx, const char *hex)
|
||||
@ -326,7 +314,7 @@ static void update_feerate(struct channel *channel, u32 feerate)
|
||||
int main(void)
|
||||
{
|
||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
||||
struct sha256_double funding_txid;
|
||||
struct bitcoin_txid funding_txid;
|
||||
/* We test from both sides. */
|
||||
struct channel *lchannel, *rchannel;
|
||||
u64 funding_amount_satoshi;
|
||||
|
@ -27,7 +27,7 @@ static struct bitcoin_tx *close_tx(const tal_t *ctx,
|
||||
struct crypto_state *cs,
|
||||
const struct channel_id *channel_id,
|
||||
u8 *scriptpubkey[NUM_SIDES],
|
||||
const struct sha256_double *funding_txid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u64 funding_satoshi,
|
||||
const u64 satoshi_out[NUM_SIDES],
|
||||
@ -155,7 +155,7 @@ int main(int argc, char *argv[])
|
||||
u8 *msg;
|
||||
struct privkey seed;
|
||||
struct pubkey funding_pubkey[NUM_SIDES];
|
||||
struct sha256_double funding_txid;
|
||||
struct bitcoin_txid funding_txid;
|
||||
u16 funding_txout;
|
||||
u64 funding_satoshi, satoshi_out[NUM_SIDES];
|
||||
u64 our_dust_limit;
|
||||
|
@ -5,7 +5,7 @@ closing_init,2001
|
||||
closing_init,,crypto_state,struct crypto_state
|
||||
closing_init,,gossip_index,u64
|
||||
closing_init,,seed,struct privkey
|
||||
closing_init,,funding_txid,struct sha256_double
|
||||
closing_init,,funding_txid,struct bitcoin_txid
|
||||
closing_init,,funding_txout,u16
|
||||
closing_init,,funding_satoshi,u64
|
||||
closing_init,,remote_fundingkey,struct pubkey
|
||||
|
|
@ -7,7 +7,7 @@
|
||||
struct bitcoin_tx *create_close_tx(const tal_t *ctx,
|
||||
const u8 *our_script,
|
||||
const u8 *their_script,
|
||||
const struct sha256_double *anchor_txid,
|
||||
const struct bitcoin_txid *anchor_txid,
|
||||
unsigned int anchor_index,
|
||||
u64 anchor_satoshis,
|
||||
uint64_t to_us, uint64_t to_them,
|
||||
|
@ -4,7 +4,6 @@
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
|
||||
struct sha256_double;
|
||||
struct pubkey;
|
||||
|
||||
/* Create close tx to spend the anchor tx output; doesn't fill in
|
||||
@ -12,7 +11,7 @@ struct pubkey;
|
||||
struct bitcoin_tx *create_close_tx(const tal_t *ctx,
|
||||
const u8 *our_script,
|
||||
const u8 *their_script,
|
||||
const struct sha256_double *anchor_txid,
|
||||
const struct bitcoin_txid *anchor_txid,
|
||||
unsigned int anchor_index,
|
||||
u64 anchor_satoshis,
|
||||
uint64_t to_us, uint64_t to_them,
|
||||
|
@ -8,7 +8,6 @@ struct bitcoin_tx;
|
||||
struct ext_key;
|
||||
struct privkey;
|
||||
struct pubkey;
|
||||
struct sha256_double;
|
||||
struct utxo;
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <common/keyset.h>
|
||||
|
||||
static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
|
||||
const struct sha256_double *commit_txid,
|
||||
const struct bitcoin_txid *commit_txid,
|
||||
unsigned int commit_output_number,
|
||||
u64 msatoshi,
|
||||
u16 to_self_delay,
|
||||
@ -72,7 +72,7 @@ static struct bitcoin_tx *htlc_tx(const tal_t *ctx,
|
||||
}
|
||||
|
||||
struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
|
||||
const struct sha256_double *commit_txid,
|
||||
const struct bitcoin_txid *commit_txid,
|
||||
unsigned int commit_output_number,
|
||||
u64 htlc_msatoshi,
|
||||
u16 to_self_delay,
|
||||
@ -117,7 +117,7 @@ void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success,
|
||||
}
|
||||
|
||||
struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
|
||||
const struct sha256_double *commit_txid,
|
||||
const struct bitcoin_txid *commit_txid,
|
||||
unsigned int commit_output_number,
|
||||
u64 htlc_msatoshi,
|
||||
u32 cltv_expiry,
|
||||
|
@ -6,7 +6,6 @@
|
||||
struct keyset;
|
||||
struct preimage;
|
||||
struct pubkey;
|
||||
struct sha256_double;
|
||||
|
||||
static inline u64 htlc_timeout_fee(u32 feerate_per_kw)
|
||||
{
|
||||
@ -35,7 +34,7 @@ static inline u64 htlc_success_fee(u32 feerate_per_kw)
|
||||
/* Create HTLC-success tx to spend a received HTLC commitment tx
|
||||
* output; doesn't fill in input witness. */
|
||||
struct bitcoin_tx *htlc_success_tx(const tal_t *ctx,
|
||||
const struct sha256_double *commit_txid,
|
||||
const struct bitcoin_txid *commit_txid,
|
||||
unsigned int commit_output_number,
|
||||
u64 htlc_msatoshi,
|
||||
u16 to_self_delay,
|
||||
@ -55,7 +54,7 @@ void htlc_success_tx_add_witness(struct bitcoin_tx *htlc_success,
|
||||
/* Create HTLC-timeout tx to spend an offered HTLC commitment tx
|
||||
* output; doesn't fill in input witness. */
|
||||
struct bitcoin_tx *htlc_timeout_tx(const tal_t *ctx,
|
||||
const struct sha256_double *commit_txid,
|
||||
const struct bitcoin_txid *commit_txid,
|
||||
unsigned int commit_output_number,
|
||||
u64 htlc_msatoshi,
|
||||
u32 cltv_expiry,
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include <inttypes.h>
|
||||
|
||||
struct channel *new_initial_channel(const tal_t *ctx,
|
||||
const struct sha256_double *funding_txid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u64 funding_satoshis,
|
||||
u64 local_msatoshi,
|
||||
|
@ -28,7 +28,7 @@ struct channel_view {
|
||||
|
||||
struct channel {
|
||||
/* Funding txid and output. */
|
||||
struct sha256_double funding_txid;
|
||||
struct bitcoin_txid funding_txid;
|
||||
unsigned int funding_txout;
|
||||
|
||||
/* Keys used to spend funding tx. */
|
||||
@ -142,7 +142,7 @@ static inline u16 to_self_delay(const struct channel *channel, enum side side)
|
||||
* Returns channel, or NULL if malformed.
|
||||
*/
|
||||
struct channel *new_initial_channel(const tal_t *ctx,
|
||||
const struct sha256_double *funding_txid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u64 funding_satoshis,
|
||||
u64 local_msatoshi,
|
||||
|
@ -55,7 +55,7 @@ u8 *to_self_wscript(const tal_t *ctx,
|
||||
}
|
||||
|
||||
struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
const struct sha256_double *funding_txid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u64 funding_satoshis,
|
||||
enum side funder,
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <common/htlc.h>
|
||||
|
||||
struct keyset;
|
||||
struct sha256_double;
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
@ -67,7 +66,7 @@ static inline u64 commit_tx_base_fee(u32 feerate_per_kw,
|
||||
* transaction, so we carefully use the terms "self" and "other" here.
|
||||
*/
|
||||
struct bitcoin_tx *initial_commit_tx(const tal_t *ctx,
|
||||
const struct sha256_double *funding_txid,
|
||||
const struct bitcoin_txid *funding_txid,
|
||||
unsigned int funding_txout,
|
||||
u64 funding_satoshis,
|
||||
enum side funder,
|
||||
|
@ -9,6 +9,7 @@
|
||||
union printable_types {
|
||||
const struct pubkey *pubkey;
|
||||
const struct sha256_double *sha256_double;
|
||||
const struct bitcoin_txid *bitcoin_txid;
|
||||
const struct sha256 *sha256;
|
||||
const struct ripemd160 *ripemd160;
|
||||
const struct rel_locktime *rel_locktime;
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
void towire_utxo(u8 **pptr, const struct utxo *utxo)
|
||||
{
|
||||
towire_sha256_double(pptr, &utxo->txid);
|
||||
towire_bitcoin_txid(pptr, &utxo->txid);
|
||||
towire_u32(pptr, utxo->outnum);
|
||||
towire_u64(pptr, utxo->amount);
|
||||
towire_u32(pptr, utxo->keyindex);
|
||||
@ -12,7 +12,7 @@ void towire_utxo(u8 **pptr, const struct utxo *utxo)
|
||||
|
||||
void fromwire_utxo(const u8 **ptr, size_t *max, struct utxo *utxo)
|
||||
{
|
||||
fromwire_sha256_double(ptr, max, &utxo->txid);
|
||||
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);
|
||||
|
@ -1,13 +1,13 @@
|
||||
#ifndef LIGHTNING_COMMON_UTXO_H
|
||||
#define LIGHTNING_COMMON_UTXO_H
|
||||
#include "config.h"
|
||||
#include <bitcoin/shadouble.h>
|
||||
#include <bitcoin/tx.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/tal/tal.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct utxo {
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
u32 outnum;
|
||||
u64 amount;
|
||||
u32 keyindex;
|
||||
|
@ -43,7 +43,7 @@ static void add_tx_to_block(struct block *b,
|
||||
}
|
||||
|
||||
static bool we_broadcast(const struct chain_topology *topo,
|
||||
const struct sha256_double *txid)
|
||||
const struct bitcoin_txid *txid)
|
||||
{
|
||||
const struct outgoing_tx *otx;
|
||||
|
||||
@ -74,7 +74,7 @@ static void connect_block(struct chain_topology *topo,
|
||||
/* Now we see if any of those txs are interesting. */
|
||||
for (i = 0; i < tal_count(b->full_txs); i++) {
|
||||
const struct bitcoin_tx *tx = b->full_txs[i];
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
size_t j;
|
||||
|
||||
/* Tell them if it spends a txo we care about. */
|
||||
@ -108,12 +108,12 @@ static void connect_block(struct chain_topology *topo,
|
||||
}
|
||||
|
||||
static const struct bitcoin_tx *tx_in_block(const struct block *b,
|
||||
const struct sha256_double *txid)
|
||||
const struct bitcoin_txid *txid)
|
||||
{
|
||||
size_t i, n = tal_count(b->txs);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
struct sha256_double this_txid;
|
||||
struct bitcoin_txid this_txid;
|
||||
bitcoin_txid(b->txs[i], &this_txid);
|
||||
if (structeq(&this_txid, txid))
|
||||
return b->txs[i];
|
||||
@ -123,7 +123,7 @@ static const struct bitcoin_tx *tx_in_block(const struct block *b,
|
||||
|
||||
/* FIXME: Use hash table. */
|
||||
static struct block *block_for_tx(const struct chain_topology *topo,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
const struct bitcoin_tx **tx)
|
||||
{
|
||||
struct block *b;
|
||||
@ -141,7 +141,7 @@ static struct block *block_for_tx(const struct chain_topology *topo,
|
||||
}
|
||||
|
||||
size_t get_tx_depth(const struct chain_topology *topo,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
const struct bitcoin_tx **tx)
|
||||
{
|
||||
const struct block *b;
|
||||
@ -274,7 +274,7 @@ void broadcast_tx(struct chain_topology *topo,
|
||||
tal_add_destructor2(peer, clear_otx_peer, otx);
|
||||
|
||||
log_add(topo->log, " (tx %s)",
|
||||
type_to_string(ltmp, struct sha256_double, &otx->txid));
|
||||
type_to_string(ltmp, struct bitcoin_txid, &otx->txid));
|
||||
|
||||
#if DEVELOPER
|
||||
if (topo->dev_no_broadcast) {
|
||||
@ -543,7 +543,7 @@ u32 get_feerate(const struct chain_topology *topo, enum feerate feerate)
|
||||
}
|
||||
|
||||
struct txlocator *locate_tx(const void *ctx, const struct chain_topology *topo,
|
||||
const struct sha256_double *txid)
|
||||
const struct bitcoin_txid *txid)
|
||||
{
|
||||
struct block *block = block_for_tx(topo, txid, NULL);
|
||||
if (block == NULL) {
|
||||
@ -554,7 +554,7 @@ struct txlocator *locate_tx(const void *ctx, const struct chain_topology *topo,
|
||||
loc->blkheight = block->height;
|
||||
size_t i, n = tal_count(block->txs);
|
||||
for (i = 0; i < n; i++) {
|
||||
struct sha256_double this_txid;
|
||||
struct bitcoin_txid this_txid;
|
||||
bitcoin_txid(block->txs[i], &this_txid);
|
||||
if (structeq(&this_txid, txid)){
|
||||
loc->index = block->txnums[i];
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define LIGHTNING_LIGHTNINGD_CHAINTOPOLOGY_H
|
||||
#include "config.h"
|
||||
#include <bitcoin/block.h>
|
||||
#include <bitcoin/shadouble.h>
|
||||
#include <bitcoin/tx.h>
|
||||
#include <ccan/list/list.h>
|
||||
#include <ccan/short_types/short_types.h>
|
||||
#include <ccan/structeq/structeq.h>
|
||||
@ -31,7 +31,7 @@ struct outgoing_tx {
|
||||
struct list_node list;
|
||||
struct peer *peer;
|
||||
const char *hextx;
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
void (*failed)(struct peer *peer, int exitstatus, const char *err);
|
||||
/* FIXME: Remove this. */
|
||||
struct chain_topology *topo;
|
||||
@ -139,7 +139,7 @@ struct txlocator {
|
||||
/* This is the number of blocks which would have to be mined to invalidate
|
||||
* the tx (optional tx is filled in if return is non-zero). */
|
||||
size_t get_tx_depth(const struct chain_topology *topo,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
const struct bitcoin_tx **tx);
|
||||
|
||||
/* Get highest block number. */
|
||||
@ -161,7 +161,7 @@ void setup_topology(struct chain_topology *topology,
|
||||
struct timers *timers,
|
||||
struct timerel poll_time, u32 first_peer_block);
|
||||
|
||||
struct txlocator *locate_tx(const void *ctx, const struct chain_topology *topo, const struct sha256_double *txid);
|
||||
struct txlocator *locate_tx(const void *ctx, const struct chain_topology *topo, const struct bitcoin_txid *txid);
|
||||
|
||||
void notify_new_block(struct lightningd *ld, unsigned int height);
|
||||
void notify_feerate_change(struct lightningd *ld);
|
||||
|
@ -359,7 +359,7 @@ void json_add_pubkey(struct json_result *response,
|
||||
}
|
||||
|
||||
void json_add_txid(struct json_result *result, const char *fieldname,
|
||||
const struct sha256_double *txid)
|
||||
const struct bitcoin_txid *txid)
|
||||
{
|
||||
char hex[hex_str_size(sizeof(*txid))];
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <ccan/list/list.h>
|
||||
#include <common/json.h>
|
||||
|
||||
struct sha256_double;
|
||||
struct bitcoin_txid;
|
||||
struct wireaddr;
|
||||
|
||||
/* Context for a command (from JSON, but might outlive the connection!)
|
||||
@ -69,7 +69,7 @@ void json_add_pubkey(struct json_result *response,
|
||||
|
||||
/* '"fieldname" : <hexrev>' or "<hexrev>" if fieldname is NULL */
|
||||
void json_add_txid(struct json_result *result, const char *fieldname,
|
||||
const struct sha256_double *txid);
|
||||
const struct bitcoin_txid *txid);
|
||||
|
||||
/* Extract a pubkey from this */
|
||||
bool json_tok_pubkey(const char *buffer, const jsmntok_t *tok,
|
||||
|
@ -1108,7 +1108,7 @@ static enum watch_result onchain_tx_watched(struct peer *peer,
|
||||
void *unused)
|
||||
{
|
||||
u8 *msg;
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
|
||||
if (depth == 0) {
|
||||
log_unusual(peer->log, "Chain reorganization!");
|
||||
@ -1154,7 +1154,7 @@ static enum watch_result onchain_txo_watched(struct peer *peer,
|
||||
static void watch_tx_and_outputs(struct peer *peer,
|
||||
const struct bitcoin_tx *tx)
|
||||
{
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
struct txwatch *txw;
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
@ -1379,7 +1379,7 @@ static enum watch_result funding_spent(struct peer *peer,
|
||||
void *unused)
|
||||
{
|
||||
u8 *msg, *scriptpubkey;
|
||||
struct sha256_double our_last_txid;
|
||||
struct bitcoin_txid our_last_txid;
|
||||
s64 keyindex;
|
||||
struct pubkey ourkey;
|
||||
struct htlc_stub *stubs;
|
||||
@ -1495,13 +1495,13 @@ static enum watch_result funding_lockin_cb(struct peer *peer,
|
||||
unsigned int depth,
|
||||
void *unused)
|
||||
{
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
const char *txidstr;
|
||||
struct txlocator *loc;
|
||||
bool peer_ready;
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
txidstr = type_to_string(peer, struct sha256_double, &txid);
|
||||
txidstr = type_to_string(peer, struct bitcoin_txid, &txid);
|
||||
log_debug(peer->log, "Funding tx %s depth %u of %u",
|
||||
txidstr, depth, peer->minimum_depth);
|
||||
tal_free(txidstr);
|
||||
@ -2153,7 +2153,7 @@ static void opening_funder_finished(struct subd *opening, const u8 *resp,
|
||||
u8 *msg;
|
||||
struct channel_info *channel_info;
|
||||
struct utxo *utxos;
|
||||
struct sha256_double funding_txid;
|
||||
struct bitcoin_txid funding_txid;
|
||||
struct pubkey changekey;
|
||||
struct pubkey local_fundingkey;
|
||||
struct crypto_state cs;
|
||||
@ -2221,11 +2221,11 @@ static void opening_funder_finished(struct subd *opening, const u8 *resp,
|
||||
log_debug(fc->peer->log, "%zi: %"PRIu64" satoshi (%s) %s\n",
|
||||
i, fc->utxomap[i]->amount,
|
||||
fc->utxomap[i]->is_p2sh ? "P2SH" : "SEGWIT",
|
||||
type_to_string(ltmp, struct sha256_double,
|
||||
type_to_string(ltmp, struct bitcoin_txid,
|
||||
&fc->funding_tx->input[i].txid));
|
||||
}
|
||||
|
||||
fc->peer->funding_txid = tal(fc->peer, struct sha256_double);
|
||||
fc->peer->funding_txid = tal(fc->peer, struct bitcoin_txid);
|
||||
bitcoin_txid(fc->funding_tx, fc->peer->funding_txid);
|
||||
|
||||
if (!structeq(fc->peer->funding_txid, &funding_txid)) {
|
||||
@ -2292,7 +2292,7 @@ static void opening_fundee_finished(struct subd *opening,
|
||||
/* This is a new channel_info->their_config, set its ID to 0 */
|
||||
peer->channel_info->their_config.id = 0;
|
||||
|
||||
peer->funding_txid = tal(peer, struct sha256_double);
|
||||
peer->funding_txid = tal(peer, struct bitcoin_txid);
|
||||
if (!fromwire_opening_fundee_reply(tmpctx, reply, NULL,
|
||||
&channel_info->their_config,
|
||||
remote_commit,
|
||||
@ -2334,7 +2334,7 @@ static void opening_fundee_finished(struct subd *opening,
|
||||
}
|
||||
|
||||
log_debug(peer->log, "Watching funding tx %s",
|
||||
type_to_string(reply, struct sha256_double,
|
||||
type_to_string(reply, struct bitcoin_txid,
|
||||
peer->funding_txid));
|
||||
watch_txid(peer, peer->ld->topology, peer, peer->funding_txid,
|
||||
funding_lockin_cb, NULL);
|
||||
|
@ -69,7 +69,7 @@ struct peer {
|
||||
u64 next_htlc_id;
|
||||
|
||||
/* Funding txid and amounts (once known) */
|
||||
struct sha256_double *funding_txid;
|
||||
struct bitcoin_txid *funding_txid;
|
||||
u16 funding_outnum;
|
||||
u64 funding_satoshi, push_msat;
|
||||
bool remote_funding_locked;
|
||||
|
@ -20,26 +20,14 @@ static bool print_superverbose;
|
||||
/* Turn this on to brute-force fee values */
|
||||
/*#define DEBUG */
|
||||
|
||||
static struct sha256 sha256_from_hex(const char *hex)
|
||||
{
|
||||
struct sha256 sha256;
|
||||
if (strstarts(hex, "0x"))
|
||||
hex += 2;
|
||||
if (!hex_decode(hex, strlen(hex), &sha256, sizeof(sha256)))
|
||||
abort();
|
||||
return sha256;
|
||||
}
|
||||
|
||||
/* bitcoind loves its backwards txids! */
|
||||
static struct sha256_double txid_from_hex(const char *hex)
|
||||
static struct bitcoin_txid txid_from_hex(const char *hex)
|
||||
{
|
||||
struct sha256_double sha256;
|
||||
struct sha256 rev = sha256_from_hex(hex);
|
||||
size_t i;
|
||||
struct bitcoin_txid txid;
|
||||
|
||||
for (i = 0; i < sizeof(rev); i++)
|
||||
sha256.sha.u.u8[sizeof(sha256) - 1 - i] = rev.u.u8[i];
|
||||
return sha256;
|
||||
if (!bitcoin_txid_from_hex(hex, strlen(hex), &txid))
|
||||
abort();
|
||||
return txid;
|
||||
}
|
||||
|
||||
static struct secret secret_from_hex(const char *hex)
|
||||
@ -204,7 +192,7 @@ static void report_htlcs(const struct bitcoin_tx *tx,
|
||||
{
|
||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
||||
size_t i, n;
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
struct bitcoin_tx **htlc_tx;
|
||||
secp256k1_ecdsa_signature *remotehtlcsig;
|
||||
struct keyset keyset;
|
||||
@ -439,7 +427,7 @@ static const struct htlc **invert_htlcs(const struct htlc **htlcs)
|
||||
int main(void)
|
||||
{
|
||||
tal_t *tmpctx = tal_tmpctx(NULL);
|
||||
struct sha256_double funding_txid;
|
||||
struct bitcoin_txid funding_txid;
|
||||
u64 funding_amount_satoshi, dust_limit_satoshi;
|
||||
u32 feerate_per_kw;
|
||||
u16 to_self_delay;
|
||||
|
@ -65,17 +65,18 @@ static void destroy_txowatch(struct txowatch *w)
|
||||
txowatch_hash_del(&w->topo->txowatches, w);
|
||||
}
|
||||
|
||||
const struct sha256_double *txwatch_keyof(const struct txwatch *w)
|
||||
const struct bitcoin_txid *txwatch_keyof(const struct txwatch *w)
|
||||
{
|
||||
return &w->txid;
|
||||
}
|
||||
|
||||
size_t txid_hash(const struct sha256_double *txid)
|
||||
size_t txid_hash(const struct bitcoin_txid *txid)
|
||||
{
|
||||
return siphash24(siphash_seed(), txid->sha.u.u8, sizeof(txid->sha.u.u8));
|
||||
return siphash24(siphash_seed(),
|
||||
txid->shad.sha.u.u8, sizeof(txid->shad.sha.u.u8));
|
||||
}
|
||||
|
||||
bool txwatch_eq(const struct txwatch *w, const struct sha256_double *txid)
|
||||
bool txwatch_eq(const struct txwatch *w, const struct bitcoin_txid *txid)
|
||||
{
|
||||
return structeq(&w->txid, txid);
|
||||
}
|
||||
@ -88,7 +89,7 @@ static void destroy_txwatch(struct txwatch *w)
|
||||
struct txwatch *watch_txid_(const tal_t *ctx,
|
||||
struct chain_topology *topo,
|
||||
struct peer *peer,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
enum watch_result (*cb)(struct peer *peer,
|
||||
const struct bitcoin_tx *,
|
||||
unsigned int depth,
|
||||
@ -112,7 +113,7 @@ struct txwatch *watch_txid_(const tal_t *ctx,
|
||||
}
|
||||
|
||||
bool watching_txid(const struct chain_topology *topo,
|
||||
const struct sha256_double *txid)
|
||||
const struct bitcoin_txid *txid)
|
||||
{
|
||||
return txwatch_hash_get(&topo->txwatches, txid) != NULL;
|
||||
}
|
||||
@ -127,7 +128,7 @@ struct txwatch *watch_tx_(const tal_t *ctx,
|
||||
void *arg),
|
||||
void *cb_arg)
|
||||
{
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
return watch_txid(ctx, topo, peer, &txid, cb, cb_arg);
|
||||
@ -136,7 +137,7 @@ struct txwatch *watch_tx_(const tal_t *ctx,
|
||||
struct txowatch *watch_txo_(const tal_t *ctx,
|
||||
struct chain_topology *topo,
|
||||
struct peer *peer,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
unsigned int output,
|
||||
enum watch_result (*cb)(struct peer *peer,
|
||||
const struct bitcoin_tx *tx,
|
||||
@ -173,7 +174,7 @@ static bool txw_fire(struct chain_topology *topo,
|
||||
log_debug(txw->peer->log,
|
||||
"Got depth change %u->%u for %s",
|
||||
txw->depth, depth,
|
||||
type_to_string(ltmp, struct sha256_double, &txw->txid));
|
||||
type_to_string(ltmp, struct bitcoin_txid, &txw->txid));
|
||||
txw->depth = depth;
|
||||
r = txw->cb(txw->peer, tx, txw->depth, txw->cbdata);
|
||||
switch (r) {
|
||||
@ -190,7 +191,7 @@ void txwatch_fire(struct chain_topology *topo,
|
||||
const struct bitcoin_tx *tx,
|
||||
unsigned int depth)
|
||||
{
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
struct txwatch *txw;
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
@ -206,15 +207,15 @@ void txowatch_fire(struct chain_topology *topo,
|
||||
size_t input_num,
|
||||
const struct block *block)
|
||||
{
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
enum watch_result r;
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
log_debug(txow->peer->log,
|
||||
"Got UTXO spend for %s:%u: %s",
|
||||
type_to_string(ltmp, struct sha256_double, &txow->out.txid),
|
||||
type_to_string(ltmp, struct bitcoin_txid, &txow->out.txid),
|
||||
txow->out.index,
|
||||
type_to_string(ltmp, struct sha256_double, &txid));
|
||||
type_to_string(ltmp, struct bitcoin_txid, &txid));
|
||||
|
||||
r = txow->cb(txow->peer, tx, input_num, block, txow->cbdata);
|
||||
switch (r) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef LIGHTNING_LIGHTNINGD_WATCH_H
|
||||
#define LIGHTNING_LIGHTNINGD_WATCH_H
|
||||
#include "config.h"
|
||||
#include "bitcoin/shadouble.h"
|
||||
#include <bitcoin/tx.h>
|
||||
#include <ccan/crypto/ripemd160/ripemd160.h>
|
||||
#include <ccan/htable/htable_type.h>
|
||||
#include <ccan/list/list.h>
|
||||
@ -17,7 +17,7 @@ enum watch_result {
|
||||
};
|
||||
|
||||
struct txwatch_output {
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
unsigned int index;
|
||||
};
|
||||
|
||||
@ -55,7 +55,7 @@ struct txwatch {
|
||||
struct peer *peer;
|
||||
|
||||
/* Transaction to watch. */
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
unsigned int depth;
|
||||
|
||||
/* A new depth (0 if kicked out, otherwise 1 = tip, etc.) */
|
||||
@ -67,9 +67,9 @@ struct txwatch {
|
||||
void *cbdata;
|
||||
};
|
||||
|
||||
const struct sha256_double *txwatch_keyof(const struct txwatch *w);
|
||||
size_t txid_hash(const struct sha256_double *txid);
|
||||
bool txwatch_eq(const struct txwatch *w, const struct sha256_double *txid);
|
||||
const struct bitcoin_txid *txwatch_keyof(const struct txwatch *w);
|
||||
size_t txid_hash(const struct bitcoin_txid *txid);
|
||||
bool txwatch_eq(const struct txwatch *w, const struct bitcoin_txid *txid);
|
||||
HTABLE_DEFINE_TYPE(struct txwatch, txwatch_keyof, txid_hash, txwatch_eq,
|
||||
txwatch_hash);
|
||||
|
||||
@ -77,7 +77,7 @@ HTABLE_DEFINE_TYPE(struct txwatch, txwatch_keyof, txid_hash, txwatch_eq,
|
||||
struct txwatch *watch_txid_(const tal_t *ctx,
|
||||
struct chain_topology *topo,
|
||||
struct peer *peer,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
enum watch_result (*cb)(struct peer *peer,
|
||||
const struct bitcoin_tx *,
|
||||
unsigned int depth,
|
||||
@ -115,7 +115,7 @@ struct txwatch *watch_tx_(const tal_t *ctx,
|
||||
struct txowatch *watch_txo_(const tal_t *ctx,
|
||||
struct chain_topology *topo,
|
||||
struct peer *peer,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
unsigned int output,
|
||||
enum watch_result (*cb)(struct peer *peer,
|
||||
const struct bitcoin_tx *tx,
|
||||
@ -144,7 +144,7 @@ void txowatch_fire(struct chain_topology *topo,
|
||||
const struct block *block);
|
||||
|
||||
bool watching_txid(const struct chain_topology *topo,
|
||||
const struct sha256_double *txid);
|
||||
const struct bitcoin_txid *txid);
|
||||
|
||||
void watch_topology_changed(struct chain_topology *topo);
|
||||
#endif /* LIGHTNING_LIGHTNINGD_WATCH_H */
|
||||
|
@ -68,14 +68,14 @@ struct proposed_resolution {
|
||||
|
||||
/* How it actually got resolved. */
|
||||
struct resolution {
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
unsigned int depth;
|
||||
enum tx_type tx_type;
|
||||
};
|
||||
|
||||
struct tracked_output {
|
||||
enum tx_type tx_type;
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
u32 tx_blockheight;
|
||||
u32 outnum;
|
||||
u64 satoshi;
|
||||
@ -257,7 +257,7 @@ static struct bitcoin_tx *tx_to_us(const tal_t *ctx,
|
||||
|
||||
static struct tracked_output *
|
||||
new_tracked_output(struct tracked_output ***outs,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
u32 tx_blockheight,
|
||||
enum tx_type tx_type,
|
||||
u32 outnum,
|
||||
@ -272,7 +272,7 @@ static struct tracked_output *
|
||||
|
||||
status_trace("Tracking output %u of %s: %s/%s",
|
||||
outnum,
|
||||
type_to_string(trc, struct sha256_double, txid),
|
||||
type_to_string(trc, struct bitcoin_txid, txid),
|
||||
tx_type_name(tx_type),
|
||||
output_type_name(output_type));
|
||||
|
||||
@ -298,7 +298,7 @@ static void ignore_output(struct tracked_output *out)
|
||||
{
|
||||
status_trace("Ignoring output %u of %s: %s/%s",
|
||||
out->outnum,
|
||||
type_to_string(trc, struct sha256_double, &out->txid),
|
||||
type_to_string(trc, struct bitcoin_txid, &out->txid),
|
||||
tx_type_name(out->tx_type),
|
||||
output_type_name(out->output_type));
|
||||
|
||||
@ -366,7 +366,7 @@ static void propose_resolution_at_block(struct tracked_output *out,
|
||||
|
||||
/* This simple case: true if this was resolved by our proposal. */
|
||||
static bool resolved_by_proposal(struct tracked_output *out,
|
||||
const struct sha256_double *txid)
|
||||
const struct bitcoin_txid *txid)
|
||||
{
|
||||
/* If there's no TX associated, it's not us. */
|
||||
if (!out->proposal->tx)
|
||||
@ -394,7 +394,7 @@ static bool resolved_by_proposal(struct tracked_output *out,
|
||||
|
||||
/* Otherwise, we figure out what happened and then call this. */
|
||||
static void resolved_by_other(struct tracked_output *out,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
enum tx_type tx_type)
|
||||
{
|
||||
out->resolved = tal(out, struct resolution);
|
||||
@ -406,7 +406,7 @@ static void resolved_by_other(struct tracked_output *out,
|
||||
tx_type_name(out->tx_type),
|
||||
output_type_name(out->output_type),
|
||||
tx_type_name(tx_type),
|
||||
type_to_string(trc, struct sha256_double, txid));
|
||||
type_to_string(trc, struct bitcoin_txid, txid));
|
||||
}
|
||||
|
||||
static void unknown_spend(struct tracked_output *out,
|
||||
@ -479,8 +479,8 @@ static bool is_mutual_close(const struct bitcoin_tx *tx,
|
||||
}
|
||||
|
||||
/* We only ever send out one, so matching it is easy. */
|
||||
static bool is_local_commitment(const struct sha256_double *txid,
|
||||
const struct sha256_double *our_broadcast_txid)
|
||||
static bool is_local_commitment(const struct bitcoin_txid *txid,
|
||||
const struct bitcoin_txid *our_broadcast_txid)
|
||||
{
|
||||
return structeq(txid, our_broadcast_txid);
|
||||
}
|
||||
@ -505,7 +505,7 @@ static bool all_irrevocably_resolved(struct tracked_output **outs)
|
||||
static void unwatch_tx(const struct bitcoin_tx *tx)
|
||||
{
|
||||
u8 *msg;
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
|
||||
@ -591,7 +591,7 @@ static void handle_htlc_onchain_fulfill(struct tracked_output *out,
|
||||
static void resolve_htlc_tx(struct tracked_output ***outs,
|
||||
size_t out_index,
|
||||
const struct bitcoin_tx *htlc_tx,
|
||||
const struct sha256_double *htlc_txid,
|
||||
const struct bitcoin_txid *htlc_txid,
|
||||
u32 tx_blockheight)
|
||||
{
|
||||
struct tracked_output *out;
|
||||
@ -670,7 +670,7 @@ static void output_spent(struct tracked_output ***outs,
|
||||
u32 input_num,
|
||||
u32 tx_blockheight)
|
||||
{
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
|
||||
@ -742,7 +742,7 @@ static void output_spent(struct tracked_output ***outs,
|
||||
|
||||
/* Not interesting to us, so unwatch the tx and all its outputs */
|
||||
status_trace("Notified about tx %s output %u spend, but we don't care",
|
||||
type_to_string(trc, struct sha256_double,
|
||||
type_to_string(trc, struct bitcoin_txid,
|
||||
&tx->input[input_num].txid),
|
||||
tx->input[input_num].index);
|
||||
unwatch_tx(tx);
|
||||
@ -783,7 +783,7 @@ static void update_resolution_depth(struct tracked_output *out, u32 depth)
|
||||
}
|
||||
|
||||
static void tx_new_depth(struct tracked_output **outs,
|
||||
const struct sha256_double *txid, u32 depth)
|
||||
const struct bitcoin_txid *txid, u32 depth)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
@ -932,7 +932,7 @@ static void wait_for_resolved(struct tracked_output **outs)
|
||||
{
|
||||
while (!all_irrevocably_resolved(outs)) {
|
||||
u8 *msg = wire_sync_read(outs, REQ_FD);
|
||||
struct sha256_double txid;
|
||||
struct bitcoin_txid txid;
|
||||
struct bitcoin_tx *tx = tal(msg, struct bitcoin_tx);
|
||||
u32 input_num, depth, tx_blockheight;
|
||||
struct preimage preimage;
|
||||
@ -962,7 +962,7 @@ static void set_state(enum peer_state state)
|
||||
}
|
||||
|
||||
static void handle_mutual_close(const struct bitcoin_tx *tx,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
struct tracked_output **outs)
|
||||
{
|
||||
set_state(ONCHAIND_MUTUAL);
|
||||
@ -1151,7 +1151,7 @@ static void note_missing_htlcs(u8 **htlc_scripts,
|
||||
|
||||
static void handle_our_unilateral(const struct bitcoin_tx *tx,
|
||||
u32 tx_blockheight,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
const struct secrets *secrets,
|
||||
const struct sha256 *shaseed,
|
||||
const struct pubkey *remote_revocation_basepoint,
|
||||
@ -1450,7 +1450,7 @@ static void steal_htlc(struct tracked_output *out)
|
||||
* claim all the funds.
|
||||
*/
|
||||
static void handle_their_cheat(const struct bitcoin_tx *tx,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
u32 tx_blockheight,
|
||||
const struct sha256 *revocation_preimage,
|
||||
const struct secrets *secrets,
|
||||
@ -1714,7 +1714,7 @@ static void handle_their_cheat(const struct bitcoin_tx *tx,
|
||||
|
||||
static void handle_their_unilateral(const struct bitcoin_tx *tx,
|
||||
u32 tx_blockheight,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
const struct secrets *secrets,
|
||||
const struct sha256 *shaseed,
|
||||
const struct pubkey *remote_per_commitment_point,
|
||||
@ -1950,7 +1950,7 @@ int main(int argc, char *argv[])
|
||||
struct secrets secrets;
|
||||
struct sha256 shaseed;
|
||||
struct tracked_output **outs;
|
||||
struct sha256_double our_broadcast_txid, txid;
|
||||
struct bitcoin_txid our_broadcast_txid, txid;
|
||||
secp256k1_ecdsa_signature *remote_htlc_sigs;
|
||||
u64 funding_amount_satoshi, num_htlcs;
|
||||
u8 *scriptpubkey[NUM_SIDES];
|
||||
|
@ -14,7 +14,7 @@ onchain_init,,feerate_per_kw,u32
|
||||
onchain_init,,local_dust_limit_satoshi,u64
|
||||
onchain_init,,remote_revocation_basepoint,struct pubkey
|
||||
# Gives an easy way to tell if it's our unilateral close or theirs...
|
||||
onchain_init,,our_broadcast_txid,struct sha256_double
|
||||
onchain_init,,our_broadcast_txid,struct bitcoin_txid
|
||||
onchain_init,,local_scriptpubkey_len,u16
|
||||
onchain_init,,local_scriptpubkey,local_scriptpubkey_len*u8
|
||||
onchain_init,,remote_scriptpubkey_len,u16
|
||||
@ -56,12 +56,12 @@ onchain_spent,,blockheight,u32
|
||||
|
||||
# master->onchaind: We will receive more than one of these, as depth changes.
|
||||
onchain_depth,5005
|
||||
onchain_depth,,txid,struct sha256_double
|
||||
onchain_depth,,txid,struct bitcoin_txid
|
||||
onchain_depth,,depth,u32
|
||||
|
||||
# onchaind->master: We don't want to watch this tx, or its outputs
|
||||
onchain_unwatch_tx,5006
|
||||
onchain_unwatch_tx,,txid,struct sha256_double
|
||||
onchain_unwatch_tx,,txid,struct bitcoin_txid
|
||||
onchain_unwatch_tx,,num_outputs,u32
|
||||
|
||||
# master->onchaind: We know HTLC preimage
|
||||
|
|
@ -47,7 +47,7 @@ struct state {
|
||||
/* Funding and feerate: set by opening peer. */
|
||||
u64 funding_satoshis, push_msat;
|
||||
u32 feerate_per_kw;
|
||||
struct sha256_double funding_txid;
|
||||
struct bitcoin_txid funding_txid;
|
||||
u16 funding_txout;
|
||||
|
||||
/* Secret keys and basepoint secrets. */
|
||||
@ -436,7 +436,7 @@ static u8 *funder_channel(struct state *state,
|
||||
type_to_string(trc, struct pubkey, our_funding_pubkey));
|
||||
|
||||
msg = towire_funding_created(state, &state->channel_id,
|
||||
&state->funding_txid.sha,
|
||||
&state->funding_txid,
|
||||
state->funding_txout,
|
||||
&sig);
|
||||
if (!sync_crypto_write(&state->cs, PEER_FD, msg))
|
||||
@ -643,7 +643,7 @@ static u8 *fundee_channel(struct state *state,
|
||||
"Reading funding_created: %s", strerror(errno));
|
||||
|
||||
if (!fromwire_funding_created(msg, NULL, &id_in,
|
||||
&state->funding_txid.sha,
|
||||
&state->funding_txid,
|
||||
&state->funding_txout,
|
||||
&theirsig))
|
||||
peer_failed(PEER_FD, &state->cs, &state->channel_id,
|
||||
|
@ -43,7 +43,7 @@ opening_funder_reply,,delayed_payment_basepoint,struct pubkey
|
||||
opening_funder_reply,,their_per_commit_point,struct pubkey
|
||||
opening_funder_reply,,minimum_depth,u32
|
||||
opening_funder_reply,,remote_fundingkey,struct pubkey
|
||||
opening_funder_reply,,funding_txid,struct sha256_double
|
||||
opening_funder_reply,,funding_txid,struct bitcoin_txid
|
||||
opening_funder_reply,,feerate_per_kw,u32
|
||||
|
||||
# This means they offer the open (contains their offer packet)
|
||||
@ -67,7 +67,7 @@ opening_fundee_reply,,htlc_basepoint,struct pubkey
|
||||
opening_fundee_reply,,delayed_payment_basepoint,struct pubkey
|
||||
opening_fundee_reply,,their_per_commit_point,struct pubkey
|
||||
opening_fundee_reply,,remote_fundingkey,struct pubkey
|
||||
opening_fundee_reply,,funding_txid,struct sha256_double
|
||||
opening_fundee_reply,,funding_txid,struct bitcoin_txid
|
||||
opening_fundee_reply,,funding_txout,u16
|
||||
opening_fundee_reply,,funding_satoshis,u64
|
||||
opening_fundee_reply,,push_msat,u64
|
||||
|
|
@ -19,6 +19,7 @@ type2size = {
|
||||
'struct pubkey': 33,
|
||||
'struct sha256': 32,
|
||||
'struct sha256_double': 32,
|
||||
'struct bitcoin_txid': 32,
|
||||
'u64': 8,
|
||||
'u32': 4,
|
||||
'u16': 2,
|
||||
@ -78,6 +79,7 @@ partialtypemap = {
|
||||
'features': FieldType('u8'),
|
||||
'channel_id': FieldType('struct channel_id'),
|
||||
'chain_hash': FieldType('struct sha256_double'),
|
||||
'funding_txid': FieldType('struct bitcoin_txid'),
|
||||
'pad': FieldType('pad'),
|
||||
}
|
||||
|
||||
|
@ -255,7 +255,7 @@ static bool test_channel_crud(const tal_t *ctx)
|
||||
struct wallet_channel c1, *c2 = tal(w, struct wallet_channel);
|
||||
struct peer p;
|
||||
struct channel_info ci;
|
||||
struct sha256_double *hash = tal(w, struct sha256_double);
|
||||
struct bitcoin_txid *hash = tal(w, struct bitcoin_txid);
|
||||
struct pubkey pk;
|
||||
struct changed_htlc last_commit;
|
||||
secp256k1_ecdsa_signature *sig = tal(w, secp256k1_ecdsa_signature);
|
||||
|
@ -55,7 +55,7 @@ static bool wallet_stmt2output(sqlite3_stmt *stmt, struct utxo *utxo)
|
||||
}
|
||||
|
||||
bool wallet_update_output_status(struct wallet *w,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
const u32 outnum, enum output_status oldstatus,
|
||||
enum output_status newstatus)
|
||||
{
|
||||
@ -475,7 +475,7 @@ static bool wallet_stmt2channel(struct wallet *w, sqlite3_stmt *stmt,
|
||||
|
||||
if (sqlite3_column_type(stmt, 12) != SQLITE_NULL) {
|
||||
assert(sqlite3_column_bytes(stmt, 12) == 32);
|
||||
chan->peer->funding_txid = tal(chan->peer, struct sha256_double);
|
||||
chan->peer->funding_txid = tal(chan->peer, struct bitcoin_txid);
|
||||
memcpy(chan->peer->funding_txid, sqlite3_column_blob(stmt, 12), 32);
|
||||
} else {
|
||||
chan->peer->funding_txid = NULL;
|
||||
@ -829,7 +829,7 @@ int wallet_extract_owned_outputs(struct wallet *w, const struct bitcoin_tx *tx,
|
||||
log_debug(w->log, "Owning output %zu %"PRIu64" (%s) txid %s",
|
||||
output, tx->output[output].amount,
|
||||
is_p2sh ? "P2SH" : "SEGWIT",
|
||||
type_to_string(ltmp, struct sha256_double,
|
||||
type_to_string(ltmp, struct bitcoin_txid,
|
||||
&utxo->txid));
|
||||
|
||||
if (!wallet_add_utxo(w, utxo, is_p2sh ? p2sh_wpkh : our_change)) {
|
||||
|
@ -118,7 +118,7 @@ bool wallet_add_utxo(struct wallet *w, struct utxo *utxo,
|
||||
* `output_state_any` as @oldstatus.
|
||||
*/
|
||||
bool wallet_update_output_status(struct wallet *w,
|
||||
const struct sha256_double *txid,
|
||||
const struct bitcoin_txid *txid,
|
||||
const u32 outnum, enum output_status oldstatus,
|
||||
enum output_status newstatus);
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <bitcoin/preimage.h>
|
||||
#include <bitcoin/pubkey.h>
|
||||
#include <bitcoin/shadouble.h>
|
||||
#include <bitcoin/tx.h>
|
||||
#include <ccan/build_assert/build_assert.h>
|
||||
#include <ccan/endian/endian.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
@ -176,6 +177,12 @@ void fromwire_sha256_double(const u8 **cursor, size_t *max,
|
||||
fromwire_sha256(cursor, max, &sha256d->sha);
|
||||
}
|
||||
|
||||
void fromwire_bitcoin_txid(const u8 **cursor, size_t *max,
|
||||
struct bitcoin_txid *txid)
|
||||
{
|
||||
fromwire_sha256_double(cursor, max, &txid->shad);
|
||||
}
|
||||
|
||||
void fromwire_preimage(const u8 **cursor, size_t *max, struct preimage *preimage)
|
||||
{
|
||||
fromwire(cursor, max, preimage, sizeof(*preimage));
|
||||
@ -207,7 +214,7 @@ REGISTER_TYPE_TO_HEXSTR(channel_id);
|
||||
* (ie. `funding_output_index` alters the last two bytes).
|
||||
*/
|
||||
void derive_channel_id(struct channel_id *channel_id,
|
||||
struct sha256_double *txid, u16 txout)
|
||||
struct bitcoin_txid *txid, u16 txout)
|
||||
{
|
||||
BUILD_ASSERT(sizeof(*channel_id) == sizeof(*txid));
|
||||
memcpy(channel_id, txid, sizeof(*channel_id));
|
||||
|
@ -82,7 +82,7 @@ struct msg_closing_signed {
|
||||
};
|
||||
struct msg_funding_created {
|
||||
struct channel_id temporary_channel_id;
|
||||
struct sha256 txid;
|
||||
struct bitcoin_txid txid;
|
||||
u16 output_index;
|
||||
secp256k1_ecdsa_signature signature;
|
||||
};
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "wire.h"
|
||||
#include <bitcoin/preimage.h>
|
||||
#include <bitcoin/shadouble.h>
|
||||
#include <bitcoin/tx.h>
|
||||
#include <ccan/crypto/ripemd160/ripemd160.h>
|
||||
#include <ccan/endian/endian.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
@ -119,6 +120,11 @@ void towire_sha256_double(u8 **pptr, const struct sha256_double *sha256d)
|
||||
towire_sha256(pptr, &sha256d->sha);
|
||||
}
|
||||
|
||||
void towire_bitcoin_txid(u8 **pptr, const struct bitcoin_txid *txid)
|
||||
{
|
||||
towire_sha256_double(pptr, &txid->shad);
|
||||
}
|
||||
|
||||
void towire_preimage(u8 **pptr, const struct preimage *preimage)
|
||||
{
|
||||
towire(pptr, preimage, sizeof(*preimage));
|
||||
|
@ -15,11 +15,12 @@ struct channel_id {
|
||||
u8 id[32];
|
||||
};
|
||||
|
||||
struct bitcoin_txid;
|
||||
struct preimage;
|
||||
struct ripemd160;
|
||||
|
||||
void derive_channel_id(struct channel_id *channel_id,
|
||||
struct sha256_double *txid, u16 txout);
|
||||
struct bitcoin_txid *txid, u16 txout);
|
||||
|
||||
/* Read the type; returns -1 if not long enough. cursor is a tal ptr. */
|
||||
int fromwire_peektype(const u8 *cursor);
|
||||
@ -38,6 +39,7 @@ void towire_short_channel_id(u8 **pptr,
|
||||
const struct short_channel_id *short_channel_id);
|
||||
void towire_sha256(u8 **pptr, const struct sha256 *sha256);
|
||||
void towire_sha256_double(u8 **pptr, const struct sha256_double *sha256d);
|
||||
void towire_bitcoin_txid(u8 **pptr, const struct bitcoin_txid *txid);
|
||||
void towire_preimage(u8 **pptr, const struct preimage *preimage);
|
||||
void towire_ripemd160(u8 **pptr, const struct ripemd160 *ripemd);
|
||||
void towire_u8(u8 **pptr, u8 v);
|
||||
@ -70,6 +72,8 @@ void fromwire_short_channel_id(const u8 **cursor, size_t *max,
|
||||
void fromwire_sha256(const u8 **cursor, size_t *max, struct sha256 *sha256);
|
||||
void fromwire_sha256_double(const u8 **cursor, size_t *max,
|
||||
struct sha256_double *sha256d);
|
||||
void fromwire_bitcoin_txid(const u8 **cursor, size_t *max,
|
||||
struct bitcoin_txid *txid);
|
||||
void fromwire_preimage(const u8 **cursor, size_t *max, struct preimage *preimage);
|
||||
void fromwire_ripemd160(const u8 **cursor, size_t *max, struct ripemd160 *ripemd);
|
||||
void fromwire_pad(const u8 **cursor, size_t *max, size_t num);
|
||||
|
Loading…
Reference in New Issue
Block a user