From 144ab3bef4fd428108fbe7b12be1d9a9b6dba0af Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 22 Jan 2016 06:41:47 +1030 Subject: [PATCH] state: make tx arguments const. Signed-off-by: Rusty Russell --- state.c | 8 ++++---- state.h | 40 ++++++++++++++++++------------------ test/test_state_coverage.c | 42 +++++++++++++++++++------------------- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/state.c b/state.c index a08cfb09a..efcc233bd 100644 --- a/state.c +++ b/state.c @@ -82,8 +82,8 @@ static void queue_pkt(Pkt **out, Pkt *pkt) *out = pkt; } -static void queue_tx_broadcast(struct bitcoin_tx **broadcast, - struct bitcoin_tx *tx) +static void queue_tx_broadcast(const struct bitcoin_tx **broadcast, + const struct bitcoin_tx *tx) { assert(!*broadcast); assert(tx); @@ -95,10 +95,10 @@ enum command_status state(const tal_t *ctx, const enum state_input input, const union input *idata, Pkt **out, - struct bitcoin_tx **broadcast) + const struct bitcoin_tx **broadcast) { Pkt *decline; - struct bitcoin_tx *tx; + const struct bitcoin_tx *tx; Pkt *err; enum command_status cstatus = CMD_NONE; diff --git a/state.h b/state.h index dad8afa27..bf839cffd 100644 --- a/state.h +++ b/state.h @@ -40,7 +40,7 @@ enum command_status state(const tal_t *ctx, const enum state_input input, const union input *idata, Pkt **out, - struct bitcoin_tx **broadcast); + const struct bitcoin_tx **broadcast); /* Any CMD_SEND_HTLC_* */ #define CMD_SEND_UPDATE_ANY INPUT_MAX @@ -326,38 +326,38 @@ void bitcoin_create_anchor(struct peer *peer, enum state_input done); void bitcoin_release_anchor(struct peer *peer, enum state_input done); /* Get the bitcoin anchor tx. */ -struct bitcoin_tx *bitcoin_anchor(const tal_t *ctx, struct peer *peer); +const struct bitcoin_tx *bitcoin_anchor(const tal_t *ctx, struct peer *peer); /* Create a bitcoin close tx. */ -struct bitcoin_tx *bitcoin_close(const tal_t *ctx, - const struct peer *peer); +const struct bitcoin_tx *bitcoin_close(const tal_t *ctx, + const struct peer *peer); /* Create a bitcoin spend tx (to spend our commit's outputs) */ -struct bitcoin_tx *bitcoin_spend_ours(const tal_t *ctx, - const struct peer *peer); +const struct bitcoin_tx *bitcoin_spend_ours(const tal_t *ctx, + const struct peer *peer); /* Create a bitcoin spend tx (to spend their commit's outputs) */ -struct bitcoin_tx *bitcoin_spend_theirs(const tal_t *ctx, - const struct peer *peer, - const struct bitcoin_event *btc); +const struct bitcoin_tx *bitcoin_spend_theirs(const tal_t *ctx, + const struct peer *peer, + const struct bitcoin_event *btc); /* Create a bitcoin steal tx (to steal all their commit's outputs) */ -struct bitcoin_tx *bitcoin_steal(const tal_t *ctx, - const struct peer *peer, - struct bitcoin_event *btc); +const struct bitcoin_tx *bitcoin_steal(const tal_t *ctx, + const struct peer *peer, + struct bitcoin_event *btc); /* Create our commit tx */ -struct bitcoin_tx *bitcoin_commit(const tal_t *ctx, - const struct peer *peer); +const struct bitcoin_tx *bitcoin_commit(const tal_t *ctx, + const struct peer *peer); /* Create a HTLC refund collection */ -struct bitcoin_tx *bitcoin_htlc_timeout(const tal_t *ctx, - const struct peer *peer, - const struct htlc *htlc); +const struct bitcoin_tx *bitcoin_htlc_timeout(const tal_t *ctx, + const struct peer *peer, + const struct htlc *htlc); /* Create a HTLC collection */ -struct bitcoin_tx *bitcoin_htlc_spend(const tal_t *ctx, - const struct peer *peer, - const struct htlc *htlc); +const struct bitcoin_tx *bitcoin_htlc_spend(const tal_t *ctx, + const struct peer *peer, + const struct htlc *htlc); #endif /* LIGHTNING_STATE_H */ diff --git a/test/test_state_coverage.c b/test/test_state_coverage.c index 885bcc916..93b357729 100644 --- a/test/test_state_coverage.c +++ b/test/test_state_coverage.c @@ -858,7 +858,7 @@ static bool bitcoin_tx_is(const struct bitcoin_tx *btx, const char *str) return streq((const char *)btx, str); } -struct bitcoin_tx *bitcoin_anchor(const tal_t *ctx, struct peer *peer) +const struct bitcoin_tx *bitcoin_anchor(const tal_t *ctx, struct peer *peer) { if (!peer->anchor) report_trail(peer->trail, "Can't create anchor tx: no anchor!"); @@ -866,52 +866,52 @@ struct bitcoin_tx *bitcoin_anchor(const tal_t *ctx, struct peer *peer) return bitcoin_tx("anchor"); } -struct bitcoin_tx *bitcoin_close(const tal_t *ctx, - const struct peer *peer) +const struct bitcoin_tx *bitcoin_close(const tal_t *ctx, + const struct peer *peer) { return bitcoin_tx("close"); } -struct bitcoin_tx *bitcoin_spend_ours(const tal_t *ctx, - const struct peer *peer) +const struct bitcoin_tx *bitcoin_spend_ours(const tal_t *ctx, + const struct peer *peer) { return bitcoin_tx("spend our commit"); } -struct bitcoin_tx *bitcoin_spend_theirs(const tal_t *ctx, - const struct peer *peer, - const struct bitcoin_event *btc) +const struct bitcoin_tx *bitcoin_spend_theirs(const tal_t *ctx, + const struct peer *peer, + const struct bitcoin_event *btc) { return bitcoin_tx("spend their commit"); } -struct bitcoin_tx *bitcoin_steal(const tal_t *ctx, - const struct peer *peer, - struct bitcoin_event *btc) +const struct bitcoin_tx *bitcoin_steal(const tal_t *ctx, + const struct peer *peer, + struct bitcoin_event *btc) { if (fail(peer, FAIL_STEAL)) return NULL; return bitcoin_tx("steal"); } -struct bitcoin_tx *bitcoin_commit(const tal_t *ctx, - const struct peer *peer) +const struct bitcoin_tx *bitcoin_commit(const tal_t *ctx, + const struct peer *peer) { return bitcoin_tx("our commit"); } /* Create a HTLC refund collection */ -struct bitcoin_tx *bitcoin_htlc_timeout(const tal_t *ctx, - const struct peer *peer, - const struct htlc *htlc) +const struct bitcoin_tx *bitcoin_htlc_timeout(const tal_t *ctx, + const struct peer *peer, + const struct htlc *htlc) { return htlc_tx(ctx, "htlc timeout", htlc->id); } /* Create a HTLC collection */ -struct bitcoin_tx *bitcoin_htlc_spend(const tal_t *ctx, - const struct peer *peer, - const struct htlc *htlc) +const struct bitcoin_tx *bitcoin_htlc_spend(const tal_t *ctx, + const struct peer *peer, + const struct htlc *htlc) { return htlc_tx(ctx, "htlc fulfill", htlc->id); } @@ -1804,7 +1804,7 @@ static void try_input(const struct peer *peer, struct trail t; const char *problem; Pkt *output; - struct bitcoin_tx *broadcast; + const struct bitcoin_tx *broadcast; const tal_t *ctx = tal(NULL, char); enum command_status cstatus; @@ -2229,7 +2229,7 @@ static enum state_input **map_inputs(void) /* This adds to mapping_inputs every input_is() call */ if (!state_is_error(i)) { struct peer dummy; - struct bitcoin_tx *dummy_tx; + const struct bitcoin_tx *dummy_tx; Pkt *dummy_pkt; memset(&dummy, 0, sizeof(dummy)); dummy.state = i;