| 7158 | } |
| 7159 | |
| 7160 | struct chain_coin_mvt *wallet_chain_move_extract(const tal_t *ctx, |
| 7161 | struct db_stmt *stmt, |
| 7162 | struct lightningd *ld, |
| 7163 | u64 *id) |
| 7164 | { |
| 7165 | struct chain_coin_mvt *chain_mvt = tal(ctx, struct chain_coin_mvt); |
| 7166 | |
| 7167 | *id = db_col_u64(stmt, "chain_moves.id"); |
| 7168 | db_cols_account(stmt, ld, |
| 7169 | "account_channel_id", "ma1.name", |
| 7170 | &chain_mvt->account); |
| 7171 | chain_mvt->tags = db_col_mvt_tags(stmt, "tag_bitmap"); |
| 7172 | db_col_credit_or_debit(stmt, "credit_or_debit", |
| 7173 | &chain_mvt->credit, |
| 7174 | &chain_mvt->debit); |
| 7175 | chain_mvt->timestamp = db_col_u64(stmt, "timestamp"); |
| 7176 | db_col_outpoint(stmt, "utxo", &chain_mvt->outpoint); |
| 7177 | |
| 7178 | if (db_col_is_null(stmt, "spending_txid")) |
| 7179 | chain_mvt->spending_txid = NULL; |
| 7180 | else { |
| 7181 | /* Need non-const for db_col_txid */ |
| 7182 | struct bitcoin_txid *txid; |
| 7183 | chain_mvt->spending_txid = txid = tal(chain_mvt, struct bitcoin_txid); |
| 7184 | db_col_txid(stmt, "spending_txid", txid); |
| 7185 | } |
| 7186 | if (db_col_is_null(stmt, "peer_id")) |
| 7187 | chain_mvt->peer_id = NULL; |
| 7188 | else { |
| 7189 | /* Need non-const temporary */ |
| 7190 | struct node_id *peer_id; |
| 7191 | chain_mvt->peer_id = peer_id = tal(chain_mvt, struct node_id); |
| 7192 | db_col_node_id(stmt, "peer_id", peer_id); |
| 7193 | } |
| 7194 | if (db_col_is_null(stmt, "payment_hash")) |
| 7195 | chain_mvt->payment_hash = NULL; |
| 7196 | else { |
| 7197 | /* Need non-const temporary */ |
| 7198 | struct sha256 *ph; |
| 7199 | chain_mvt->payment_hash = ph = tal(chain_mvt, struct sha256); |
| 7200 | db_col_sha256(stmt, "payment_hash", ph); |
| 7201 | } |
| 7202 | chain_mvt->blockheight = db_col_int(stmt, "block_height"); |
| 7203 | if (db_col_is_null(stmt, "originating_channel_id") && db_col_is_null(stmt, "ma2.name")) { |
| 7204 | chain_mvt->originating_acct = NULL; |
| 7205 | } else { |
| 7206 | /* Need non-const temporary */ |
| 7207 | struct mvt_account_id *acct; |
| 7208 | chain_mvt->originating_acct = acct = tal(chain_mvt, struct mvt_account_id); |
| 7209 | db_cols_account(stmt, ld, |
| 7210 | "originating_channel_id", "ma2.name", |
| 7211 | acct); |
| 7212 | } |
| 7213 | chain_mvt->output_val = db_col_amount_sat(stmt, "output_sat"); |
| 7214 | if (db_col_is_null(stmt, "output_count")) |
| 7215 | chain_mvt->output_count = 0; |
| 7216 | else |
| 7217 | chain_mvt->output_count = db_col_int(stmt, "output_count"); |
no test coverage detected