From 010bd1f18fe70249d0e439a771ba12bd832414d8 Mon Sep 17 00:00:00 2001 From: the letter L <134443988+turbocrime@users.noreply.github.com> Date: Thu, 16 May 2024 16:29:32 -0700 Subject: [PATCH] idb plainmessage gasprices (#1121) * idb plainmessage gasprices * interface * indexdb version bump * add comments * modified types to use jsonified --------- Co-authored-by: turbocrime Co-authored-by: Tal Derei Co-authored-by: Tal Derei <70081547+TalDerei@users.noreply.github.com> --- apps/extension/.env.testnet | 2 +- packages/storage/src/indexed-db/index.ts | 30 +++++++++++++++--------- packages/types/src/indexed-db.ts | 5 ++-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/apps/extension/.env.testnet b/apps/extension/.env.testnet index eb074aae2e..78aac7260f 100644 --- a/apps/extension/.env.testnet +++ b/apps/extension/.env.testnet @@ -1,4 +1,4 @@ CHAIN_ID=penumbra-testnet-deimos-8 -IDB_VERSION=39 +IDB_VERSION=40 MINIFRONT_URL=https://app.testnet.penumbra.zone PRAX=lkpmkhpnhknhmibgnmmhdhgdilepfghe diff --git a/packages/storage/src/indexed-db/index.ts b/packages/storage/src/indexed-db/index.ts index c7cf797361..11fd55ed83 100644 --- a/packages/storage/src/indexed-db/index.ts +++ b/packages/storage/src/indexed-db/index.ts @@ -63,6 +63,7 @@ import { DutchAuctionDescription, } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1alpha1/auction_pb'; import { ChainRegistryClient } from '@penumbra-labs/registry'; +import { PartialMessage } from '@bufbuild/protobuf'; interface IndexedDbProps { dbVersion: number; // Incremented during schema changes @@ -286,15 +287,16 @@ export class IndexedDb implements IndexedDbInterface { const savedGasPrices = await this.getGasPrices(); // These are arbitrarily set, but can take on any value. // The gas prices set here will determine the fees to use Penumbra. + // + // Note: this is a temporary measure to enable gas prices in the web, but once + // https://github.com/penumbra-zone/penumbra/issues/4306 is merged, we can remove this. if (!savedGasPrices) { - await this.saveGasPrices( - new GasPrices({ - verificationPrice: 1n, - executionPrice: 1n, - blockSpacePrice: 1n, - compactBlockSpacePrice: 1n, - }), - ); + await this.saveGasPrices({ + verificationPrice: 1n, + executionPrice: 1n, + blockSpacePrice: 1n, + compactBlockSpacePrice: 1n, + }); } } @@ -389,11 +391,17 @@ export class IndexedDb implements IndexedDbInterface { } async getGasPrices(): Promise { - return this.db.get('GAS_PRICES', 'gas_prices'); + const jsonGasPrices = await this.db.get('GAS_PRICES', 'gas_prices'); + if (!jsonGasPrices) return undefined; + return GasPrices.fromJson(jsonGasPrices); } - async saveGasPrices(value: GasPrices): Promise { - await this.u.update({ table: 'GAS_PRICES', value, key: 'gas_prices' }); + async saveGasPrices(value: PartialMessage): Promise { + await this.u.update({ + table: 'GAS_PRICES', + value: new GasPrices(value).toJson() as Jsonified, + key: 'gas_prices', + }); } /** diff --git a/packages/types/src/indexed-db.ts b/packages/types/src/indexed-db.ts index 9eb9f55686..8e7189b3e9 100644 --- a/packages/types/src/indexed-db.ts +++ b/packages/types/src/indexed-db.ts @@ -48,6 +48,7 @@ import { AuctionId, DutchAuctionDescription, } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1alpha1/auction_pb'; +import { PartialMessage } from '@bufbuild/protobuf'; export interface IdbUpdate> { table: StoreName; @@ -85,7 +86,7 @@ export interface IndexedDbInterface { saveSwap(note: SwapRecord): Promise; getSwapByCommitment(commitment: StateCommitment): Promise; getGasPrices(): Promise; - saveGasPrices(value: GasPrices): Promise; + saveGasPrices(value: PartialMessage): Promise; getNotesForVoting( addressIndex: AddressIndex | undefined, votableAtHeight: bigint, @@ -194,7 +195,7 @@ export interface PenumbraDb extends DBSchema { }; GAS_PRICES: { key: 'gas_prices'; - value: GasPrices; + value: Jsonified; }; POSITIONS: { key: string; // base64 PositionRecord['id']['inner'];