Skip to content

Commit

Permalink
Account for the fullnode returning a DutchAuction, not a DutchAuction…
Browse files Browse the repository at this point in the history
…State
  • Loading branch information
jessepinho committed May 7, 2024
1 parent 0a927ac commit d86d87a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 4 additions & 4 deletions packages/query/src/queriers/auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PromiseClient } from '@connectrpc/connect';
import { createClient } from './utils';
import {
AuctionId,
DutchAuctionState,
DutchAuction,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1alpha1/auction_pb';

export class AuctionQuerier implements AuctionQuerierInterface {
Expand All @@ -16,13 +16,13 @@ export class AuctionQuerier implements AuctionQuerierInterface {

async auctionStateById(id: AuctionId): Promise<
// Add more auction types to this union type as they are created.
DutchAuctionState | undefined
DutchAuction | undefined
> {
const result = await this.client.auctionStateById({ id });

// As more auction types are created, handle them here.
if (result.auction?.typeUrl === DutchAuctionState.typeName) {
return DutchAuctionState.fromBinary(result.auction.value);
if (result.auction?.typeUrl === DutchAuction.typeName) {
return DutchAuction.fromBinary(result.auction.value);
}

return undefined;
Expand Down
8 changes: 6 additions & 2 deletions packages/services/src/view-service/auctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Impl } from '.';
import {
AuctionId,
DutchAuction,
DutchAuctionState,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1alpha1/auction_pb';
import { balances } from './balances';
import { getDisplayDenomFromView } from '@penumbra-zone/getters/value-view';
Expand Down Expand Up @@ -61,13 +62,16 @@ export const auctions: Impl['auctions'] = async function* (req, ctx) {
noteRecord = await indexedDb.getSpendableNoteByCommitment(value.noteCommitment);
}

let state: DutchAuctionState | undefined;
if (queryLatestState) state = (await querier.auction.auctionStateById(id))?.state;

let auction: Any | undefined;
if (!!value.auction || queryLatestState) {
if (!!value.auction || state) {
auction = new Any({
typeUrl: DutchAuction.typeName,
value: new DutchAuction({
description: value.auction,
state: queryLatestState ? await querier.auction.auctionStateById(id) : undefined,
state,
}).toBinary(),
});
}
Expand Down
4 changes: 2 additions & 2 deletions packages/types/src/querier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { MerkleRoot } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/crypto/tct/v1/tct_pb';
import {
AuctionId,
DutchAuctionState,
DutchAuction,
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/auction/v1alpha1/auction_pb';

export interface RootQuerierInterface {
Expand Down Expand Up @@ -72,5 +72,5 @@ export interface CnidariumQuerierInterface {
}

export interface AuctionQuerierInterface {
auctionStateById(id: AuctionId): Promise<DutchAuctionState | undefined>;
auctionStateById(id: AuctionId): Promise<DutchAuction | undefined>;
}

0 comments on commit d86d87a

Please sign in to comment.