diff --git a/.changeset/chilled-wombats-approve.md b/.changeset/chilled-wombats-approve.md new file mode 100644 index 0000000000..5a49788575 --- /dev/null +++ b/.changeset/chilled-wombats-approve.md @@ -0,0 +1,5 @@ +--- +'@penumbra-zone/services': patch +--- + +use `Any.pack` to create `Any` messages diff --git a/apps/minifront/src/components/staking/account/delegation-value-view/index.test.tsx b/apps/minifront/src/components/staking/account/delegation-value-view/index.test.tsx index 6e0e153319..81050d3131 100644 --- a/apps/minifront/src/components/staking/account/delegation-value-view/index.test.tsx +++ b/apps/minifront/src/components/staking/account/delegation-value-view/index.test.tsx @@ -7,6 +7,7 @@ import { } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb.js'; import { ValidatorInfo } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb.js'; import { bech32mIdentityKey } from '@penumbra-zone/bech32m/penumbravalid'; +import { Any } from '@bufbuild/protobuf'; const u8 = (length: number) => Uint8Array.from({ length }, () => Math.floor(Math.random() * 256)); @@ -90,10 +91,7 @@ const valueView = new ValueView({ }, ], - extendedMetadata: { - typeUrl: ValidatorInfo.typeName, - value: validatorInfo.toBinary(), - }, + extendedMetadata: Any.pack(validatorInfo), }, }, }); diff --git a/apps/minifront/src/state/staking/index.test.ts b/apps/minifront/src/state/staking/index.test.ts index d9fdb42325..eb83c4e127 100644 --- a/apps/minifront/src/state/staking/index.test.ts +++ b/apps/minifront/src/state/staking/index.test.ts @@ -14,6 +14,7 @@ import { } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/keys/v1/keys_pb.js'; import { THROTTLE_MS } from '.'; import { DelegationsByAddressIndexResponse } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/view/v1/view_pb.js'; +import { Any } from '@bufbuild/protobuf'; const u8 = (length: number) => Uint8Array.from({ length }, () => Math.floor(Math.random() * 256)); const validator1IdentityKey = new IdentityKey({ ik: u8(32) }); @@ -83,10 +84,7 @@ vi.mock('../../fetchers/balances', () => ({ metadata: { display: `delegation_${validator1Bech32IdentityKey}`, }, - extendedMetadata: { - typeUrl: ValidatorInfo.typeName, - value: validatorInfo1.toBinary(), - }, + extendedMetadata: Any.pack(validatorInfo1), }, }, }), @@ -111,10 +109,7 @@ vi.mock('../../fetchers/balances', () => ({ metadata: { display: `delegation_${validator2Bech32IdentityKey}`, }, - extendedMetadata: { - typeUrl: ValidatorInfo.typeName, - value: validatorInfo2.toBinary(), - }, + extendedMetadata: Any.pack(validatorInfo2), }, }, }), @@ -168,10 +163,7 @@ const mockViewClient = vi.hoisted(() => ({ case: 'knownAssetId', value: { amount: { hi: 0n, lo: 1n }, - extendedMetadata: { - typeUrl: ValidatorInfo.typeName, - value: validatorInfo1.toBinary(), - }, + extendedMetadata: Any.pack(validatorInfo1), }, }, }, @@ -184,10 +176,7 @@ const mockViewClient = vi.hoisted(() => ({ case: 'knownAssetId', value: { amount: { hi: 0n, lo: 2n }, - extendedMetadata: { - typeUrl: ValidatorInfo.typeName, - value: validatorInfo2.toBinary(), - }, + extendedMetadata: Any.pack(validatorInfo2), }, }, }, @@ -200,10 +189,7 @@ const mockViewClient = vi.hoisted(() => ({ case: 'knownAssetId', value: { amount: { hi: 0n, lo: 0n }, - extendedMetadata: { - typeUrl: ValidatorInfo.typeName, - value: validatorInfo3.toBinary(), - }, + extendedMetadata: Any.pack(validatorInfo3), }, }, }, @@ -216,10 +202,7 @@ const mockViewClient = vi.hoisted(() => ({ case: 'knownAssetId', value: { amount: { hi: 0n, lo: 0n }, - extendedMetadata: { - typeUrl: ValidatorInfo.typeName, - value: validatorInfo4.toBinary(), - }, + extendedMetadata: Any.pack(validatorInfo4), }, }, }, diff --git a/packages/services/src/view-service/auctions.test.ts b/packages/services/src/view-service/auctions.test.ts index d7153081e9..62aa1d6282 100644 --- a/packages/services/src/view-service/auctions.test.ts +++ b/packages/services/src/view-service/auctions.test.ts @@ -20,6 +20,7 @@ import { IndexedDbMock, MockQuerier, MockServices } from '../test-utils.js'; import { StateCommitment } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/crypto/tct/v1/tct_pb.js'; import { Value } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/asset/v1/asset_pb.js'; import { Amount } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/num/v1/num_pb.js'; +import { Any } from '@bufbuild/protobuf'; const AUCTION_ID_1 = new AuctionId({ inner: new Uint8Array(Array(32).fill(1)) }); const BECH32M_AUCTION_ID_1 = bech32mAuctionId(AUCTION_ID_1); @@ -165,10 +166,7 @@ describe('Auctions request handler', () => { expect(results[0]).toEqual( new AuctionsResponse({ id: AUCTION_ID_1, - auction: { - typeUrl: DutchAuction.typeName, - value: new DutchAuction({ description: MOCK_AUCTION_1, state: { seq: 0n } }).toBinary(), - }, + auction: Any.pack(new DutchAuction({ description: MOCK_AUCTION_1, state: { seq: 0n } })), noteRecord: MOCK_SPENDABLE_NOTE_RECORD, }), ); diff --git a/packages/services/src/view-service/auctions.ts b/packages/services/src/view-service/auctions.ts index 3c3263ae32..002e5f36f9 100644 --- a/packages/services/src/view-service/auctions.ts +++ b/packages/services/src/view-service/auctions.ts @@ -79,17 +79,16 @@ export const auctions: Impl['auctions'] = async function* (req, ctx) { let auction: Any | undefined; if (!!value.auction || state) { const outstandingReserves = await indexedDb.getAuctionOutstandingReserves(id); - auction = new Any({ - typeUrl: DutchAuction.typeName, - value: new DutchAuction({ + auction = Any.pack( + new DutchAuction({ state: state ?? { seq: value.seqNum, inputReserves: outstandingReserves?.input.amount, outputReserves: outstandingReserves?.output.amount, }, description: value.auction, - }).toBinary(), - }); + }), + ); } yield new AuctionsResponse({ diff --git a/packages/services/src/view-service/delegations-by-address-index.ts b/packages/services/src/view-service/delegations-by-address-index.ts index 61d1f924e3..09d9da1581 100644 --- a/packages/services/src/view-service/delegations-by-address-index.ts +++ b/packages/services/src/view-service/delegations-by-address-index.ts @@ -64,10 +64,7 @@ export const delegationsByAddressIndex: Impl['delegationsByAddressIndex'] = asyn for await (const validatorInfoResponse of mockStakeClient.validatorInfo({ showInactive })) { const validatorInfo = getValidatorInfo(validatorInfoResponse); - const extendedMetadata = new Any({ - typeUrl: ValidatorInfo.typeName, - value: validatorInfo.toBinary(), - }); + const extendedMetadata = Any.pack(validatorInfo); const identityKey = getValidatorInfo.pipe(getIdentityKeyFromValidatorInfo)( validatorInfoResponse, diff --git a/packages/services/src/view-service/unbonding-tokens-by-address-index/index.ts b/packages/services/src/view-service/unbonding-tokens-by-address-index/index.ts index f01d50a075..d37251ad25 100644 --- a/packages/services/src/view-service/unbonding-tokens-by-address-index/index.ts +++ b/packages/services/src/view-service/unbonding-tokens-by-address-index/index.ts @@ -8,7 +8,6 @@ import { Impl } from '../index.js'; import { balances } from '../balances.js'; import { getIsClaimable, isUnbondingTokenBalance } from './helpers.js'; import { Any } from '@bufbuild/protobuf'; -import { ValidatorInfo } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb.js'; import { stakeClientCtx } from '../../ctx/stake-client.js'; import { getValidatorInfo } from '@penumbra-zone/getters/get-validator-info-response'; import { assetPatterns } from '@penumbra-zone/types/assets'; @@ -59,17 +58,13 @@ export const unbondingTokensByAddressIndex: Impl['unbondingTokensByAddressIndex' identityKey: identityKeyFromBech32m(regexResult.idKey), }); const validatorInfo = getValidatorInfo(validatorInfoResponse); - const extendedMetadata = new Any({ - typeUrl: ValidatorInfo.typeName, - value: validatorInfo.toBinary(), - }); const withValidatorInfo = getBalanceView(new BalancesResponse(balancesResponse)); if (withValidatorInfo.valueView.case !== 'knownAssetId') { throw new Error(`Unexpected ValueView case: ${withValidatorInfo.valueView.case}`); } - withValidatorInfo.valueView.value.extendedMetadata = extendedMetadata; + withValidatorInfo.valueView.value.extendedMetadata = Any.pack(validatorInfo); yield new UnbondingTokensByAddressIndexResponse({ claimable,