2015-05-28 23:38:27 +02:00
|
|
|
#ifndef LIGHTNING_BITCOIN_TX_H
|
|
|
|
#define LIGHTNING_BITCOIN_TX_H
|
2016-01-21 21:08:08 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "shadouble.h"
|
2015-05-28 23:38:27 +02:00
|
|
|
#include <ccan/short_types/short_types.h>
|
2015-05-29 04:03:18 +02:00
|
|
|
#include <ccan/tal/tal.h>
|
2015-05-28 23:38:27 +02:00
|
|
|
|
|
|
|
/* We unpack varints for our in-memory representation */
|
|
|
|
#define varint_t u64
|
|
|
|
|
|
|
|
struct bitcoin_tx {
|
|
|
|
u32 version;
|
|
|
|
varint_t input_count;
|
|
|
|
struct bitcoin_tx_input *input;
|
2015-06-25 06:20:16 +02:00
|
|
|
|
2015-05-28 23:38:27 +02:00
|
|
|
varint_t output_count;
|
|
|
|
struct bitcoin_tx_output *output;
|
|
|
|
u32 lock_time;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bitcoin_tx_output {
|
|
|
|
u64 amount;
|
|
|
|
varint_t script_length;
|
|
|
|
u8 *script;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct bitcoin_tx_input {
|
|
|
|
struct sha256_double txid;
|
|
|
|
u32 index; /* output number referred to by above */
|
|
|
|
varint_t script_length;
|
|
|
|
u8 *script;
|
|
|
|
u32 sequence_number;
|
2016-04-11 09:09:53 +02:00
|
|
|
|
2016-04-11 09:13:53 +02:00
|
|
|
/* Value of the output we're spending (NULL if unknown). */
|
|
|
|
u64 *amount;
|
|
|
|
|
2016-04-11 09:09:53 +02:00
|
|
|
/* Only if BIP141 used. */
|
|
|
|
u8 **witness;
|
2015-05-28 23:38:27 +02:00
|
|
|
};
|
|
|
|
|
2015-06-02 05:29:13 +02:00
|
|
|
|
|
|
|
/* SHA256^2 the tx: simpler than sha256_tx */
|
|
|
|
void bitcoin_txid(const struct bitcoin_tx *tx, struct sha256_double *txid);
|
|
|
|
|
|
|
|
/* Useful for signature code. */
|
2015-07-24 08:30:10 +02:00
|
|
|
void sha256_tx_for_sig(struct sha256_ctx *ctx, const struct bitcoin_tx *tx,
|
|
|
|
unsigned int input_num);
|
2015-05-28 23:38:27 +02:00
|
|
|
|
2015-06-02 05:46:05 +02:00
|
|
|
/* Linear bytes of tx. */
|
|
|
|
u8 *linearize_tx(const tal_t *ctx, const struct bitcoin_tx *tx);
|
|
|
|
|
2016-04-11 09:11:53 +02:00
|
|
|
/* Force linearization in extended form; useful if 0 inputs. */
|
|
|
|
u8 *linearize_tx_force_extended(const tal_t *ctx,
|
|
|
|
const struct bitcoin_tx *tx);
|
|
|
|
|
2015-05-29 04:03:18 +02:00
|
|
|
/* Allocate a tx: you just need to fill in inputs and outputs (they're
|
|
|
|
* zeroed with inputs' sequence_number set to FFFFFFFF) */
|
|
|
|
struct bitcoin_tx *bitcoin_tx(const tal_t *ctx, varint_t input_count,
|
|
|
|
varint_t output_count);
|
|
|
|
|
2016-04-11 09:02:43 +02:00
|
|
|
/* This takes a raw bitcoin tx in hex. */
|
2016-01-21 21:11:47 +01:00
|
|
|
struct bitcoin_tx *bitcoin_tx_from_hex(const tal_t *ctx, const char *hex,
|
|
|
|
size_t hexlen);
|
2015-06-04 06:18:11 +02:00
|
|
|
|
2015-06-05 05:05:46 +02:00
|
|
|
/* 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);
|
|
|
|
|
2015-07-24 08:30:10 +02:00
|
|
|
/* Get hex string of txid (reversed, a-la bitcoind). */
|
|
|
|
bool bitcoin_txid_to_hex(const struct sha256_double *txid,
|
|
|
|
char *hexstr, size_t hexstr_len);
|
|
|
|
|
2015-05-28 23:38:27 +02:00
|
|
|
#endif /* LIGHTNING_BITCOIN_TX_H */
|