coins: update API surface for creating coin movements

Canonicalize the signature for the 'tag-type' of coin moves by unique
constructor/method calls.

Suggested-By: @rustyrussell
This commit is contained in:
lisa neigut
2020-04-14 22:08:06 -05:00
committed by Rusty Russell
parent aab9893661
commit de065580f6
10 changed files with 462 additions and 235 deletions

View File

@@ -680,15 +680,8 @@ static void record_output_spend(struct lightningd *ld,
vout);
*input_amt = utxo->amount;
mvt = new_chain_coin_mvt_sat(ctx, "wallet", txid,
utxo_txid, vout, NULL,
blockheight,
SPEND_TRACK, AMOUNT_SAT(0),
false, BTC);
if (!mvt)
fatal("unable to convert %s to msat",
type_to_string(tmpctx, struct amount_sat,
input_amt));
mvt = new_coin_spend_track(ctx, txid, utxo_txid, vout,
blockheight, BTC);
notify_chain_mvt(ld, mvt);
tal_free(ctx);
}
@@ -717,14 +710,8 @@ static void record_tx_outs_and_fees(struct lightningd *ld, const struct bitcoin_
asset = bitcoin_tx_output_get_amount(tx, i);
assert(amount_asset_is_main(&asset));
outval = amount_asset_to_sat(&asset);
mvt = new_chain_coin_mvt_sat(ctx, "wallet", txid,
txid, i, NULL,
blockheight, WITHDRAWAL,
outval, false, BTC);
if (!mvt)
fatal("unable to convert %s to msat",
type_to_string(tmpctx, struct amount_sat, &fee));
mvt = new_coin_withdrawal_sat(ctx, "wallet", txid, txid,
i, blockheight, outval, BTC);
notify_chain_mvt(ld, mvt);
}
@@ -735,15 +722,9 @@ static void record_tx_outs_and_fees(struct lightningd *ld, const struct bitcoin_
* fees logged here, to the 'wallet' account (for funding tx).
* You can do this in post by accounting for any 'chain_fees' logged for
* the funding txid when looking at a channel. */
mvt = new_chain_coin_mvt_sat(ctx, "wallet", txid,
NULL, 0, NULL, blockheight,
CHAIN_FEES, fee, false, BTC);
if (!mvt)
fatal("unable to convert %s to msat",
type_to_string(tmpctx, struct amount_sat, &fee));
notify_chain_mvt(ld, mvt);
notify_chain_mvt(ld,
new_coin_chain_fees_sat(ctx, "wallet", txid,
blockheight, fee, BTC));
tal_free(ctx);
}

View File

@@ -100,15 +100,11 @@ static void record_channel_open(struct channel *channel)
/* if we pushed sats, we should decrement that from the channel balance */
if (amount_msat_greater(channel->push, AMOUNT_MSAT(0))) {
mvt = new_chain_coin_mvt(ctx,
type_to_string(tmpctx,
struct channel_id,
&channel_id),
&channel->funding_txid,
NULL, 0, NULL,
blockheight,
PUSHED, channel->push,
false, BTC);
mvt = new_coin_pushed(ctx, type_to_string(tmpctx,
struct channel_id,
&channel_id),
&channel->funding_txid,
blockheight, channel->push, BTC);
notify_chain_mvt(channel->peer->ld, mvt);
}
} else {
@@ -118,15 +114,12 @@ static void record_channel_open(struct channel *channel)
channel_open_amt = channel->our_msat;
}
mvt = new_chain_coin_mvt(ctx,
type_to_string(tmpctx, struct channel_id,
&channel_id),
&channel->funding_txid,
&channel->funding_txid,
channel->funding_outnum,
NULL, blockheight,
DEPOSIT, channel_open_amt,
true, BTC);
mvt = new_coin_deposit(ctx,
type_to_string(tmpctx, struct channel_id,
&channel_id),
&channel->funding_txid,
channel->funding_outnum,
blockheight, channel_open_amt, BTC);
notify_chain_mvt(channel->peer->ld, mvt);
tal_free(ctx);
}

View File

@@ -341,9 +341,9 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg)
outpointfilter_add(channel->peer->ld->wallet->owned_outpoints, &u->txid, u->outnum);
wallet_add_utxo(channel->peer->ld->wallet, u, p2wpkh);
mvt = new_chain_coin_mvt_sat(msg, "wallet", &u->txid, &u->txid,
u->outnum, NULL, blockheight,
DEPOSIT, u->amount, true, BTC);
mvt = new_coin_deposit_sat(msg, "wallet", &u->txid,
u->outnum, blockheight,
u->amount, BTC);
notify_chain_mvt(channel->peer->ld, mvt);
}