Browse Source

wallet: Rip out the txtypes type in favor of enum wallet_tx_type

Suggested-by: Rusty Russell <@rustyrussell>
Signed-off-by: Christian Decker <decker.christian@gmail.com>
pull/2938/head
Christian Decker 6 years ago
committed by Rusty Russell
parent
commit
b6b548a983
  1. 3
      common/Makefile
  2. 12
      common/wallet.c
  3. 6
      common/wallet.h
  4. 1
      lightningd/Makefile
  5. 2
      lightningd/channel.c
  6. 4
      lightningd/channel.h
  7. 4
      lightningd/onchain_control.c
  8. 4
      lightningd/test/run-invoice-select-inchan.c
  9. 1
      onchaind/Makefile
  10. 5
      onchaind/onchain_wire.csv
  11. 5
      onchaind/onchaind.c
  12. 4
      onchaind/test/run-grind_feerate.c
  13. 2
      wallet/wallet.c
  14. 6
      wallet/wallet.h
  15. 2
      wallet/walletrpc.c

3
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)

12
common/wallet.c

@ -0,0 +1,12 @@
#include <common/wallet.h>
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);
}

6
common/wallet.h

@ -2,6 +2,7 @@
#define LIGHTNING_COMMON_WALLET_H
#include "config.h"
#include <wire/wire.h>
/* 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 */

1
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 \

2
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);

4
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)
{

4
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",

4
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,

1
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

5
onchaind/onchain_wire.csv

@ -1,5 +1,6 @@
#include <common/derive_basepoints.h>
#include <common/htlc_wire.h>
#include <common/wallet.h>
# 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

Can't render this file because it has a wrong number of fields in line 4.

5
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));

4
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)

2
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=?");

6
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

2
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++) {

Loading…
Cancel
Save