From c0490897fa2eb5fea79573d1e584e7bf8ceaec55 Mon Sep 17 00:00:00 2001 From: Tom Wang Date: Fri, 1 Mar 2024 22:42:37 +0800 Subject: [PATCH] Simpify queries code with object property shorthand --- packages/stargate/src/modules/auth/queries.ts | 2 +- .../stargate/src/modules/authz/queries.ts | 10 +-- packages/stargate/src/modules/bank/queries.ts | 8 +- .../src/modules/distribution/queries.ts | 16 ++-- .../stargate/src/modules/feegrant/queries.ts | 6 +- packages/stargate/src/modules/ibc/queries.ts | 90 +++++++++---------- .../stargate/src/modules/slashing/queries.ts | 2 +- .../stargate/src/modules/staking/queries.ts | 2 +- 8 files changed, 67 insertions(+), 69 deletions(-) diff --git a/packages/stargate/src/modules/auth/queries.ts b/packages/stargate/src/modules/auth/queries.ts index 348f7d8f3d..49bba529f9 100644 --- a/packages/stargate/src/modules/auth/queries.ts +++ b/packages/stargate/src/modules/auth/queries.ts @@ -25,7 +25,7 @@ export function setupAuthExtension(base: QueryClient): AuthExtension { return { auth: { account: async (address: string) => { - const { account } = await queryService.Account({ address: address }); + const { account } = await queryService.Account({ address }); return account ?? null; }, }, diff --git a/packages/stargate/src/modules/authz/queries.ts b/packages/stargate/src/modules/authz/queries.ts index 0dd2b53b6d..614ab8095c 100644 --- a/packages/stargate/src/modules/authz/queries.ts +++ b/packages/stargate/src/modules/authz/queries.ts @@ -36,21 +36,21 @@ export function setupAuthzExtension(base: QueryClient): AuthzExtension { authz: { grants: async (granter: string, grantee: string, msgTypeUrl: string, paginationKey?: Uint8Array) => { return await queryService.Grants({ - granter: granter, - grantee: grantee, - msgTypeUrl: msgTypeUrl, + granter, + grantee, + msgTypeUrl, pagination: createPagination(paginationKey), }); }, granteeGrants: async (grantee: string, paginationKey?: Uint8Array) => { return await queryService.GranteeGrants({ - grantee: grantee, + grantee, pagination: createPagination(paginationKey), }); }, granterGrants: async (granter: string, paginationKey?: Uint8Array) => { return await queryService.GranterGrants({ - granter: granter, + granter, pagination: createPagination(paginationKey), }); }, diff --git a/packages/stargate/src/modules/bank/queries.ts b/packages/stargate/src/modules/bank/queries.ts index 4ac41c010c..d681ed3a91 100644 --- a/packages/stargate/src/modules/bank/queries.ts +++ b/packages/stargate/src/modules/bank/queries.ts @@ -31,14 +31,12 @@ export function setupBankExtension(base: QueryClient): BankExtension { return { bank: { balance: async (address: string, denom: string) => { - const { balance } = await queryService.Balance({ address: address, denom: denom }); + const { balance } = await queryService.Balance({ address, denom }); assert(balance); return balance; }, allBalances: async (address: string) => { - const { balances } = await queryService.AllBalances( - QueryAllBalancesRequest.fromPartial({ address: address }), - ); + const { balances } = await queryService.AllBalances(QueryAllBalancesRequest.fromPartial({ address })); return balances; }, totalSupply: async (paginationKey?: Uint8Array) => { @@ -48,7 +46,7 @@ export function setupBankExtension(base: QueryClient): BankExtension { return response; }, supplyOf: async (denom: string) => { - const { amount } = await queryService.SupplyOf({ denom: denom }); + const { amount } = await queryService.SupplyOf({ denom }); assert(amount); return amount; }, diff --git a/packages/stargate/src/modules/distribution/queries.ts b/packages/stargate/src/modules/distribution/queries.ts index 5a66ac9a41..10f15b75c4 100644 --- a/packages/stargate/src/modules/distribution/queries.ts +++ b/packages/stargate/src/modules/distribution/queries.ts @@ -52,26 +52,26 @@ export function setupDistributionExtension(base: QueryClient): DistributionExten }, delegationRewards: async (delegatorAddress: string, validatorAddress: string) => { const response = await queryService.DelegationRewards({ - delegatorAddress: delegatorAddress, - validatorAddress: validatorAddress, + delegatorAddress, + validatorAddress, }); return response; }, delegationTotalRewards: async (delegatorAddress: string) => { const response = await queryService.DelegationTotalRewards({ - delegatorAddress: delegatorAddress, + delegatorAddress, }); return response; }, delegatorValidators: async (delegatorAddress: string) => { const response = await queryService.DelegatorValidators({ - delegatorAddress: delegatorAddress, + delegatorAddress, }); return response; }, delegatorWithdrawAddress: async (delegatorAddress: string) => { const response = await queryService.DelegatorWithdrawAddress({ - delegatorAddress: delegatorAddress, + delegatorAddress, }); return response; }, @@ -81,13 +81,13 @@ export function setupDistributionExtension(base: QueryClient): DistributionExten }, validatorCommission: async (validatorAddress: string) => { const response = await queryService.ValidatorCommission({ - validatorAddress: validatorAddress, + validatorAddress, }); return response; }, validatorOutstandingRewards: async (validatorAddress: string) => { const response = await queryService.ValidatorOutstandingRewards({ - validatorAddress: validatorAddress, + validatorAddress, }); return response; }, @@ -98,7 +98,7 @@ export function setupDistributionExtension(base: QueryClient): DistributionExten paginationKey?: Uint8Array, ) => { const response = await queryService.ValidatorSlashes({ - validatorAddress: validatorAddress, + validatorAddress, startingHeight: BigInt(startingHeight), endingHeight: BigInt(endingHeight), pagination: createPagination(paginationKey), diff --git a/packages/stargate/src/modules/feegrant/queries.ts b/packages/stargate/src/modules/feegrant/queries.ts index f37634cf1a..fab9043622 100644 --- a/packages/stargate/src/modules/feegrant/queries.ts +++ b/packages/stargate/src/modules/feegrant/queries.ts @@ -23,14 +23,14 @@ export function setupFeegrantExtension(base: QueryClient): FeegrantExtension { feegrant: { allowance: async (granter: string, grantee: string) => { const response = await queryService.Allowance({ - granter: granter, - grantee: grantee, + granter, + grantee, }); return response; }, allowances: async (grantee: string, paginationKey?: Uint8Array) => { const response = await queryService.Allowances({ - grantee: grantee, + grantee, pagination: createPagination(paginationKey), }); return response; diff --git a/packages/stargate/src/modules/ibc/queries.ts b/packages/stargate/src/modules/ibc/queries.ts index cbf2faacdc..f6ea0c4527 100644 --- a/packages/stargate/src/modules/ibc/queries.ts +++ b/packages/stargate/src/modules/ibc/queries.ts @@ -199,8 +199,8 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { channel: { channel: async (portId: string, channelId: string) => channelQueryService.Channel({ - portId: portId, - channelId: channelId, + portId, + channelId, }), channels: async (paginationKey?: Uint8Array) => channelQueryService.Channels({ @@ -218,13 +218,13 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { key = response.pagination?.nextKey; } while (key && key.length); return QueryChannelsResponse.fromPartial({ - channels: channels, + channels, height: response.height, }); }, connectionChannels: async (connection: string, paginationKey?: Uint8Array) => channelQueryService.ConnectionChannels({ - connection: connection, + connection, pagination: createPagination(paginationKey), }), allConnectionChannels: async (connection: string) => { @@ -233,21 +233,21 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { let key: Uint8Array | undefined; do { response = await channelQueryService.ConnectionChannels({ - connection: connection, + connection, pagination: createPagination(key), }); channels.push(...response.channels); key = response.pagination?.nextKey; } while (key && key.length); return QueryConnectionChannelsResponse.fromPartial({ - channels: channels, + channels, height: response.height, }); }, clientState: async (portId: string, channelId: string) => channelQueryService.ChannelClientState({ - portId: portId, - channelId: channelId, + portId, + channelId, }), consensusState: async ( portId: string, @@ -256,21 +256,21 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { revisionHeight: number, ) => channelQueryService.ChannelConsensusState({ - portId: portId, - channelId: channelId, + portId, + channelId, revisionNumber: BigInt(revisionNumber), revisionHeight: BigInt(revisionHeight), }), packetCommitment: async (portId: string, channelId: string, sequence: number) => channelQueryService.PacketCommitment({ - portId: portId, - channelId: channelId, + portId, + channelId, sequence: longify(sequence), }), packetCommitments: async (portId: string, channelId: string, paginationKey?: Uint8Array) => channelQueryService.PacketCommitments({ - channelId: channelId, - portId: portId, + portId, + channelId, pagination: createPagination(paginationKey), }), allPacketCommitments: async (portId: string, channelId: string) => { @@ -279,34 +279,34 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { let key: Uint8Array | undefined; do { response = await channelQueryService.PacketCommitments({ - channelId: channelId, - portId: portId, + portId, + channelId, pagination: createPagination(key), }); commitments.push(...response.commitments); key = response.pagination?.nextKey; } while (key && key.length); return QueryPacketCommitmentsResponse.fromPartial({ - commitments: commitments, + commitments, height: response.height, }); }, packetReceipt: async (portId: string, channelId: string, sequence: number) => channelQueryService.PacketReceipt({ - portId: portId, - channelId: channelId, + portId, + channelId, sequence: longify(sequence), }), packetAcknowledgement: async (portId: string, channelId: string, sequence: number) => channelQueryService.PacketAcknowledgement({ - portId: portId, - channelId: channelId, + portId, + channelId, sequence: longify(sequence), }), packetAcknowledgements: async (portId: string, channelId: string, paginationKey?: Uint8Array) => { const request = QueryPacketAcknowledgementsRequest.fromPartial({ - portId: portId, - channelId: channelId, + portId, + channelId, pagination: createPagination(paginationKey), }); return channelQueryService.PacketAcknowledgements(request); @@ -317,8 +317,8 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { let key: Uint8Array | undefined; do { const request = QueryPacketAcknowledgementsRequest.fromPartial({ - channelId: channelId, - portId: portId, + portId, + channelId, pagination: createPagination(key), }); response = await channelQueryService.PacketAcknowledgements(request); @@ -326,7 +326,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { key = response.pagination?.nextKey; } while (key && key.length); return QueryPacketAcknowledgementsResponse.fromPartial({ - acknowledgements: acknowledgements, + acknowledgements, height: response.height, }); }, @@ -336,20 +336,20 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { packetCommitmentSequences: readonly number[], ) => channelQueryService.UnreceivedPackets({ - portId: portId, - channelId: channelId, + portId, + channelId, packetCommitmentSequences: packetCommitmentSequences.map((s) => BigInt(s)), }), unreceivedAcks: async (portId: string, channelId: string, packetAckSequences: readonly number[]) => channelQueryService.UnreceivedAcks({ - portId: portId, - channelId: channelId, + portId, + channelId, packetAckSequences: packetAckSequences.map((s) => BigInt(s)), }), nextSequenceReceive: async (portId: string, channelId: string) => channelQueryService.NextSequenceReceive({ - portId: portId, - channelId: channelId, + portId, + channelId, }), }, client: { @@ -370,20 +370,20 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { key = response.pagination?.nextKey; } while (key && key.length); return QueryClientStatesResponse.fromPartial({ - clientStates: clientStates, + clientStates, }); }, consensusState: async (clientId: string, consensusHeight?: number) => clientQueryService.ConsensusState( QueryConsensusStateRequest.fromPartial({ - clientId: clientId, + clientId, revisionHeight: consensusHeight !== undefined ? BigInt(consensusHeight) : undefined, latestHeight: consensusHeight === undefined, }), ), consensusStates: async (clientId: string, paginationKey?: Uint8Array) => clientQueryService.ConsensusStates({ - clientId: clientId, + clientId, pagination: createPagination(paginationKey), }), allConsensusStates: async (clientId: string) => { @@ -392,14 +392,14 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { let key: Uint8Array | undefined; do { response = await clientQueryService.ConsensusStates({ - clientId: clientId, + clientId, pagination: createPagination(key), }); consensusStates.push(...response.consensusStates); key = response.pagination?.nextKey; } while (key && key.length); return QueryConsensusStatesResponse.fromPartial({ - consensusStates: consensusStates, + consensusStates, }); }, params: async () => clientQueryService.ClientParams({}), @@ -429,7 +429,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { consensusStateTm: async (clientId: string, consensusHeight?: Height) => { const response = await clientQueryService.ConsensusState( QueryConsensusStateRequest.fromPartial({ - clientId: clientId, + clientId, revisionHeight: consensusHeight?.revisionHeight, revisionNumber: consensusHeight?.revisionNumber, latestHeight: consensusHeight === undefined, @@ -441,7 +441,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { connection: { connection: async (connectionId: string) => connectionQueryService.Connection({ - connectionId: connectionId, + connectionId, }), connections: async (paginationKey?: Uint8Array) => connectionQueryService.Connections({ @@ -459,28 +459,28 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { key = response.pagination?.nextKey; } while (key && key.length); return QueryConnectionsResponse.fromPartial({ - connections: connections, + connections, height: response.height, }); }, clientConnections: async (clientId: string) => connectionQueryService.ClientConnections({ - clientId: clientId, + clientId, }), clientState: async (connectionId: string) => connectionQueryService.ConnectionClientState({ - connectionId: connectionId, + connectionId, }), consensusState: async (connectionId: string, revisionHeight: number) => connectionQueryService.ConnectionConsensusState( QueryConnectionConsensusStateRequest.fromPartial({ - connectionId: connectionId, + connectionId, revisionHeight: BigInt(revisionHeight), }), ), }, transfer: { - denomTrace: async (hash: string) => transferQueryService.DenomTrace({ hash: hash }), + denomTrace: async (hash: string) => transferQueryService.DenomTrace({ hash }), denomTraces: async (paginationKey?: Uint8Array) => transferQueryService.DenomTraces({ pagination: createPagination(paginationKey), @@ -497,7 +497,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { key = response.pagination?.nextKey; } while (key && key.length); return QueryDenomTracesResponse.fromPartial({ - denomTraces: denomTraces, + denomTraces, }); }, params: async () => transferQueryService.Params({}), diff --git a/packages/stargate/src/modules/slashing/queries.ts b/packages/stargate/src/modules/slashing/queries.ts index c4b07616bb..e4704b2721 100644 --- a/packages/stargate/src/modules/slashing/queries.ts +++ b/packages/stargate/src/modules/slashing/queries.ts @@ -24,7 +24,7 @@ export function setupSlashingExtension(base: QueryClient): SlashingExtension { slashing: { signingInfo: async (consAddress: string) => { const response = await queryService.SigningInfo({ - consAddress: consAddress, + consAddress, }); return response; }, diff --git a/packages/stargate/src/modules/staking/queries.ts b/packages/stargate/src/modules/staking/queries.ts index 03e8c0ed0d..931c937646 100644 --- a/packages/stargate/src/modules/staking/queries.ts +++ b/packages/stargate/src/modules/staking/queries.ts @@ -165,7 +165,7 @@ export function setupStakingExtension(base: QueryClient): StakingExtension { }, validators: async (status: BondStatusString, paginationKey?: Uint8Array) => { const response = await queryService.Validators({ - status: status, + status, pagination: createPagination(paginationKey), }); return response;