Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 src/client/rest/api/MstakingAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('MstakingAPI', () => {
operator_address: expect.any(String),
consensus_pubkey: expect.any(ValConsPublicKey),
jailed: expect.any(Boolean),
status: expect.any(String),
status: expect.any(Number),
tokens: expect.any(Coins),
delegator_shares: expect.any(Coins),
description: {
Expand Down
5 changes: 3 additions & 2 deletions src/client/rest/api/MstakingAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../../../core'
import { BaseAPI } from './BaseAPI'
import { APIParams, Pagination, PaginationOptions } from '../APIRequester'
import { bondStatusToJSON } from '@initia/initia.proto/initia/mstaking/v1/staking'

export interface MstakingPool {
/** amount of tokens are bonded, including those that are currently unbonding */
Expand Down Expand Up @@ -64,7 +65,7 @@ export class MstakingAPI extends BaseAPI {
pagination: Pagination
}>(
`/initia/mstaking/v1/delegations/${delegator}`,
{ ...params, status },
{ ...params, status: status ? bondStatusToJSON(status) : undefined },
headers
)
.then((data) => [
Expand Down Expand Up @@ -257,7 +258,7 @@ export class MstakingAPI extends BaseAPI {
`/initia/mstaking/v1/delegators/${delegator}/total_delegation_balance`,
{
...params,
status,
status: status ? bondStatusToJSON(status) : undefined,
},
headers
)
Expand Down
10 changes: 6 additions & 4 deletions src/core/gov/Vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { AccAddress } from '../bech32'
import {
Vote as Vote_pb,
VoteOption,
voteOptionFromJSON,
voteOptionToJSON,
WeightedVoteOption as WeightedVoteOption_pb,
} from '@initia/initia.proto/cosmos/gov/v1/gov'

Expand Down Expand Up @@ -123,7 +125,7 @@ export class WeightedVoteOption extends JSONSerializable<

public static fromAmino(data: WeightedVoteOption.Amino): WeightedVoteOption {
const { option, weight } = data
return new WeightedVoteOption(option, parseFloat(weight))
return new WeightedVoteOption(voteOptionFromJSON(option), parseFloat(weight))
}

public toAmino(): WeightedVoteOption.Amino {
Expand All @@ -136,13 +138,13 @@ export class WeightedVoteOption extends JSONSerializable<

public static fromData(data: WeightedVoteOption.Data): WeightedVoteOption {
const { option, weight } = data
return new WeightedVoteOption(option, parseFloat(weight))
return new WeightedVoteOption(voteOptionFromJSON(option), parseFloat(weight))
}

public toData(): WeightedVoteOption.Data {
const { option, weight } = this
return {
option,
option: voteOptionToJSON(option),
weight: weight.toString(),
}
}
Expand All @@ -167,7 +169,7 @@ export namespace WeightedVoteOption {
}

export interface Data {
option: VoteOption
option: string
weight: string
}

Expand Down
24 changes: 19 additions & 5 deletions src/core/gov/msgs/MsgVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { JSONSerializable } from '../../../util/json'
import { AccAddress } from '../../bech32'
import { Any } from '@initia/initia.proto/google/protobuf/any'
import { MsgVote as MsgVote_pb } from '@initia/initia.proto/cosmos/gov/v1/tx'
import { VoteOption } from '@initia/initia.proto/cosmos/gov/v1/gov'
import {
VoteOption,
voteOptionFromJSON,
voteOptionToJSON,
} from '@initia/initia.proto/cosmos/gov/v1/gov'

/**
* MsgVote defines a message to cast a vote.
Expand Down Expand Up @@ -31,7 +35,12 @@ export class MsgVote extends JSONSerializable<
const {
value: { proposal_id, voter, option, metadata },
} = data
return new MsgVote(parseInt(proposal_id), voter, option, metadata ?? '')
return new MsgVote(
parseInt(proposal_id),
voter,
voteOptionFromJSON(option),
metadata ?? ''
)
}

public toAmino(): MsgVote.Amino {
Expand All @@ -49,7 +58,12 @@ export class MsgVote extends JSONSerializable<

public static fromData(data: MsgVote.Data): MsgVote {
const { proposal_id, voter, option, metadata } = data
return new MsgVote(parseInt(proposal_id), voter, option, metadata)
return new MsgVote(
parseInt(proposal_id),
voter,
voteOptionFromJSON(option),
metadata
)
}

public toData(): MsgVote.Data {
Expand All @@ -58,7 +72,7 @@ export class MsgVote extends JSONSerializable<
'@type': '/cosmos.gov.v1.MsgVote',
proposal_id: proposal_id.toFixed(),
voter,
option,
option: voteOptionToJSON(option),
metadata,
}
}
Expand Down Expand Up @@ -112,7 +126,7 @@ export namespace MsgVote {
'@type': '/cosmos.gov.v1.MsgVote'
proposal_id: string
voter: AccAddress
option: Option
option: string
metadata: string
}

Expand Down
22 changes: 17 additions & 5 deletions src/core/gov/msgs/MsgVoteLegacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { JSONSerializable } from '../../../util/json'
import { AccAddress } from '../../bech32'
import { Any } from '@initia/initia.proto/google/protobuf/any'
import { MsgVote as MsgVote_pb } from '@initia/initia.proto/cosmos/gov/v1beta1/tx'
import { VoteOption } from '@initia/initia.proto/cosmos/gov/v1beta1/gov'
import {
VoteOption,
voteOptionFromJSON,
voteOptionToJSON,
} from '@initia/initia.proto/cosmos/gov/v1beta1/gov'

/**
* MsgVoteLegacy votes for a proposal.
Expand All @@ -29,7 +33,11 @@ export class MsgVoteLegacy extends JSONSerializable<
const {
value: { proposal_id, voter, option },
} = data
return new MsgVoteLegacy(parseInt(proposal_id), voter, option)
return new MsgVoteLegacy(
parseInt(proposal_id),
voter,
voteOptionFromJSON(option)
)
}

public toAmino(): MsgVoteLegacy.Amino {
Expand All @@ -46,7 +54,11 @@ export class MsgVoteLegacy extends JSONSerializable<

public static fromData(data: MsgVoteLegacy.Data): MsgVoteLegacy {
const { proposal_id, voter, option } = data
return new MsgVoteLegacy(parseInt(proposal_id), voter, option)
return new MsgVoteLegacy(
parseInt(proposal_id),
voter,
voteOptionFromJSON(option)
)
}

public toData(): MsgVoteLegacy.Data {
Expand All @@ -55,7 +67,7 @@ export class MsgVoteLegacy extends JSONSerializable<
'@type': '/cosmos.gov.v1beta1.MsgVote',
proposal_id: proposal_id.toFixed(),
voter,
option,
option: voteOptionToJSON(option),
}
}

Expand Down Expand Up @@ -105,7 +117,7 @@ export namespace MsgVoteLegacy {
'@type': '/cosmos.gov.v1beta1.MsgVote'
proposal_id: string
voter: AccAddress
option: Option
option: string
}

export type Proto = MsgVote_pb
Expand Down
14 changes: 8 additions & 6 deletions src/core/mstaking/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
Commission as Commission_pb,
CommissionRates as CommissionRates_pb,
BondStatus,
bondStatusFromJSON,
bondStatusToJSON,
} from '@initia/initia.proto/initia/mstaking/v1/staking'
import { Any } from '@initia/initia.proto/google/protobuf/any'

Expand Down Expand Up @@ -65,7 +67,7 @@ export class Validator extends JSONSerializable<
data.operator_address,
ValConsPublicKey.fromAmino(data.consensus_pubkey),
data.jailed || false,
data.status || 0,
bondStatusFromJSON(data.status),
Coins.fromAmino(data.tokens),
Coins.fromAmino(data.delegator_shares),
Validator.Description.fromAmino(data.description),
Expand All @@ -82,7 +84,7 @@ export class Validator extends JSONSerializable<
operator_address: this.operator_address,
consensus_pubkey: this.consensus_pubkey.toAmino(),
jailed: this.jailed,
status: this.status,
status: bondStatusToJSON(this.status),
tokens: this.tokens.toAmino(),
delegator_shares: this.delegator_shares.toAmino(),
description: this.description,
Expand All @@ -99,7 +101,7 @@ export class Validator extends JSONSerializable<
data.operator_address,
ValConsPublicKey.fromData(data.consensus_pubkey),
data.jailed || false,
data.status || 0,
bondStatusFromJSON(data.status),
Coins.fromData(data.tokens),
Coins.fromData(data.delegator_shares),
Validator.Description.fromData(data.description),
Expand All @@ -116,7 +118,7 @@ export class Validator extends JSONSerializable<
operator_address: this.operator_address,
consensus_pubkey: this.consensus_pubkey.toData(),
jailed: this.jailed,
status: this.status,
status: bondStatusToJSON(this.status),
tokens: this.tokens.toData(),
delegator_shares: this.delegator_shares.toData(),
description: this.description,
Expand Down Expand Up @@ -188,7 +190,7 @@ export namespace Validator {
operator_address: ValAddress
consensus_pubkey: ValConsPublicKey.Amino
jailed: boolean
status: BondStatus
status: string
tokens: Coins.Amino
delegator_shares: Coins.Amino
description: Description.Amino
Expand All @@ -203,7 +205,7 @@ export namespace Validator {
operator_address: ValAddress
consensus_pubkey: ValConsPublicKey.Data
jailed: boolean
status: BondStatus
status: string
tokens: Coins.Data
delegator_shares: Coins.Data
description: Description.Data
Expand Down
Loading