wallet-core: fixup for coin availability (visible coins)

This commit is contained in:
Florian Dold 2023-06-28 17:22:27 +02:00
parent 3f4526847b
commit 93ab00e601
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
2 changed files with 13 additions and 3 deletions

View File

@ -2152,10 +2152,8 @@ export interface CoinAvailabilityRecord {
* Number of fresh coins that are available * Number of fresh coins that are available
* and visible, i.e. the source transaction is in * and visible, i.e. the source transaction is in
* a final state. * a final state.
*
* (Optional for backwards compatibility, defaults to 0.)
*/ */
visibleCoinCount?: number; visibleCoinCount: number;
} }
export interface ContractTermsRecord { export interface ContractTermsRecord {
@ -2942,6 +2940,17 @@ export const walletDbFixups: FixupDescription[] = [
}); });
}, },
}, },
{
name: "CoinAvailabilityRecord_visibleCoinCount_add",
async fn(tx): Promise<void> {
await tx.coinAvailability.iter().forEachAsync(async (r) => {
if (r.visibleCoinCount == null) {
r.visibleCoinCount = r.freshCoinCount;
await tx.coinAvailability.put(r);
}
});
},
},
]; ];
const logger = new Logger("db.ts"); const logger = new Logger("db.ts");

View File

@ -147,6 +147,7 @@ export async function makeCoinAvailable(
denomPubHash: denom.denomPubHash, denomPubHash: denom.denomPubHash,
exchangeBaseUrl: denom.exchangeBaseUrl, exchangeBaseUrl: denom.exchangeBaseUrl,
freshCoinCount: 0, freshCoinCount: 0,
visibleCoinCount: 0,
}; };
} }
car.freshCoinCount++; car.freshCoinCount++;