coins: use the chain's BIP173 name instead of a 'unit of account'

Updates the unit of account to be the chain_id, which is the BIP173 name
of the chain that the coins moved on.

Suggested-By: @rustyrussell
This commit is contained in:
lisa neigut
2020-04-14 22:40:28 -05:00
committed by Rusty Russell
parent de065580f6
commit 8acbbca05d
15 changed files with 93 additions and 166 deletions

View File

@@ -680,8 +680,7 @@ static void record_output_spend(struct lightningd *ld,
vout);
*input_amt = utxo->amount;
mvt = new_coin_spend_track(ctx, txid, utxo_txid, vout,
blockheight, BTC);
mvt = new_coin_spend_track(ctx, txid, utxo_txid, vout, blockheight);
notify_chain_mvt(ld, mvt);
tal_free(ctx);
}
@@ -711,7 +710,7 @@ static void record_tx_outs_and_fees(struct lightningd *ld, const struct bitcoin_
assert(amount_asset_is_main(&asset));
outval = amount_asset_to_sat(&asset);
mvt = new_coin_withdrawal_sat(ctx, "wallet", txid, txid,
i, blockheight, outval, BTC);
i, blockheight, outval);
notify_chain_mvt(ld, mvt);
}
@@ -724,7 +723,7 @@ static void record_tx_outs_and_fees(struct lightningd *ld, const struct bitcoin_
* the funding txid when looking at a channel. */
notify_chain_mvt(ld,
new_coin_chain_fees_sat(ctx, "wallet", txid,
blockheight, fee, BTC));
blockheight, fee));
tal_free(ctx);
}

View File

@@ -104,7 +104,7 @@ static void record_channel_open(struct channel *channel)
struct channel_id,
&channel_id),
&channel->funding_txid,
blockheight, channel->push, BTC);
blockheight, channel->push);
notify_chain_mvt(channel->peer->ld, mvt);
}
} else {
@@ -119,7 +119,7 @@ static void record_channel_open(struct channel *channel)
&channel_id),
&channel->funding_txid,
channel->funding_outnum,
blockheight, channel_open_amt, BTC);
blockheight, channel_open_amt);
notify_chain_mvt(channel->peer->ld, mvt);
tal_free(ctx);
}

View File

@@ -18,8 +18,8 @@ void notify_channel_mvt(struct lightningd *ld, const struct channel_coin_mvt *mv
timestamp = time_now().ts.tv_sec;
count = update_count(ld);
cm = finalize_channel_mvt(mvt, mvt, timestamp,
&ld->id, count);
cm = finalize_channel_mvt(mvt, mvt, chainparams->bip173_name,
timestamp, &ld->id, count);
notify_coin_mvt(ld, cm);
}
@@ -31,8 +31,8 @@ void notify_chain_mvt(struct lightningd *ld, const struct chain_coin_mvt *mvt)
timestamp = time_now().ts.tv_sec;
count = update_count(ld);
cm = finalize_chain_mvt(mvt, mvt, timestamp,
&ld->id, count);
cm = finalize_chain_mvt(mvt, mvt, chainparams->bip173_name,
timestamp, &ld->id, count);
notify_coin_mvt(ld, cm);
}
@@ -44,7 +44,7 @@ struct channel_coin_mvt *new_channel_mvt_invoice_hin(const tal_t *ctx,
channel->funding_outnum,
hin->payment_hash, NULL,
hin->msat, INVOICE,
true, BTC);
true);
}
struct channel_coin_mvt *new_channel_mvt_routed_hin(const tal_t *ctx,
@@ -55,7 +55,7 @@ struct channel_coin_mvt *new_channel_mvt_routed_hin(const tal_t *ctx,
channel->funding_outnum,
hin->payment_hash, NULL,
hin->msat, ROUTED,
true, BTC);
true);
}
struct channel_coin_mvt *new_channel_mvt_invoice_hout(const tal_t *ctx,
@@ -66,7 +66,7 @@ struct channel_coin_mvt *new_channel_mvt_invoice_hout(const tal_t *ctx,
channel->funding_outnum,
hout->payment_hash, &hout->partid,
hout->msat, INVOICE,
false, BTC);
false);
}
struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx,
@@ -77,7 +77,7 @@ struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx,
channel->funding_outnum,
hout->payment_hash, NULL,
hout->msat, ROUTED,
false, BTC);
false);
}
void coin_mvts_init_count(struct lightningd *ld)

View File

@@ -402,7 +402,7 @@ static void coin_movement_notification_serialize(struct json_stream *stream,
json_add_null(stream, "blockheight");
}
json_add_u32(stream, "timestamp", mvt->timestamp);
json_add_string(stream, "unit_of_account", mvt_unit_str(mvt->unit));
json_add_string(stream, "coin_type", mvt->bip173_name);
json_object_end(stream);
}

View File

@@ -342,8 +342,7 @@ static void onchain_add_utxo(struct channel *channel, const u8 *msg)
wallet_add_utxo(channel->peer->ld->wallet, u, p2wpkh);
mvt = new_coin_deposit_sat(msg, "wallet", &u->txid,
u->outnum, blockheight,
u->amount, BTC);
u->outnum, blockheight, u->amount);
notify_chain_mvt(channel->peer->ld, mvt);
}