mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-19 05:44:12 +01:00
onchaind: Store and annotate transactions we broadcast ourselves
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
parent
05dbf1a2a9
commit
ae0bc4aed0
@ -165,12 +165,19 @@ static void watch_tx_and_outputs(struct channel *channel,
|
||||
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;
|
||||
|
||||
if (!fromwire_onchain_broadcast_tx(msg, msg, &tx)) {
|
||||
if (!fromwire_onchain_broadcast_tx(msg, msg, &tx, &type)) {
|
||||
channel_internal_error(channel, "Invalid onchain_broadcast_tx");
|
||||
return;
|
||||
}
|
||||
|
||||
bitcoin_txid(tx, &txid);
|
||||
wallet_transaction_add(w, tx, 0, 0);
|
||||
wallet_transaction_annotate(w, &txid, type, channel->dbid);
|
||||
|
||||
/* We don't really care if it fails, we'll respond via watch. */
|
||||
broadcast_tx(channel->peer->ld->topology, channel, tx, NULL);
|
||||
}
|
||||
|
@ -48,6 +48,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
|
||||
|
||||
# master->onchaind: Notifier that an output has been spent by input_num of tx.
|
||||
onchain_spent,5004
|
||||
|
|
@ -15,6 +15,7 @@
|
||||
#include <common/type_to_string.h>
|
||||
#include <common/utils.h>
|
||||
#include <common/version.h>
|
||||
#include <common/wallet.h>
|
||||
#include <errno.h>
|
||||
#include <hsmd/gen_hsm_wire.h>
|
||||
#include <inttypes.h>
|
||||
@ -457,6 +458,41 @@ static void ignore_output(struct tracked_output *out)
|
||||
out->resolved->tx_type = SELF;
|
||||
}
|
||||
|
||||
static txtypes onchain_txtype_to_wallet_txtype(enum tx_type t)
|
||||
{
|
||||
switch (t) {
|
||||
case FUNDING_TRANSACTION:
|
||||
return TX_CHANNEL_FUNDING;
|
||||
case MUTUAL_CLOSE:
|
||||
return TX_CHANNEL_CLOSE;
|
||||
case OUR_UNILATERAL:
|
||||
return TX_CHANNEL_UNILATERAL;
|
||||
case THEIR_HTLC_FULFILL_TO_US:
|
||||
case OUR_HTLC_SUCCESS_TX:
|
||||
return TX_CHANNEL_HTLC_SUCCESS;
|
||||
case OUR_HTLC_TIMEOUT_TO_US:
|
||||
case OUR_HTLC_TIMEOUT_TX:
|
||||
return TX_CHANNEL_HTLC_TIMEOUT;
|
||||
case OUR_DELAYED_RETURN_TO_WALLET:
|
||||
case SELF:
|
||||
return TX_CHANNEL_SWEEP;
|
||||
case OUR_PENALTY_TX:
|
||||
return TX_CHANNEL_PENALTY;
|
||||
case THEIR_UNILATERAL:
|
||||
case UNKNOWN_UNILATERAL:
|
||||
case THEIR_REVOKED_UNILATERAL:
|
||||
return TX_CHANNEL_UNILATERAL | TX_THEIRS;
|
||||
case THEIR_HTLC_TIMEOUT_TO_THEM:
|
||||
return TX_CHANNEL_HTLC_TIMEOUT | TX_THEIRS;
|
||||
case OUR_HTLC_FULFILL_TO_THEM:
|
||||
return TX_CHANNEL_HTLC_SUCCESS | TX_THEIRS;
|
||||
case IGNORING_TINY_PAYMENT:
|
||||
case UNKNOWN_TXTYPE:
|
||||
return TX_UNKNOWN;
|
||||
}
|
||||
abort();
|
||||
}
|
||||
|
||||
static void proposal_meets_depth(struct tracked_output *out)
|
||||
{
|
||||
/* If we simply wanted to ignore it after some depth */
|
||||
@ -471,9 +507,11 @@ static void proposal_meets_depth(struct tracked_output *out)
|
||||
tx_type_name(out->tx_type),
|
||||
output_type_name(out->output_type));
|
||||
|
||||
wire_sync_write(REQ_FD,
|
||||
take(towire_onchain_broadcast_tx(NULL,
|
||||
out->proposal->tx)));
|
||||
wire_sync_write(
|
||||
REQ_FD,
|
||||
take(towire_onchain_broadcast_tx(
|
||||
NULL, out->proposal->tx,
|
||||
onchain_txtype_to_wallet_txtype(out->proposal->tx_type))));
|
||||
|
||||
/* Don't wait for this if we're ignoring the tiny payment. */
|
||||
if (out->proposal->tx_type == IGNORING_TINY_PAYMENT) {
|
||||
|
@ -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)
|
||||
u8 *towire_onchain_broadcast_tx(const tal_t *ctx UNNEEDED, const struct bitcoin_tx *tx UNNEEDED, u16 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)
|
||||
|
Loading…
Reference in New Issue
Block a user