From 37c2873c887596c7cd1331585e47b5cf3213632b Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 20 Dec 2017 23:05:32 +0100 Subject: [PATCH] wallet: Store outputs from onchaind in the DB Signed-off-by: Christian Decker --- lightningd/peer_control.c | 18 +++++++++++++++++- wallet/wallet.h | 3 ++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lightningd/peer_control.c b/lightningd/peer_control.c index ab45936bc..085afa7c4 100644 --- a/lightningd/peer_control.c +++ b/lightningd/peer_control.c @@ -1281,7 +1281,23 @@ static void handle_irrevocably_resolved(struct peer *peer, const u8 *msg) */ static void onchain_add_utxo(struct peer *peer, const u8 *msg) { - /* FIXME(cdecker) Implement */ + struct utxo *u = tal(msg, struct utxo); + u->close_info = tal(u, struct unilateral_close_info); + + u->is_p2sh = true; + u->keyindex = 0; + u->status = output_state_available; + u->close_info->channel_id = peer->channel->id; + u->close_info->peer_id = peer->id; + + if (!fromwire_onchain_add_utxo(msg, NULL, &u->txid, &u->outnum, + &u->close_info->commitment_point, + &u->amount)) { + fatal("onchaind gave invalid add_utxo message: %s", tal_hex(msg, msg)); + } + + + wallet_add_utxo(peer->ld->wallet, u, p2wpkh); } static unsigned int onchain_msg(struct subd *sd, const u8 *msg, const int *fds) diff --git a/wallet/wallet.h b/wallet/wallet.h index 0fc382560..dfd74bb7f 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -44,7 +44,8 @@ enum wallet_output_type { to_local = 1, htlc_offer = 3, htlc_recv = 4, - our_change = 5 + our_change = 5, + p2wpkh = 6 }; /* A database backed shachain struct. The datastructure is