diff --git a/common/coin_mvt.c b/common/coin_mvt.c index f2d897b27..fbb32624d 100644 --- a/common/coin_mvt.c +++ b/common/coin_mvt.c @@ -61,7 +61,8 @@ static struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx, const struct sha256 *payment_hash TAKES, u32 blockheight, enum mvt_tag tag, struct amount_msat amount, - bool is_credit) + bool is_credit, + struct amount_sat output_val) { struct chain_coin_mvt *mvt = tal(ctx, struct chain_coin_mvt); @@ -90,6 +91,7 @@ static struct chain_coin_mvt *new_chain_coin_mvt(const tal_t *ctx, mvt->debit = amount; mvt->credit = AMOUNT_MSAT(0); } + mvt->output_val = output_val; return mvt; } @@ -250,6 +252,10 @@ struct coin_mvt *finalize_chain_mvt(const tal_t *ctx, mvt->tag = chain_mvt->tag; mvt->credit = chain_mvt->credit; mvt->debit = chain_mvt->debit; + + mvt->output_val = tal(mvt, struct amount_sat); + *mvt->output_val = chain_mvt->output_val; + mvt->timestamp = timestamp; mvt->blockheight = chain_mvt->blockheight; mvt->version = COIN_MVT_VERSION; @@ -278,6 +284,7 @@ struct coin_mvt *finalize_channel_mvt(const tal_t *ctx, mvt->tag = chan_mvt->tag; mvt->credit = chan_mvt->credit; mvt->debit = chan_mvt->debit; + mvt->output_val = NULL; mvt->timestamp = timestamp; /* channel movements don't have a blockheight */ mvt->blockheight = 0; @@ -345,4 +352,5 @@ void fromwire_chain_coin_mvt(const u8 **cursor, size_t *max, struct chain_coin_m mvt->tag = fromwire_u8(cursor, max); mvt->credit = fromwire_amount_msat(cursor, max); mvt->debit = fromwire_amount_msat(cursor, max); + mvt->output_val = fromwire_amount_sat(cursor, max); } diff --git a/common/coin_mvt.h b/common/coin_mvt.h index 7049259d7..77ba24e90 100644 --- a/common/coin_mvt.h +++ b/common/coin_mvt.h @@ -66,6 +66,9 @@ struct chain_coin_mvt { /* only one or the other */ struct amount_msat credit; struct amount_msat debit; + + /* total value of output (useful for tracking external outs) */ + struct amount_sat output_val; }; /* differs depending on type!? */ @@ -94,6 +97,10 @@ struct coin_mvt { struct amount_msat credit; struct amount_msat debit; + /* Value of the output. May be different than + * our credit/debit amount, eg channel opens */ + struct amount_sat *output_val; + u32 timestamp; u32 blockheight; diff --git a/lightningd/notification.c b/lightningd/notification.c index 82612e6a2..de7d1e64e 100644 --- a/lightningd/notification.c +++ b/lightningd/notification.c @@ -471,6 +471,10 @@ static void coin_movement_notification_serialize(struct json_stream *stream, json_mvt_id(stream, mvt->type, &mvt->id); json_add_amount_msat_only(stream, "credit", mvt->credit); json_add_amount_msat_only(stream, "debit", mvt->debit); + /* Only chain movements */ + if (mvt->output_val) + json_add_amount_sat_only(stream, "output_value", + *mvt->output_val); json_add_string(stream, "tag", mvt_tag_str(mvt->tag)); /* Only chain movements have blockheights. A blockheight