* We store the bolt11 string in several places with the `lightning:` prefix, so * we update one by one by lowering and normalize the string in a canonical one. * * See also `to_canonical_invstr` in `common/bolt11.c` the definition of * canonical invoice. */
| 932 | * canonical invoice. |
| 933 | */ |
| 934 | void migrate_normalize_invstr(struct lightningd *ld, struct db *db) |
| 935 | { |
| 936 | struct db_stmt *stmt; |
| 937 | |
| 938 | stmt = db_prepare_v2(db, SQL("SELECT bolt11, id" |
| 939 | " FROM invoices" |
| 940 | " WHERE bolt11 IS NOT NULL;")); |
| 941 | db_query_prepared(stmt); |
| 942 | while (db_step(stmt)) { |
| 943 | u64 id; |
| 944 | const char *invstr; |
| 945 | struct db_stmt *update_stmt; |
| 946 | |
| 947 | id = db_col_u64(stmt, "id"); |
| 948 | invstr = db_col_strdup(tmpctx, stmt, "bolt11"); |
| 949 | invstr = to_canonical_invstr(tmpctx, invstr); |
| 950 | |
| 951 | update_stmt = db_prepare_v2(db, SQL("UPDATE invoices" |
| 952 | " SET bolt11 = ?" |
| 953 | " WHERE id = ?;")); |
| 954 | db_bind_text(update_stmt, invstr); |
| 955 | db_bind_u64(update_stmt, id); |
| 956 | db_exec_prepared_v2(update_stmt); |
| 957 | |
| 958 | tal_free(update_stmt); |
| 959 | } |
| 960 | tal_free(stmt); |
| 961 | |
| 962 | stmt = db_prepare_v2(db, SQL("SELECT bolt11, id" |
| 963 | " FROM payments" |
| 964 | " WHERE bolt11 IS NOT NULL;")); |
| 965 | db_query_prepared(stmt); |
| 966 | while (db_step(stmt)) { |
| 967 | u64 id; |
| 968 | const char *invstr; |
| 969 | struct db_stmt *update_stmt; |
| 970 | |
| 971 | id = db_col_u64(stmt, "id"); |
| 972 | invstr = db_col_strdup(tmpctx, stmt, "bolt11"); |
| 973 | invstr = to_canonical_invstr(tmpctx, invstr); |
| 974 | |
| 975 | update_stmt = db_prepare_v2(db, SQL("UPDATE payments" |
| 976 | " SET bolt11 = ?" |
| 977 | " WHERE id = ?;")); |
| 978 | db_bind_text(update_stmt, invstr); |
| 979 | db_bind_u64(update_stmt, id); |
| 980 | db_exec_prepared_v2(update_stmt); |
| 981 | |
| 982 | tal_free(update_stmt); |
| 983 | } |
| 984 | tal_free(stmt); |
| 985 | } |
| 986 | |
| 987 | /* We required local aliases to be set on established channels, |
| 988 | * but we forgot about already-existing ones in the db! */ |
nothing calls this directly
no test coverage detected