* wallet_stmt2output - Extract data from stmt and fill an UTXO */
| 191 | * wallet_stmt2output - Extract data from stmt and fill an UTXO |
| 192 | */ |
| 193 | static struct utxo *wallet_stmt2output(const tal_t *ctx, struct db_stmt *stmt) |
| 194 | { |
| 195 | struct utxo *utxo = tal(ctx, struct utxo); |
| 196 | u32 *blockheight, *spendheight; |
| 197 | db_col_txid(stmt, "prev_out_tx", &utxo->outpoint.txid); |
| 198 | utxo->outpoint.n = db_col_int(stmt, "prev_out_index"); |
| 199 | db_col_amount_sat(stmt, "value", &utxo->amount); |
| 200 | utxo->is_p2sh = db_col_int(stmt, "type") == p2sh_wpkh; |
| 201 | utxo->status = db_col_int(stmt, "status"); |
| 202 | utxo->keyindex = db_col_int(stmt, "keyindex"); |
| 203 | if (!db_col_is_null(stmt, "channel_id")) { |
| 204 | utxo->close_info = tal(utxo, struct unilateral_close_info); |
| 205 | utxo->close_info->channel_id = db_col_u64(stmt, "channel_id"); |
| 206 | db_col_node_id(stmt, "peer_id", &utxo->close_info->peer_id); |
| 207 | if (!db_col_is_null(stmt, "commitment_point")) { |
| 208 | utxo->close_info->commitment_point |
| 209 | = tal(utxo->close_info, struct pubkey); |
| 210 | db_col_pubkey(stmt, "commitment_point", |
| 211 | utxo->close_info->commitment_point); |
| 212 | } else |
| 213 | utxo->close_info->commitment_point = NULL; |
| 214 | utxo->close_info->option_anchor_outputs |
| 215 | = db_col_int(stmt, "option_anchor_outputs"); |
| 216 | utxo->close_info->csv = db_col_int(stmt, "csv_lock"); |
| 217 | } else { |
| 218 | utxo->close_info = NULL; |
| 219 | db_col_ignore(stmt, "peer_id"); |
| 220 | db_col_ignore(stmt, "commitment_point"); |
| 221 | db_col_ignore(stmt, "option_anchor_outputs"); |
| 222 | db_col_ignore(stmt, "csv_lock"); |
| 223 | } |
| 224 | |
| 225 | utxo->scriptPubkey = db_col_arr(utxo, stmt, "scriptpubkey", u8); |
| 226 | |
| 227 | utxo->blockheight = NULL; |
| 228 | utxo->spendheight = NULL; |
| 229 | |
| 230 | if (!db_col_is_null(stmt, "confirmation_height")) { |
| 231 | blockheight = tal(utxo, u32); |
| 232 | *blockheight = db_col_int(stmt, "confirmation_height"); |
| 233 | utxo->blockheight = blockheight; |
| 234 | } |
| 235 | |
| 236 | if (!db_col_is_null(stmt, "spend_height")) { |
| 237 | spendheight = tal(utxo, u32); |
| 238 | *spendheight = db_col_int(stmt, "spend_height"); |
| 239 | utxo->spendheight = spendheight; |
| 240 | } |
| 241 | |
| 242 | /* This column can be null if 0.9.1 db or below. */ |
| 243 | utxo->reserved_til = db_col_int_or_default(stmt, "reserved_til", 0); |
| 244 | |
| 245 | return utxo; |
| 246 | } |
| 247 | |
| 248 | bool wallet_update_output_status(struct wallet *w, |
| 249 | const struct bitcoin_outpoint *outpoint, |
no test coverage detected