Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cosmos sdk decimal under typingsFormat.customTypes.useCosmosSDKDec flag #332

Merged
merged 1 commit into from
Mar 29, 2023
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
13 changes: 7 additions & 6 deletions __fixtures__/v-next/outputv4/akash/inflation/v1beta2/params.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as _m0 from "protobufjs/minimal";
import { Decimal } from "@cosmjs/math";
import { isSet, DeepPartial, Exact } from "../../../helpers";
export const protobufPackage = "akash.inflation.v1beta2";

Expand Down Expand Up @@ -38,15 +39,15 @@ function createBaseParams(): Params {
export const Params = {
encode(message: Params, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.inflationDecayFactor !== "") {
writer.uint32(10).string(message.inflationDecayFactor);
writer.uint32(10).string(Decimal.fromUserInput(message.inflationDecayFactor, 18).atomics);
}

if (message.initialInflation !== "") {
writer.uint32(18).string(message.initialInflation);
writer.uint32(18).string(Decimal.fromUserInput(message.initialInflation, 18).atomics);
}

if (message.variance !== "") {
writer.uint32(26).string(message.variance);
writer.uint32(26).string(Decimal.fromUserInput(message.variance, 18).atomics);
}

return writer;
Expand All @@ -62,15 +63,15 @@ export const Params = {

switch (tag >>> 3) {
case 1:
message.inflationDecayFactor = reader.string();
message.inflationDecayFactor = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 2:
message.initialInflation = reader.string();
message.initialInflation = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 3:
message.variance = reader.string();
message.variance = Decimal.fromAtomics(reader.string(), 18).toString();
break;

default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DecCoin, DecCoinSDKType, Coin, CoinSDKType } from "../../base/v1beta1/coin";
import * as _m0 from "protobufjs/minimal";
import { Decimal } from "@cosmjs/math";
import { isSet, DeepPartial, Long } from "../../../helpers";
export const protobufPackage = "cosmos.distribution.v1beta1";

Expand Down Expand Up @@ -257,15 +258,15 @@ function createBaseParams(): Params {
export const Params = {
encode(message: Params, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.communityTax !== "") {
writer.uint32(10).string(message.communityTax);
writer.uint32(10).string(Decimal.fromUserInput(message.communityTax, 18).atomics);
}

if (message.baseProposerReward !== "") {
writer.uint32(18).string(message.baseProposerReward);
writer.uint32(18).string(Decimal.fromUserInput(message.baseProposerReward, 18).atomics);
}

if (message.bonusProposerReward !== "") {
writer.uint32(26).string(message.bonusProposerReward);
writer.uint32(26).string(Decimal.fromUserInput(message.bonusProposerReward, 18).atomics);
}

if (message.withdrawAddrEnabled === true) {
Expand All @@ -285,15 +286,15 @@ export const Params = {

switch (tag >>> 3) {
case 1:
message.communityTax = reader.string();
message.communityTax = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 2:
message.baseProposerReward = reader.string();
message.baseProposerReward = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 3:
message.bonusProposerReward = reader.string();
message.bonusProposerReward = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 4:
Expand Down Expand Up @@ -757,7 +758,7 @@ export const ValidatorSlashEvent = {
}

if (message.fraction !== "") {
writer.uint32(18).string(message.fraction);
writer.uint32(18).string(Decimal.fromUserInput(message.fraction, 18).atomics);
}

return writer;
Expand All @@ -777,7 +778,7 @@ export const ValidatorSlashEvent = {
break;

case 2:
message.fraction = reader.string();
message.fraction = Decimal.fromAtomics(reader.string(), 18).toString();
break;

default:
Expand Down Expand Up @@ -1154,7 +1155,7 @@ export const DelegatorStartingInfo = {
}

if (message.stake !== "") {
writer.uint32(18).string(message.stake);
writer.uint32(18).string(Decimal.fromUserInput(message.stake, 18).atomics);
}

if (!message.height.isZero()) {
Expand All @@ -1178,7 +1179,7 @@ export const DelegatorStartingInfo = {
break;

case 2:
message.stake = reader.string();
message.stake = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 3:
Expand Down
5 changes: 3 additions & 2 deletions __fixtures__/v-next/outputv4/cosmos/gov/v1beta1/gov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Any, AnySDKType } from "../../../google/protobuf/any";
import { Timestamp, TimestampSDKType } from "../../../google/protobuf/timestamp";
import { Duration, DurationSDKType } from "../../../google/protobuf/duration";
import * as _m0 from "protobufjs/minimal";
import { Decimal } from "@cosmjs/math";
import { isSet, DeepPartial, Long, toTimestamp, fromTimestamp, bytesFromBase64, base64FromBytes } from "../../../helpers";
export const protobufPackage = "cosmos.gov.v1beta1";

Expand Down Expand Up @@ -379,7 +380,7 @@ export const WeightedVoteOption = {
}

if (message.weight !== "") {
writer.uint32(18).string(message.weight);
writer.uint32(18).string(Decimal.fromUserInput(message.weight, 18).atomics);
}

return writer;
Expand All @@ -399,7 +400,7 @@ export const WeightedVoteOption = {
break;

case 2:
message.weight = reader.string();
message.weight = Decimal.fromAtomics(reader.string(), 18).toString();
break;

default:
Expand Down
25 changes: 13 additions & 12 deletions __fixtures__/v-next/outputv4/cosmos/mint/v1beta1/mint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as _m0 from "protobufjs/minimal";
import { Decimal } from "@cosmjs/math";
import { isSet, DeepPartial, Long } from "../../../helpers";
export const protobufPackage = "cosmos.mint.v1beta1";

Expand Down Expand Up @@ -58,11 +59,11 @@ function createBaseMinter(): Minter {
export const Minter = {
encode(message: Minter, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.inflation !== "") {
writer.uint32(10).string(message.inflation);
writer.uint32(10).string(Decimal.fromUserInput(message.inflation, 18).atomics);
}

if (message.annualProvisions !== "") {
writer.uint32(18).string(message.annualProvisions);
writer.uint32(18).string(Decimal.fromUserInput(message.annualProvisions, 18).atomics);
}

return writer;
Expand All @@ -78,11 +79,11 @@ export const Minter = {

switch (tag >>> 3) {
case 1:
message.inflation = reader.string();
message.inflation = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 2:
message.annualProvisions = reader.string();
message.annualProvisions = Decimal.fromAtomics(reader.string(), 18).toString();
break;

default:
Expand Down Expand Up @@ -156,19 +157,19 @@ export const Params = {
}

if (message.inflationRateChange !== "") {
writer.uint32(18).string(message.inflationRateChange);
writer.uint32(18).string(Decimal.fromUserInput(message.inflationRateChange, 18).atomics);
}

if (message.inflationMax !== "") {
writer.uint32(26).string(message.inflationMax);
writer.uint32(26).string(Decimal.fromUserInput(message.inflationMax, 18).atomics);
}

if (message.inflationMin !== "") {
writer.uint32(34).string(message.inflationMin);
writer.uint32(34).string(Decimal.fromUserInput(message.inflationMin, 18).atomics);
}

if (message.goalBonded !== "") {
writer.uint32(42).string(message.goalBonded);
writer.uint32(42).string(Decimal.fromUserInput(message.goalBonded, 18).atomics);
}

if (!message.blocksPerYear.isZero()) {
Expand All @@ -192,19 +193,19 @@ export const Params = {
break;

case 2:
message.inflationRateChange = reader.string();
message.inflationRateChange = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 3:
message.inflationMax = reader.string();
message.inflationMax = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 4:
message.inflationMin = reader.string();
message.inflationMin = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 5:
message.goalBonded = reader.string();
message.goalBonded = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 6:
Expand Down
29 changes: 15 additions & 14 deletions __fixtures__/v-next/outputv4/cosmos/staking/v1beta1/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Duration, DurationSDKType } from "../../../google/protobuf/duration";
import { Coin, CoinSDKType } from "../../base/v1beta1/coin";
import * as _m0 from "protobufjs/minimal";
import { isSet, DeepPartial, toTimestamp, fromTimestamp, Long } from "../../../helpers";
import { Decimal } from "@cosmjs/math";
export const protobufPackage = "cosmos.staking.v1beta1";

/** BondStatus is the status of a validator. */
Expand Down Expand Up @@ -646,15 +647,15 @@ function createBaseCommissionRates(): CommissionRates {
export const CommissionRates = {
encode(message: CommissionRates, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.rate !== "") {
writer.uint32(10).string(message.rate);
writer.uint32(10).string(Decimal.fromUserInput(message.rate, 18).atomics);
}

if (message.maxRate !== "") {
writer.uint32(18).string(message.maxRate);
writer.uint32(18).string(Decimal.fromUserInput(message.maxRate, 18).atomics);
}

if (message.maxChangeRate !== "") {
writer.uint32(26).string(message.maxChangeRate);
writer.uint32(26).string(Decimal.fromUserInput(message.maxChangeRate, 18).atomics);
}

return writer;
Expand All @@ -670,15 +671,15 @@ export const CommissionRates = {

switch (tag >>> 3) {
case 1:
message.rate = reader.string();
message.rate = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 2:
message.maxRate = reader.string();
message.maxRate = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 3:
message.maxChangeRate = reader.string();
message.maxChangeRate = Decimal.fromAtomics(reader.string(), 18).toString();
break;

default:
Expand Down Expand Up @@ -1004,7 +1005,7 @@ export const Validator = {
}

if (message.delegatorShares !== "") {
writer.uint32(50).string(message.delegatorShares);
writer.uint32(50).string(Decimal.fromUserInput(message.delegatorShares, 18).atomics);
}

if (message.description !== undefined) {
Expand Down Expand Up @@ -1060,7 +1061,7 @@ export const Validator = {
break;

case 6:
message.delegatorShares = reader.string();
message.delegatorShares = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 7:
Expand Down Expand Up @@ -1665,7 +1666,7 @@ export const Delegation = {
}

if (message.shares !== "") {
writer.uint32(26).string(message.shares);
writer.uint32(26).string(Decimal.fromUserInput(message.shares, 18).atomics);
}

return writer;
Expand All @@ -1689,7 +1690,7 @@ export const Delegation = {
break;

case 3:
message.shares = reader.string();
message.shares = Decimal.fromAtomics(reader.string(), 18).toString();
break;

default:
Expand Down Expand Up @@ -2012,7 +2013,7 @@ export const RedelegationEntry = {
}

if (message.sharesDst !== "") {
writer.uint32(34).string(message.sharesDst);
writer.uint32(34).string(Decimal.fromUserInput(message.sharesDst, 18).atomics);
}

return writer;
Expand Down Expand Up @@ -2040,7 +2041,7 @@ export const RedelegationEntry = {
break;

case 4:
message.sharesDst = reader.string();
message.sharesDst = Decimal.fromAtomics(reader.string(), 18).toString();
break;

default:
Expand Down Expand Up @@ -2274,7 +2275,7 @@ export const Params = {
}

if (message.minCommissionRate !== "") {
writer.uint32(50).string(message.minCommissionRate);
writer.uint32(50).string(Decimal.fromUserInput(message.minCommissionRate, 18).atomics);
}

return writer;
Expand Down Expand Up @@ -2310,7 +2311,7 @@ export const Params = {
break;

case 6:
message.minCommissionRate = reader.string();
message.minCommissionRate = Decimal.fromAtomics(reader.string(), 18).toString();
break;

default:
Expand Down
5 changes: 3 additions & 2 deletions __fixtures__/v-next/outputv4/cosmos/staking/v1beta1/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Coin, CoinSDKType } from "../../base/v1beta1/coin";
import { Timestamp, TimestampSDKType } from "../../../google/protobuf/timestamp";
import * as _m0 from "protobufjs/minimal";
import { isSet, DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
import { Decimal } from "@cosmjs/math";
export const protobufPackage = "cosmos.staking.v1beta1";

/** MsgCreateValidator defines a SDK message for creating a new validator. */
Expand Down Expand Up @@ -392,7 +393,7 @@ export const MsgEditValidator = {
}

if (message.commissionRate !== "") {
writer.uint32(26).string(message.commissionRate);
writer.uint32(26).string(Decimal.fromUserInput(message.commissionRate, 18).atomics);
}

if (message.minSelfDelegation !== "") {
Expand Down Expand Up @@ -420,7 +421,7 @@ export const MsgEditValidator = {
break;

case 3:
message.commissionRate = reader.string();
message.commissionRate = Decimal.fromAtomics(reader.string(), 18).toString();
break;

case 4:
Expand Down
Loading