wallet: add explicit API for onchaind to register UTXOs.

This is the only place outside the wallet code where we create
a 'struct utxo', so it makes sense for us to move that logic inside
the wallet.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2020-07-06 14:58:43 +09:30
committed by Christian Decker
parent 1708fb91e5
commit 4271fc8652
3 changed files with 101 additions and 18 deletions

View File

@@ -323,31 +323,33 @@ static void handle_irrevocably_resolved(struct channel *channel, const u8 *msg U
*/
static void onchain_add_utxo(struct channel *channel, const u8 *msg)
{
struct utxo *u = tal(msg, struct utxo);
struct chain_coin_mvt *mvt;
u32 blockheight;
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 = channel->dbid;
u->close_info->peer_id = channel->peer->id;
u->spendheight = NULL;
u->scriptPubkey = NULL;
struct bitcoin_txid txid;
u32 outnum;
struct amount_sat amount;
struct pubkey *commitment_point;
u8 *scriptPubkey;
if (!fromwire_onchain_add_utxo(
u, msg, &u->txid, &u->outnum, &u->close_info->commitment_point,
&u->amount, &blockheight, &u->scriptPubkey)) {
fatal("onchaind gave invalid add_utxo message: %s", tal_hex(msg, msg));
tmpctx, msg, &txid, &outnum, &commitment_point,
&amount, &blockheight, &scriptPubkey)) {
log_broken(channel->log,
"onchaind gave invalid add_utxo message: %s",
tal_hex(msg, msg));
return;
}
u->blockheight = blockheight>0?&blockheight:NULL;
outpointfilter_add(channel->peer->ld->wallet->owned_outpoints, &u->txid, u->outnum);
wallet_add_utxo(channel->peer->ld->wallet, u, p2wpkh);
assert(blockheight);
outpointfilter_add(channel->peer->ld->wallet->owned_outpoints,
&txid, outnum);
wallet_add_onchaind_utxo(channel->peer->ld->wallet,
&txid, outnum, scriptPubkey,
blockheight, amount, channel,
commitment_point);
mvt = new_coin_deposit_sat(msg, "wallet", &u->txid,
u->outnum, blockheight, u->amount);
mvt = new_coin_deposit_sat(msg, "wallet", &txid,
outnum, blockheight, amount);
notify_chain_mvt(channel->peer->ld, mvt);
}