core-lightning/bitcoin/block.h
Christian Decker 436da7f231 elements: Move blkid computation into its own function
The header is not a contiguous section of memory in elements, and it is of
variable length, so the simple trick of hashing in-memory data won't work
anymore. Some of the datafields would have been wrong on big-endian machines
anyway, so this is better anyway.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
2019-10-03 04:32:57 +00:00

61 lines
1.5 KiB
C

#ifndef LIGHTNING_BITCOIN_BLOCK_H
#define LIGHTNING_BITCOIN_BLOCK_H
#include "config.h"
#include "bitcoin/shadouble.h"
#include <ccan/endian/endian.h>
#include <ccan/short_types/short_types.h>
#include <ccan/structeq/structeq.h>
#include <ccan/tal/tal.h>
#include <stdbool.h>
struct chainparams;
struct bitcoin_blkid {
struct sha256_double shad;
};
/* Define bitcoin_blkid_eq (no padding) */
STRUCTEQ_DEF(bitcoin_blkid, 0, shad.sha.u);
struct bitcoin_block_hdr {
le32 version;
struct bitcoin_blkid prev_hash;
struct sha256_double merkle_hash;
le32 timestamp;
le32 target;
le32 nonce;
};
struct elements_block_proof {
u8 *challenge;
u8 *solution;
};
struct elements_block_hdr {
u32 block_height;
struct elements_block_proof proof;
};
struct bitcoin_block {
struct bitcoin_block_hdr hdr;
struct elements_block_hdr *elements_hdr;
/* tal_count shows now many */
struct bitcoin_tx **tx;
};
struct bitcoin_block *
bitcoin_block_from_hex(const tal_t *ctx, const struct chainparams *chainparams,
const char *hex, size_t hexlen);
/* Compute the double SHA block ID from the block header. */
void bitcoin_block_blkid(const struct bitcoin_block *block,
struct bitcoin_blkid *out);
/* Parse hex string to get blockid (reversed, a-la bitcoind). */
bool bitcoin_blkid_from_hex(const char *hexstr, size_t hexstr_len,
struct bitcoin_blkid *blockid);
/* Get hex string of blockid (reversed, a-la bitcoind). */
bool bitcoin_blkid_to_hex(const struct bitcoin_blkid *blockid,
char *hexstr, size_t hexstr_len);
#endif /* LIGHTNING_BITCOIN_BLOCK_H */