| 126 | } |
| 127 | |
| 128 | static struct income_event *maybe_chain_income(const tal_t *ctx, |
| 129 | struct db *db, |
| 130 | struct account *acct, |
| 131 | struct chain_event *ev) |
| 132 | { |
| 133 | if (streq(ev->tag, "htlc_fulfill")) { |
| 134 | if (streq(ev->acct_name, EXTERNAL_ACCT)) |
| 135 | /* Swap the credit/debit as it went to external */ |
| 136 | return chain_to_income(ctx, ev, |
| 137 | ev->origin_acct, |
| 138 | ev->debit, |
| 139 | ev->credit); |
| 140 | /* Normal credit/debit as it originated from external */ |
| 141 | return chain_to_income(ctx, ev, |
| 142 | ev->acct_name, |
| 143 | ev->credit, ev->debit); |
| 144 | } |
| 145 | |
| 146 | /* expenses */ |
| 147 | if (streq(ev->tag, "anchor")) { |
| 148 | if (acct->we_opened) |
| 149 | /* for now, we count all anchors as expenses */ |
| 150 | return chain_to_income(ctx, ev, |
| 151 | ev->acct_name, |
| 152 | ev->debit, |
| 153 | ev->credit); |
| 154 | /* non-openers dont spend/gain anything on anchors */ |
| 155 | return NULL; |
| 156 | } |
| 157 | |
| 158 | /* income */ |
| 159 | if (streq(ev->tag, "deposit")) { |
| 160 | struct db_stmt *stmt; |
| 161 | |
| 162 | /* deposit to external is cost to us */ |
| 163 | if (streq(ev->acct_name, EXTERNAL_ACCT)) { |
| 164 | struct income_event *iev; |
| 165 | |
| 166 | /* External deposits w/o a blockheight |
| 167 | * aren't confirmed yet */ |
| 168 | if (ev->blockheight == 0) |
| 169 | return NULL; |
| 170 | |
| 171 | iev = chain_to_income(ctx, ev, |
| 172 | ev->origin_acct, |
| 173 | ev->debit, |
| 174 | ev->credit); |
| 175 | /* Also, really a withdrawal.. phh */ |
| 176 | iev->tag = tal_strdup(iev, mvt_tag_str(WITHDRAWAL)); |
| 177 | return iev; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | /* Did this deposit originate from within our |
| 182 | * wallet? */ |
| 183 | /*FIXME: there's an edge case where we put funds |
| 184 | * into a tx that included funds from a 3rd party |
| 185 | * coming to us... eg. a splice out from the peer |
no test coverage detected