2016-04-24 12:10:29 +02:00
|
|
|
#ifndef LIGHTNING_BITCOIN_BLOCK_H
|
|
|
|
#define LIGHTNING_BITCOIN_BLOCK_H
|
|
|
|
#include "config.h"
|
|
|
|
#include "bitcoin/shadouble.h"
|
|
|
|
#include <ccan/endian/endian.h>
|
2018-07-04 07:30:02 +02:00
|
|
|
#include <ccan/structeq/structeq.h>
|
2016-04-24 12:10:29 +02:00
|
|
|
#include <ccan/tal/tal.h>
|
|
|
|
|
2019-07-30 19:51:53 +02:00
|
|
|
struct chainparams;
|
|
|
|
|
2020-01-24 22:19:04 +01:00
|
|
|
enum dynafed_params_type {
|
|
|
|
DYNAFED_PARAMS_NULL,
|
|
|
|
DYNAFED_PARAMS_COMPACT,
|
|
|
|
DYNAFED_PARAMS_FULL,
|
|
|
|
};
|
|
|
|
|
2017-12-18 07:44:10 +01:00
|
|
|
struct bitcoin_blkid {
|
|
|
|
struct sha256_double shad;
|
|
|
|
};
|
2018-07-04 07:30:02 +02:00
|
|
|
/* Define bitcoin_blkid_eq (no padding) */
|
|
|
|
STRUCTEQ_DEF(bitcoin_blkid, 0, shad.sha.u);
|
2017-12-18 07:44:10 +01:00
|
|
|
|
2016-04-24 12:10:29 +02:00
|
|
|
struct bitcoin_block_hdr {
|
|
|
|
le32 version;
|
2017-12-18 07:44:10 +01:00
|
|
|
struct bitcoin_blkid prev_hash;
|
2016-04-24 12:10:29 +02:00
|
|
|
struct sha256_double merkle_hash;
|
|
|
|
le32 timestamp;
|
|
|
|
le32 target;
|
|
|
|
le32 nonce;
|
2020-01-23 13:38:13 +01:00
|
|
|
struct bitcoin_blkid hash;
|
2016-04-24 12:10:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bitcoin_block {
|
|
|
|
struct bitcoin_block_hdr hdr;
|
|
|
|
/* tal_count shows now many */
|
|
|
|
struct bitcoin_tx **tx;
|
2020-08-26 13:31:41 +02:00
|
|
|
struct bitcoin_txid *txids;
|
2016-04-24 12:10:29 +02:00
|
|
|
};
|
|
|
|
|
2019-07-30 19:51:53 +02:00
|
|
|
struct bitcoin_block *
|
|
|
|
bitcoin_block_from_hex(const tal_t *ctx, const struct chainparams *chainparams,
|
|
|
|
const char *hex, size_t hexlen);
|
2016-04-24 12:10:29 +02:00
|
|
|
|
2019-04-13 17:55:06 +02:00
|
|
|
/* Compute the double SHA block ID from the block header. */
|
|
|
|
void bitcoin_block_blkid(const struct bitcoin_block *block,
|
|
|
|
struct bitcoin_blkid *out);
|
|
|
|
|
2020-05-15 12:30:43 +02:00
|
|
|
/* Marshalling/unmarshaling over the wire */
|
|
|
|
void towire_bitcoin_blkid(u8 **pptr, const struct bitcoin_blkid *blkid);
|
|
|
|
void fromwire_bitcoin_blkid(const u8 **cursor, size_t *max,
|
|
|
|
struct bitcoin_blkid *blkid);
|
|
|
|
void fromwire_chainparams(const u8 **cursor, size_t *max,
|
|
|
|
const struct chainparams **chainparams);
|
|
|
|
void towire_chainparams(u8 **cursor, const struct chainparams *chainparams);
|
|
|
|
|
2016-04-24 12:10:29 +02:00
|
|
|
#endif /* LIGHTNING_BITCOIN_BLOCK_H */
|