daemon/chaintopology: use struct topology for more functions, not lightningd_state

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2017-03-02 22:51:49 +10:30
parent 923526baf3
commit 61e576ef12
11 changed files with 166 additions and 138 deletions

View File

@@ -6,6 +6,7 @@
#include <ccan/list/list.h>
#include <ccan/short_types/short_types.h>
#include <ccan/structeq/structeq.h>
#include <ccan/time/time.h>
#include <daemon/watch.h>
#include <stddef.h>
@@ -80,6 +81,18 @@ struct topology {
u64 feerate;
bool startup;
/* How far back (in blocks) to go. */
unsigned int first_blocknum;
/* How often to poll. */
struct timerel poll_time;
/* The bitcoind. */
struct bitcoind *bitcoind;
/* Our timer list. */
struct timers *timers;
/* Bitcoin transctions we're broadcasting */
struct list_head outgoing_txs;
@@ -100,32 +113,37 @@ struct txlocator {
/* This is the number of blocks which would have to be mined to invalidate
* the tx. */
size_t get_tx_depth(struct lightningd_state *dstate,
size_t get_tx_depth(const struct topology *topo,
const struct sha256_double *txid);
/* Get the mediantime of the block including this tx (must be one!) */
u32 get_tx_mediantime(struct lightningd_state *dstate,
u32 get_tx_mediantime(const struct topology *topo,
const struct sha256_double *txid);
/* Get mediantime of the tip; if more than one, pick greatest time. */
u32 get_tip_mediantime(struct lightningd_state *dstate);
u32 get_tip_mediantime(const struct topology *topo);
/* Get highest block number. */
u32 get_block_height(struct lightningd_state *dstate);
u32 get_block_height(const struct topology *topo);
/* Get fee rate. */
u64 get_feerate(struct lightningd_state *dstate);
/* Broadcast a single tx, and rebroadcast as reqd (copies tx).
* If failed is non-NULL, call that and don't rebroadcast. */
void broadcast_tx(struct peer *peer, const struct bitcoin_tx *tx,
void broadcast_tx(struct topology *topo,
struct peer *peer, const struct bitcoin_tx *tx,
void (*failed)(struct peer *peer,
int exitstatus,
const char *err));
struct topology *new_topology(const tal_t *ctx);
void setup_topology(struct topology *topology, struct bitcoind *bitcoind);
void setup_topology(struct topology *topology, struct bitcoind *bitcoind,
struct timers *timers,
struct timerel poll_time, u32 first_peer_block);
struct txlocator *locate_tx(const void *ctx, struct lightningd_state *dstate, const struct sha256_double *txid);
struct txlocator *locate_tx(const void *ctx, const struct topology *topo, const struct sha256_double *txid);
void notify_new_block(struct topology *topo, unsigned int height);
#endif /* LIGHTNING_DAEMON_CRYPTOPKT_H */