@@ -84,6 +84,8 @@ static void migrate_initialize_forwards_wait_indexes(struct lightningd *ld,
8484 struct db * db );
8585static void migrate_initialize_alias_local (struct lightningd * ld ,
8686 struct db * db );
87+ static void insert_addrtype_to_addresses (struct lightningd * ld ,
88+ struct db * db );
8789
8890/* Do not reorder or remove elements from this array, it is used to
8991 * migrate existing databases from a previous state, based on the
@@ -1024,6 +1026,7 @@ static struct migration dbmigrations[] = {
10241026 {SQL ("CREATE TABLE addresses ("
10251027 " keyidx BIGINT,"
10261028 " addrtype INTEGER)" ), NULL },
1029+ {NULL , insert_addrtype_to_addresses },
10271030};
10281031
10291032/**
@@ -2000,3 +2003,22 @@ static void migrate_initialize_alias_local(struct lightningd *ld,
20002003 tal_free (stmt );
20012004 }
20022005}
2006+
2007+ /* Insert address type as `ADDR_ALL` for issued addresses */
2008+ static void insert_addrtype_to_addresses (struct lightningd * ld ,
2009+ struct db * db )
2010+ {
2011+ struct db_stmt * stmt ;
2012+ u64 bip32_max_index = db_get_intvar (db , "bip32_max_index" , 0 );
2013+ for (u64 newidx = 1 ; newidx <= bip32_max_index ; newidx ++ ) {
2014+ stmt = db_prepare_v2 (db ,
2015+ SQL ("INSERT INTO addresses ("
2016+ " keyidx"
2017+ ", addrtype"
2018+ ") VALUES (?, ?);" ));
2019+ db_bind_u64 (stmt , newidx );
2020+ db_bind_int (stmt , wallet_addrtype_in_db (ADDR_ALL ));
2021+ db_exec_prepared_v2 (stmt );
2022+ tal_free (stmt );
2023+ }
2024+ }
0 commit comments