| 1030 | } |
| 1031 | |
| 1032 | void channel_record_open(struct channel *channel, u32 blockheight, bool record_push) |
| 1033 | { |
| 1034 | struct chain_coin_mvt *mvt; |
| 1035 | struct amount_msat start_balance; |
| 1036 | bool is_pushed = !amount_msat_is_zero(channel->push); |
| 1037 | bool is_leased = channel->lease_expiry > 0; |
| 1038 | |
| 1039 | /* If funds were pushed, add/sub them from the starting balance */ |
| 1040 | if (channel->opener == LOCAL) { |
| 1041 | if (!amount_msat_add(&start_balance, |
| 1042 | channel->our_msat, channel->push)) |
| 1043 | fatal("Unable to add push_msat (%s) + our_msat (%s)", |
| 1044 | fmt_amount_msat(tmpctx, channel->push), |
| 1045 | fmt_amount_msat(tmpctx, channel->our_msat)); |
| 1046 | } else { |
| 1047 | if (!amount_msat_sub(&start_balance, |
| 1048 | channel->our_msat, channel->push)) |
| 1049 | fatal("Unable to sub our_msat (%s) - push (%s)", |
| 1050 | fmt_amount_msat(tmpctx, channel->our_msat), |
| 1051 | fmt_amount_msat(tmpctx, channel->push)); |
| 1052 | } |
| 1053 | |
| 1054 | /* If it's not in a block yet, send a proposal */ |
| 1055 | if (blockheight > 0) |
| 1056 | mvt = new_coin_channel_open(tmpctx, |
| 1057 | channel, |
| 1058 | &channel->funding, |
| 1059 | &channel->peer->id, |
| 1060 | blockheight, |
| 1061 | start_balance, |
| 1062 | channel->funding_sats, |
| 1063 | channel->opener == LOCAL, |
| 1064 | is_leased); |
| 1065 | else |
| 1066 | mvt = new_coin_channel_open_proposed(tmpctx, |
| 1067 | channel, |
| 1068 | &channel->funding, |
| 1069 | &channel->peer->id, |
| 1070 | start_balance, |
| 1071 | channel->funding_sats, |
| 1072 | channel->opener == LOCAL, |
| 1073 | is_leased); |
| 1074 | |
| 1075 | wallet_save_chain_mvt(channel->peer->ld, mvt); |
| 1076 | |
| 1077 | /* If we pushed sats, *now* record them */ |
| 1078 | if (is_pushed && record_push) |
| 1079 | wallet_save_channel_mvt(channel->peer->ld, |
| 1080 | new_coin_channel_push(tmpctx, channel, |
| 1081 | channel->opener == REMOTE ? COIN_CREDIT : COIN_DEBIT, |
| 1082 | channel->push, |
| 1083 | is_leased |
| 1084 | ? mk_mvt_tags(MVT_LEASE_FEE) |
| 1085 | : mk_mvt_tags(MVT_PUSHED))); |
| 1086 | } |
| 1087 | |
| 1088 | void lockin_has_completed(struct channel *channel, bool record_push) |
| 1089 | { |
no test coverage detected