diff --git a/common/Makefile b/common/Makefile index 57bae7ccf..951611bea 100644 --- a/common/Makefile +++ b/common/Makefile @@ -53,6 +53,7 @@ COMMON_SRC_NOGEN := \ common/utils.c \ common/utxo.c \ common/version.c \ + common/wallet.c \ common/wallet_tx.c \ common/wireaddr.c \ common/wire_error.c \ @@ -60,7 +61,7 @@ COMMON_SRC_NOGEN := \ COMMON_SRC_GEN := common/gen_status_wire.c common/gen_peer_status_wire.c -COMMON_HEADERS_NOGEN := $(COMMON_SRC_NOGEN:.c=.h) common/overflows.h common/htlc.h common/status_levels.h common/json_command.h common/jsonrpc_errors.h common/wallet.h +COMMON_HEADERS_NOGEN := $(COMMON_SRC_NOGEN:.c=.h) common/overflows.h common/htlc.h common/status_levels.h common/json_command.h common/jsonrpc_errors.h COMMON_HEADERS_GEN := common/gen_htlc_state_names.h common/gen_status_wire.h common/gen_peer_status_wire.h COMMON_HEADERS := $(COMMON_HEADERS_GEN) $(COMMON_HEADERS_NOGEN) diff --git a/common/wallet.c b/common/wallet.c new file mode 100644 index 000000000..9c0964f55 --- /dev/null +++ b/common/wallet.c @@ -0,0 +1,12 @@ +#include + +enum wallet_tx_type fromwire_wallet_tx_type(const u8 **cursor, size_t *max) +{ + enum wallet_tx_type type = fromwire_u16(cursor, max); + return type; +} + +void towire_wallet_tx_type(u8 **pptr, const enum wallet_tx_type type) +{ + towire_u16(pptr, type); +} diff --git a/common/wallet.h b/common/wallet.h index be5303800..1315a6613 100644 --- a/common/wallet.h +++ b/common/wallet.h @@ -2,6 +2,7 @@ #define LIGHTNING_COMMON_WALLET_H #include "config.h" +#include /* Types of transactions we store in the `transactions` table. Mainly used for * display purposes later. */ @@ -19,7 +20,8 @@ enum wallet_tx_type { TX_CHANNEL_PENALTY = 512, TX_CHANNEL_CHEAT = 1024, }; -/* Any combination of the above wallet_tx_types */ -typedef unsigned short txtypes; + +enum wallet_tx_type fromwire_wallet_tx_type(const u8 **cursor, size_t *max); +void towire_wallet_tx_type(u8 **pptr, const enum wallet_tx_type type); #endif /* LIGHTNING_COMMON_WALLET_H */ diff --git a/lightningd/Makefile b/lightningd/Makefile index 88ce4ebf6..462447fd1 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -52,6 +52,7 @@ LIGHTNINGD_COMMON_OBJS := \ common/utils.o \ common/utxo.o \ common/version.o \ + common/wallet.o \ common/wallet_tx.o \ common/wire_error.o \ common/wireaddr.o \ diff --git a/lightningd/channel.c b/lightningd/channel.c index 9f1cfe971..6908bb63c 100644 --- a/lightningd/channel.c +++ b/lightningd/channel.c @@ -333,7 +333,7 @@ struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid) void channel_set_last_tx(struct channel *channel, struct bitcoin_tx *tx, const struct bitcoin_signature *sig, - txtypes txtypes) + enum wallet_tx_type txtypes) { channel->last_sig = *sig; tal_free(channel->last_tx); diff --git a/lightningd/channel.h b/lightningd/channel.h index 4fe47a95e..df48d3ada 100644 --- a/lightningd/channel.h +++ b/lightningd/channel.h @@ -76,7 +76,7 @@ struct channel { /* Last tx they gave us. */ struct bitcoin_tx *last_tx; - txtypes last_tx_type; + enum wallet_tx_type last_tx_type; struct bitcoin_signature last_sig; secp256k1_ecdsa_signature *last_htlc_sigs; @@ -203,7 +203,7 @@ struct channel *channel_by_dbid(struct lightningd *ld, const u64 dbid); void channel_set_last_tx(struct channel *channel, struct bitcoin_tx *tx, const struct bitcoin_signature *sig, - txtypes type); + enum wallet_tx_type type); static inline bool channel_can_add_htlc(const struct channel *channel) { diff --git a/lightningd/onchain_control.c b/lightningd/onchain_control.c index bbd254b78..8bf60116f 100644 --- a/lightningd/onchain_control.c +++ b/lightningd/onchain_control.c @@ -167,7 +167,7 @@ static void handle_onchain_broadcast_tx(struct channel *channel, const u8 *msg) struct bitcoin_tx *tx; struct wallet *w = channel->peer->ld->wallet; struct bitcoin_txid txid; - txtypes type; + enum wallet_tx_type type; if (!fromwire_onchain_broadcast_tx(msg, msg, &tx, &type)) { channel_internal_error(channel, "Invalid onchain_broadcast_tx"); @@ -294,7 +294,7 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg) static void onchain_transaction_annotate(struct channel *channel, const u8 *msg) { struct bitcoin_txid txid; - txtypes type; + enum wallet_tx_type type; if (!fromwire_onchain_transaction_annotate(msg, &txid, &type)) fatal("onchaind gave invalid onchain_transaction_annotate " "message: %s", diff --git a/lightningd/test/run-invoice-select-inchan.c b/lightningd/test/run-invoice-select-inchan.c index 25b294e00..2197f28db 100644 --- a/lightningd/test/run-invoice-select-inchan.c +++ b/lightningd/test/run-invoice-select-inchan.c @@ -563,8 +563,8 @@ void wallet_transaction_add(struct wallet *w UNNEEDED, const struct bitcoin_tx * { fprintf(stderr, "wallet_transaction_add called!\n"); abort(); } /* Generated stub for wallet_transaction_annotate */ void wallet_transaction_annotate(struct wallet *w UNNEEDED, - const struct bitcoin_txid *txid UNNEEDED, txtypes type UNNEEDED, - u64 channel_id UNNEEDED) + const struct bitcoin_txid *txid UNNEEDED, + enum wallet_tx_type type UNNEEDED, u64 channel_id UNNEEDED) { fprintf(stderr, "wallet_transaction_annotate called!\n"); abort(); } /* Generated stub for wallet_transaction_locate */ struct txlocator *wallet_transaction_locate(const tal_t *ctx UNNEEDED, struct wallet *w UNNEEDED, diff --git a/onchaind/Makefile b/onchaind/Makefile index aa102f1d5..4d180b537 100644 --- a/onchaind/Makefile +++ b/onchaind/Makefile @@ -70,6 +70,7 @@ ONCHAIND_COMMON_OBJS := \ common/utils.o \ common/utxo.o \ common/version.o \ + common/wallet.o \ hsmd/gen_hsm_wire.o onchaind/gen_onchain_wire.h: $(WIRE_GEN) onchaind/onchain_wire.csv diff --git a/onchaind/onchain_wire.csv b/onchaind/onchain_wire.csv index af8a113cd..c226616e4 100644 --- a/onchaind/onchain_wire.csv +++ b/onchaind/onchain_wire.csv @@ -1,5 +1,6 @@ #include #include +#include # Begin! Here's the onchain tx which spends funding tx, followed by all HTLCs. onchain_init,5001 @@ -48,7 +49,7 @@ onchain_init_reply,5101 # onchaind->master: Send out a tx. onchain_broadcast_tx,5003 onchain_broadcast_tx,,tx,struct bitcoin_tx -onchain_broadcast_tx,,type,u16 +onchain_broadcast_tx,,type,enum wallet_tx_type # master->onchaind: Notifier that an output has been spent by input_num of tx. onchain_spent,5004 @@ -105,4 +106,4 @@ onchain_dev_memleak_reply,,leak,bool # transactions. onchain_transaction_annotate,5034 onchain_transaction_annotate,,txid,struct bitcoin_txid -onchain_transaction_annotate,,type,u16 +onchain_transaction_annotate,,type,enum wallet_tx_type diff --git a/onchaind/onchaind.c b/onchaind/onchaind.c index ff495438b..cf9d567c4 100644 --- a/onchaind/onchaind.c +++ b/onchaind/onchaind.c @@ -458,7 +458,7 @@ static void ignore_output(struct tracked_output *out) out->resolved->tx_type = SELF; } -static txtypes onchain_txtype_to_wallet_txtype(enum tx_type t) +static enum wallet_tx_type onchain_txtype_to_wallet_txtype(enum tx_type t) { switch (t) { case FUNDING_TRANSACTION: @@ -980,7 +980,8 @@ static void steal_htlc_tx(struct tracked_output *out) propose_resolution(out, tx, 0, tx_type); } -static void onchain_transaction_annotate(const struct bitcoin_txid *txid, txtypes type) +static void onchain_transaction_annotate(const struct bitcoin_txid *txid, + enum wallet_tx_type type) { u8 *msg = towire_onchain_transaction_annotate(tmpctx, txid, type); wire_sync_write(REQ_FD, take(msg)); diff --git a/onchaind/test/run-grind_feerate.c b/onchaind/test/run-grind_feerate.c index 657137456..f3b205350 100644 --- a/onchaind/test/run-grind_feerate.c +++ b/onchaind/test/run-grind_feerate.c @@ -130,7 +130,7 @@ u8 *towire_onchain_add_utxo(const tal_t *ctx UNNEEDED, const struct bitcoin_txid u8 *towire_onchain_all_irrevocably_resolved(const tal_t *ctx UNNEEDED) { fprintf(stderr, "towire_onchain_all_irrevocably_resolved called!\n"); abort(); } /* Generated stub for towire_onchain_broadcast_tx */ -u8 *towire_onchain_broadcast_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, u16 type UNNEEDED) +u8 *towire_onchain_broadcast_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, enum wallet_tx_type type UNNEEDED) { fprintf(stderr, "towire_onchain_broadcast_tx called!\n"); abort(); } /* Generated stub for towire_onchain_dev_memleak_reply */ u8 *towire_onchain_dev_memleak_reply(const tal_t *ctx UNNEEDED, bool leak UNNEEDED) @@ -148,7 +148,7 @@ u8 *towire_onchain_init_reply(const tal_t *ctx UNNEEDED) u8 *towire_onchain_missing_htlc_output(const tal_t *ctx UNNEEDED, const struct htlc_stub *htlc UNNEEDED) { fprintf(stderr, "towire_onchain_missing_htlc_output called!\n"); abort(); } /* Generated stub for towire_onchain_transaction_annotate */ -u8 *towire_onchain_transaction_annotate(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, u16 type UNNEEDED) +u8 *towire_onchain_transaction_annotate(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED, enum wallet_tx_type type UNNEEDED) { fprintf(stderr, "towire_onchain_transaction_annotate called!\n"); abort(); } /* Generated stub for towire_onchain_unwatch_tx */ u8 *towire_onchain_unwatch_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_txid *txid UNNEEDED) diff --git a/wallet/wallet.c b/wallet/wallet.c index cd5659710..280d9769f 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -2416,7 +2416,7 @@ void wallet_transaction_add(struct wallet *w, const struct bitcoin_tx *tx, } void wallet_transaction_annotate(struct wallet *w, - const struct bitcoin_txid *txid, txtypes type, + const struct bitcoin_txid *txid, enum wallet_tx_type type, u64 channel_id) { sqlite3_stmt *stmt = db_select_prepare(w->db, "type, channel_id FROM transactions WHERE id=?"); diff --git a/wallet/wallet.h b/wallet/wallet.h index 603559dce..85d64f1f1 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -294,7 +294,7 @@ struct wallet_transaction { u32 blockheight; u32 txindex; u8 *rawtx; - txtypes type; + enum wallet_tx_type type; u64 channel_id; }; @@ -1047,8 +1047,8 @@ void wallet_transaction_add(struct wallet *w, const struct bitcoin_tx *tx, * after the fact with a channel number for grouping and a type for filtering. */ void wallet_transaction_annotate(struct wallet *w, - const struct bitcoin_txid *txid, txtypes type, - u64 channel_id); + const struct bitcoin_txid *txid, + enum wallet_tx_type type, u64 channel_id); /** * Get the confirmation height of a transaction we are watching by its diff --git a/wallet/walletrpc.c b/wallet/walletrpc.c index 64d9d7c5e..5a0d63ca9 100644 --- a/wallet/walletrpc.c +++ b/wallet/walletrpc.c @@ -802,7 +802,7 @@ struct { {0, NULL} }; -static void json_add_txtypes(struct json_stream *result, const char *fieldname, txtypes value) +static void json_add_txtypes(struct json_stream *result, const char *fieldname, enum wallet_tx_type value) { json_array_start(result, fieldname); for (size_t i=0; wallet_tx_type_display_names[i].name != NULL; i++) {