mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 15:14:23 +01:00
wallet: keep a list of unreleased transactions.
We're going to use this in the next patch. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -72,9 +72,6 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
|
|||||||
const struct channel_id *channel UNNEEDED,
|
const struct channel_id *channel UNNEEDED,
|
||||||
const char *fmt UNNEEDED, ...)
|
const char *fmt UNNEEDED, ...)
|
||||||
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
||||||
/* Generated stub for towire_gossipd_local_add_channel */
|
|
||||||
u8 *towire_gossipd_local_add_channel(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED, const struct node_id *remote_node_id UNNEEDED, struct amount_sat satoshis UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire_gossipd_local_add_channel called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire_gossip_store_channel_amount */
|
/* Generated stub for towire_gossip_store_channel_amount */
|
||||||
u8 *towire_gossip_store_channel_amount(const tal_t *ctx UNNEEDED, struct amount_sat satoshis UNNEEDED)
|
u8 *towire_gossip_store_channel_amount(const tal_t *ctx UNNEEDED, struct amount_sat satoshis UNNEEDED)
|
||||||
{ fprintf(stderr, "towire_gossip_store_channel_amount called!\n"); abort(); }
|
{ fprintf(stderr, "towire_gossip_store_channel_amount called!\n"); abort(); }
|
||||||
|
|||||||
@@ -61,9 +61,6 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
|
|||||||
const struct channel_id *channel UNNEEDED,
|
const struct channel_id *channel UNNEEDED,
|
||||||
const char *fmt UNNEEDED, ...)
|
const char *fmt UNNEEDED, ...)
|
||||||
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
||||||
/* Generated stub for towire_gossipd_local_add_channel */
|
|
||||||
u8 *towire_gossipd_local_add_channel(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED, const struct node_id *remote_node_id UNNEEDED, struct amount_sat satoshis UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire_gossipd_local_add_channel called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire_gossip_store_channel_amount */
|
/* Generated stub for towire_gossip_store_channel_amount */
|
||||||
u8 *towire_gossip_store_channel_amount(const tal_t *ctx UNNEEDED, struct amount_sat satoshis UNNEEDED)
|
u8 *towire_gossip_store_channel_amount(const tal_t *ctx UNNEEDED, struct amount_sat satoshis UNNEEDED)
|
||||||
{ fprintf(stderr, "towire_gossip_store_channel_amount called!\n"); abort(); }
|
{ fprintf(stderr, "towire_gossip_store_channel_amount called!\n"); abort(); }
|
||||||
|
|||||||
@@ -59,9 +59,6 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
|
|||||||
const struct channel_id *channel UNNEEDED,
|
const struct channel_id *channel UNNEEDED,
|
||||||
const char *fmt UNNEEDED, ...)
|
const char *fmt UNNEEDED, ...)
|
||||||
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
||||||
/* Generated stub for towire_gossipd_local_add_channel */
|
|
||||||
u8 *towire_gossipd_local_add_channel(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED, const struct node_id *remote_node_id UNNEEDED, struct amount_sat satoshis UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire_gossipd_local_add_channel called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire_gossip_store_channel_amount */
|
/* Generated stub for towire_gossip_store_channel_amount */
|
||||||
u8 *towire_gossip_store_channel_amount(const tal_t *ctx UNNEEDED, struct amount_sat satoshis UNNEEDED)
|
u8 *towire_gossip_store_channel_amount(const tal_t *ctx UNNEEDED, struct amount_sat satoshis UNNEEDED)
|
||||||
{ fprintf(stderr, "towire_gossip_store_channel_amount called!\n"); abort(); }
|
{ fprintf(stderr, "towire_gossip_store_channel_amount called!\n"); abort(); }
|
||||||
|
|||||||
@@ -59,9 +59,6 @@ u8 *towire_errorfmt(const tal_t *ctx UNNEEDED,
|
|||||||
const struct channel_id *channel UNNEEDED,
|
const struct channel_id *channel UNNEEDED,
|
||||||
const char *fmt UNNEEDED, ...)
|
const char *fmt UNNEEDED, ...)
|
||||||
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
{ fprintf(stderr, "towire_errorfmt called!\n"); abort(); }
|
||||||
/* Generated stub for towire_gossipd_local_add_channel */
|
|
||||||
u8 *towire_gossipd_local_add_channel(const tal_t *ctx UNNEEDED, const struct short_channel_id *short_channel_id UNNEEDED, const struct node_id *remote_node_id UNNEEDED, struct amount_sat satoshis UNNEEDED)
|
|
||||||
{ fprintf(stderr, "towire_gossipd_local_add_channel called!\n"); abort(); }
|
|
||||||
/* Generated stub for towire_gossip_store_channel_amount */
|
/* Generated stub for towire_gossip_store_channel_amount */
|
||||||
u8 *towire_gossip_store_channel_amount(const tal_t *ctx UNNEEDED, struct amount_sat satoshis UNNEEDED)
|
u8 *towire_gossip_store_channel_amount(const tal_t *ctx UNNEEDED, struct amount_sat satoshis UNNEEDED)
|
||||||
{ fprintf(stderr, "towire_gossip_store_channel_amount called!\n"); abort(); }
|
{ fprintf(stderr, "towire_gossip_store_channel_amount called!\n"); abort(); }
|
||||||
|
|||||||
@@ -831,6 +831,7 @@ int main(int argc, char *argv[])
|
|||||||
* unreserving UTXOs (see #1737) */
|
* unreserving UTXOs (see #1737) */
|
||||||
db_begin_transaction(ld->wallet->db);
|
db_begin_transaction(ld->wallet->db);
|
||||||
tal_free(ld->jsonrpc);
|
tal_free(ld->jsonrpc);
|
||||||
|
free_unreleased_txs(ld->wallet);
|
||||||
db_commit_transaction(ld->wallet->db);
|
db_commit_transaction(ld->wallet->db);
|
||||||
|
|
||||||
remove(ld->pidfile);
|
remove(ld->pidfile);
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ void fatal(const char *fmt UNNEEDED, ...)
|
|||||||
/* Generated stub for free_htlcs */
|
/* Generated stub for free_htlcs */
|
||||||
void free_htlcs(struct lightningd *ld UNNEEDED, const struct channel *channel UNNEEDED)
|
void free_htlcs(struct lightningd *ld UNNEEDED, const struct channel *channel UNNEEDED)
|
||||||
{ fprintf(stderr, "free_htlcs called!\n"); abort(); }
|
{ fprintf(stderr, "free_htlcs called!\n"); abort(); }
|
||||||
|
/* Generated stub for free_unreleased_txs */
|
||||||
|
void free_unreleased_txs(struct wallet *w UNNEEDED)
|
||||||
|
{ fprintf(stderr, "free_unreleased_txs called!\n"); abort(); }
|
||||||
/* Generated stub for fromwire_status_fail */
|
/* Generated stub for fromwire_status_fail */
|
||||||
bool fromwire_status_fail(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, enum status_failreason *failreason UNNEEDED, wirestring **desc UNNEEDED)
|
bool fromwire_status_fail(const tal_t *ctx UNNEEDED, const void *p UNNEEDED, enum status_failreason *failreason UNNEEDED, wirestring **desc UNNEEDED)
|
||||||
{ fprintf(stderr, "fromwire_status_fail called!\n"); abort(); }
|
{ fprintf(stderr, "fromwire_status_fail called!\n"); abort(); }
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ struct wallet *wallet_new(struct lightningd *ld,
|
|||||||
wallet->log = log;
|
wallet->log = log;
|
||||||
wallet->bip32_base = NULL;
|
wallet->bip32_base = NULL;
|
||||||
list_head_init(&wallet->unstored_payments);
|
list_head_init(&wallet->unstored_payments);
|
||||||
|
list_head_init(&wallet->unreleased_txs);
|
||||||
|
|
||||||
db_begin_transaction(wallet->db);
|
db_begin_transaction(wallet->db);
|
||||||
wallet->invoices = invoices_new(wallet, wallet->db, log, timers);
|
wallet->invoices = invoices_new(wallet, wallet->db, log, timers);
|
||||||
@@ -2699,3 +2700,42 @@ const struct forwarding *wallet_forwarded_payments_get(struct wallet *w,
|
|||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct unreleased_tx *find_unreleased_tx(struct wallet *w,
|
||||||
|
const struct bitcoin_txid *txid)
|
||||||
|
{
|
||||||
|
struct unreleased_tx *utx;
|
||||||
|
|
||||||
|
list_for_each(&w->unreleased_txs, utx, list) {
|
||||||
|
if (bitcoin_txid_eq(txid, &utx->txid))
|
||||||
|
return utx;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void destroy_unreleased_tx(struct unreleased_tx *utx)
|
||||||
|
{
|
||||||
|
list_del(&utx->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove_unreleased_tx(struct unreleased_tx *utx)
|
||||||
|
{
|
||||||
|
tal_del_destructor(utx, destroy_unreleased_tx);
|
||||||
|
list_del(&utx->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_unreleased_tx(struct wallet *w, struct unreleased_tx *utx)
|
||||||
|
{
|
||||||
|
list_add_tail(&w->unreleased_txs, &utx->list);
|
||||||
|
tal_add_destructor(utx, destroy_unreleased_tx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* These will touch the db, so need to be explicitly freed. */
|
||||||
|
void free_unreleased_txs(struct wallet *w)
|
||||||
|
{
|
||||||
|
struct unreleased_tx *utx;
|
||||||
|
|
||||||
|
while ((utx = list_top(&w->unreleased_txs, struct unreleased_tx, list)))
|
||||||
|
tal_free(utx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,24 @@ struct wallet {
|
|||||||
/* Filter matching all outpoints that might be a funding transaction on
|
/* Filter matching all outpoints that might be a funding transaction on
|
||||||
* the blockchain. This is currently all P2WSH outputs */
|
* the blockchain. This is currently all P2WSH outputs */
|
||||||
struct outpointfilter *utxoset_outpoints;
|
struct outpointfilter *utxoset_outpoints;
|
||||||
|
|
||||||
|
/* Unreleased txs, waiting for txdiscard/txsend */
|
||||||
|
struct list_head unreleased_txs;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* A transaction we've txprepared, but haven't signed and released yet */
|
||||||
|
struct unreleased_tx {
|
||||||
|
/* In wallet->unreleased_txs */
|
||||||
|
struct list_node list;
|
||||||
|
/* All the utxos. */
|
||||||
|
struct wallet_tx *wtx;
|
||||||
|
/* Scriptpubkey this pays to. */
|
||||||
|
const u8 *destination;
|
||||||
|
/* The tx itself (unsigned initially) */
|
||||||
|
struct bitcoin_tx *tx;
|
||||||
|
struct bitcoin_txid txid;
|
||||||
|
/* Index of change output, or -1 if none. */
|
||||||
|
int change_outnum;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Possible states for tracked outputs in the database. Not sure yet
|
/* Possible states for tracked outputs in the database. Not sure yet
|
||||||
@@ -1080,4 +1098,13 @@ const struct forwarding *wallet_forwarded_payments_get(struct wallet *w,
|
|||||||
bool wallet_remote_ann_sigs_load(const tal_t *ctx, struct wallet *w, u64 id,
|
bool wallet_remote_ann_sigs_load(const tal_t *ctx, struct wallet *w, u64 id,
|
||||||
secp256k1_ecdsa_signature **remote_ann_node_sig,
|
secp256k1_ecdsa_signature **remote_ann_node_sig,
|
||||||
secp256k1_ecdsa_signature **remote_ann_bitcoin_sig);
|
secp256k1_ecdsa_signature **remote_ann_bitcoin_sig);
|
||||||
|
|
||||||
|
/* Operations for unreleased transactions */
|
||||||
|
struct unreleased_tx *find_unreleased_tx(struct wallet *w,
|
||||||
|
const struct bitcoin_txid *txid);
|
||||||
|
void remove_unreleased_tx(struct unreleased_tx *utx);
|
||||||
|
void add_unreleased_tx(struct wallet *w, struct unreleased_tx *utx);
|
||||||
|
|
||||||
|
/* These will touch the db, so need to be explicitly freed. */
|
||||||
|
void free_unreleased_txs(struct wallet *w);
|
||||||
#endif /* LIGHTNING_WALLET_WALLET_H */
|
#endif /* LIGHTNING_WALLET_WALLET_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user