Skip to content

Commit

Permalink
fix: gov modules
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Jun 7, 2022
1 parent ac1c848 commit beb1eb4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
41 changes: 30 additions & 11 deletions packages/sdk-ts/src/client/chain/grpc/ChainGrpcGovApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,40 @@ import { paginationRequestFromPagination } from '../../../utils/pagination'
import { ChainGrpcGovTransformer } from '../transformers/ChainGrpcGovTransformer'

export class ChainGrpcGovApi extends BaseConsumer {
async fetchParamsByType(type: string) {
const request = new QueryGovernanceParamsRequest()
async fetchModuleParams() {
const paramTypes = ['voting', 'deposit', 'tallying']
const requests = paramTypes.map((type) => {
const request = new QueryGovernanceParamsRequest()
request.setParamsType(type)

request.setParamsType(type)
return request
})

try {
const response = await this.request<
QueryGovernanceParamsRequest,
QueryGovernanceParamsResponse,
typeof GovernanceQuery.Params
>(request, GovernanceQuery.Params)

return ChainGrpcGovTransformer.moduleParamsResponseToModuleParams(
response,
const responses = await Promise.all(
requests.map((request) =>
this.request<
QueryGovernanceParamsRequest,
QueryGovernanceParamsResponse,
typeof GovernanceQuery.Params
>(request, GovernanceQuery.Params),
),
)
const votingParams = responses.find((response) =>
response.hasVotingParams(),
)!
const tallyParams = responses.find((response) =>
response.hasTallyParams(),
)!
const depositParams = responses.find((response) =>
response.hasDepositParams(),
)!

return ChainGrpcGovTransformer.moduleParamsResponseToModuleParamsByType({
votingParams: votingParams.getVotingParams()!,
tallyParams: tallyParams.getTallyParams()!,
depositParams: depositParams.getDepositParams()!,
})
} catch (e: any) {
throw new Error(e.message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import {
Vote,
TallyResult,
GrpcTallyResult,
GrpcGovernanceDepositParams,
GrpcGovernanceVotingParams,
GrpcGovernanceTallyParams,
} from '../types/gov'
import { Pagination } from '../../../types/index'
import { grpcPaginationToPagination } from '../../../utils/pagination'
Expand Down Expand Up @@ -47,6 +50,34 @@ export class ChainGrpcGovTransformer {
}
}

static moduleParamsResponseToModuleParamsByType({
depositParams,
votingParams,
tallyParams,
}: {
depositParams: GrpcGovernanceDepositParams
votingParams: GrpcGovernanceVotingParams
tallyParams: GrpcGovernanceTallyParams
}): GovModuleStateParams {
return {
depositParams: {
minDepositList: depositParams
?.getMinDepositList()
.map((m) => m.toObject()),
maxDepositPeriod:
depositParams?.getMaxDepositPeriod()?.getSeconds() || 0,
},
votingParams: {
votingPeriod: votingParams.getVotingPeriod()?.getSeconds() || 0,
},
tallyParams: {
quorum: uint8ArrayToString(tallyParams.getQuorum()) || '',
threshold: uint8ArrayToString(tallyParams.getThreshold()) || '',
vetoThreshold: uint8ArrayToString(tallyParams.getVetoThreshold()) || '',
},
}
}

static proposalResponseToProposal(response: QueryProposalResponse): Proposal {
const proposal = response.getProposal()!

Expand Down

0 comments on commit beb1eb4

Please sign in to comment.