| 3938 | } |
| 3939 | |
| 3940 | struct outpoint *wallet_outpoint_for_scid(struct wallet *w, tal_t *ctx, |
| 3941 | const struct short_channel_id *scid) |
| 3942 | { |
| 3943 | struct db_stmt *stmt; |
| 3944 | struct outpoint *op; |
| 3945 | stmt = db_prepare_v2(w->db, SQL("SELECT" |
| 3946 | " txid," |
| 3947 | " spendheight," |
| 3948 | " scriptpubkey," |
| 3949 | " satoshis " |
| 3950 | "FROM utxoset " |
| 3951 | "WHERE blockheight = ?" |
| 3952 | " AND txindex = ?" |
| 3953 | " AND outnum = ?" |
| 3954 | " AND spendheight IS NULL")); |
| 3955 | db_bind_int(stmt, 0, short_channel_id_blocknum(scid)); |
| 3956 | db_bind_int(stmt, 1, short_channel_id_txnum(scid)); |
| 3957 | db_bind_int(stmt, 2, short_channel_id_outnum(scid)); |
| 3958 | db_query_prepared(stmt); |
| 3959 | |
| 3960 | if (!db_step(stmt)) { |
| 3961 | tal_free(stmt); |
| 3962 | return NULL; |
| 3963 | } |
| 3964 | |
| 3965 | op = tal(ctx, struct outpoint); |
| 3966 | op->blockheight = short_channel_id_blocknum(scid); |
| 3967 | op->txindex = short_channel_id_txnum(scid); |
| 3968 | op->outpoint.n = short_channel_id_outnum(scid); |
| 3969 | db_col_txid(stmt, "txid", &op->outpoint.txid); |
| 3970 | if (db_col_is_null(stmt, "spendheight")) |
| 3971 | op->spendheight = 0; |
| 3972 | else |
| 3973 | op->spendheight = db_col_int(stmt, "spendheight"); |
| 3974 | op->scriptpubkey = db_col_arr(op, stmt, "scriptpubkey", u8); |
| 3975 | db_col_amount_sat(stmt, "satoshis", &op->sat); |
| 3976 | tal_free(stmt); |
| 3977 | |
| 3978 | return op; |
| 3979 | } |
| 3980 | |
| 3981 | /* Turns "SELECT blockheight, txindex, outnum" into scids */ |
| 3982 | static const struct short_channel_id *db_scids(const tal_t *ctx, |
no test coverage detected