Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idb plainmessage gasprices #1121

Merged
merged 6 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/extension/.env.testnet
Original file line number Diff line number Diff line change
@@ -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
16 changes: 12 additions & 4 deletions packages/storage/src/indexed-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, PlainMessage, toPlainMessage } from '@bufbuild/protobuf';

interface IndexedDbProps {
dbVersion: number; // Incremented during schema changes
Expand Down Expand Up @@ -286,6 +287,9 @@ 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({
Expand Down Expand Up @@ -388,12 +392,16 @@ export class IndexedDb implements IndexedDbInterface {
return SwapRecord.fromJson(json);
}

async getGasPrices(): Promise<GasPrices | undefined> {
return this.db.get('GAS_PRICES', 'gas_prices');
async getGasPrices(): Promise<PlainMessage<GasPrices> | undefined> {
return await this.db.get('GAS_PRICES', 'gas_prices');
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
}

async saveGasPrices(value: GasPrices): Promise<void> {
await this.u.update({ table: 'GAS_PRICES', value, key: 'gas_prices' });
async saveGasPrices(value: PartialMessage<GasPrices>): Promise<void> {
await this.u.update({
table: 'GAS_PRICES',
value: toPlainMessage(new GasPrices(value)),
key: 'gas_prices',
});
}

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/types/src/indexed-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
AuctionId,
DutchAuctionDescription,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1alpha1/auction_pb';
import { PlainMessage } from '@bufbuild/protobuf';

export interface IdbUpdate<DBTypes extends PenumbraDb, StoreName extends StoreNames<DBTypes>> {
table: StoreName;
Expand Down Expand Up @@ -84,7 +85,7 @@ export interface IndexedDbInterface {
getSwapByNullifier(nullifier: Nullifier): Promise<SwapRecord | undefined>;
saveSwap(note: SwapRecord): Promise<void>;
getSwapByCommitment(commitment: StateCommitment): Promise<SwapRecord | undefined>;
getGasPrices(): Promise<GasPrices | undefined>;
getGasPrices(): Promise<PlainMessage<GasPrices> | undefined>;
saveGasPrices(value: GasPrices): Promise<void>;
getNotesForVoting(
addressIndex: AddressIndex | undefined,
Expand Down Expand Up @@ -194,7 +195,7 @@ export interface PenumbraDb extends DBSchema {
};
GAS_PRICES: {
key: 'gas_prices';
value: GasPrices;
value: PlainMessage<GasPrices>;
turbocrime marked this conversation as resolved.
Show resolved Hide resolved
};
POSITIONS: {
key: string; // base64 PositionRecord['id']['inner'];
Expand Down
Loading