From 1fb4e42a79c23db1c12fbba3576ffeb26ea35b22 Mon Sep 17 00:00:00 2001 From: willclarktech Date: Wed, 31 Mar 2021 18:53:14 +0200 Subject: [PATCH] stargate: Fix uint64 -> string representation --- packages/stargate/src/aminomsgs.ts | 10 +++++----- packages/stargate/src/aminotypes.spec.ts | 24 ++++++++++++------------ packages/stargate/src/aminotypes.ts | 12 ++++++------ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/stargate/src/aminomsgs.ts b/packages/stargate/src/aminomsgs.ts index d02c72a1..5040c11f 100644 --- a/packages/stargate/src/aminomsgs.ts +++ b/packages/stargate/src/aminomsgs.ts @@ -178,7 +178,7 @@ enum VoteOption { export interface AminoMsgVote extends AminoMsg { readonly type: "cosmos-sdk/MsgVote"; readonly value: { - readonly proposal_id: number; + readonly proposal_id: string; /** Bech32 account address */ readonly voter: string; readonly option: VoteOption; @@ -193,7 +193,7 @@ export function isAminoMsgVote(msg: AminoMsg): msg is AminoMsgVote { export interface AminoMsgDeposit extends AminoMsg { readonly type: "cosmos-sdk/MsgDeposit"; readonly value: { - readonly proposal_id: number; + readonly proposal_id: string; /** Bech32 account address */ readonly depositor: string; readonly amount: readonly Coin[]; @@ -338,8 +338,8 @@ export function isAminoMsgUndelegate(msg: AminoMsg): msg is AminoMsgUndelegate { // https://github.com/cosmos/ibc-go/blob/07b6a97b67d17fd214a83764cbdb2c2c3daef445/modules/core/02-client/types/client.pb.go#L297-L312 interface AminoHeight { - readonly revision_number: number; - readonly revision_height: number; + readonly revision_number: string; + readonly revision_height: string; } // https://github.com/cosmos/ibc-go/blob/07b6a97b67d17fd214a83764cbdb2c2c3daef445/modules/apps/transfer/types/tx.pb.go#L33-L53 @@ -357,7 +357,7 @@ export interface AminoMsgTransfer extends AminoMsg { readonly timeout_height?: AminoHeight; // Timeout timestamp (in nanoseconds) relative to the current block timestamp. // The timeout is disabled when set to 0. - readonly timeout_timestamp: number; + readonly timeout_timestamp: string; }; } diff --git a/packages/stargate/src/aminotypes.spec.ts b/packages/stargate/src/aminotypes.spec.ts index ed036d85..b2491751 100644 --- a/packages/stargate/src/aminotypes.spec.ts +++ b/packages/stargate/src/aminotypes.spec.ts @@ -326,10 +326,10 @@ describe("AminoTypes", () => { sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", timeoutHeight: { - revisionHeight: Long.fromNumber(123, true), - revisionNumber: Long.fromNumber(456, true), + revisionHeight: Long.fromString("123", true), + revisionNumber: Long.fromString("456", true), }, - timeoutTimestamp: Long.fromNumber(789, true), + timeoutTimestamp: Long.fromString("789", true), }; const aminoMsg = new AminoTypes().toAmino({ typeUrl: "/ibc.applications.transfer.v1.MsgTransfer", @@ -344,10 +344,10 @@ describe("AminoTypes", () => { sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", timeout_height: { - revision_height: 123, - revision_number: 456, + revision_height: "123", + revision_number: "456", }, - timeout_timestamp: 789, + timeout_timestamp: "789", }, }; expect(aminoMsg).toEqual(expected); @@ -636,10 +636,10 @@ describe("AminoTypes", () => { sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", timeout_height: { - revision_height: 123, - revision_number: 456, + revision_height: "123", + revision_number: "456", }, - timeout_timestamp: 789, + timeout_timestamp: "789", }, }; const msg = new AminoTypes().fromAmino(aminoMsg); @@ -650,10 +650,10 @@ describe("AminoTypes", () => { sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", timeoutHeight: { - revisionHeight: Long.fromNumber(123, true), - revisionNumber: Long.fromNumber(456, true), + revisionHeight: Long.fromString("123", true), + revisionNumber: Long.fromString("456", true), }, - timeoutTimestamp: Long.fromNumber(789, true), + timeoutTimestamp: Long.fromString("789", true), }; expect(msg).toEqual({ typeUrl: "/ibc.applications.transfer.v1.MsgTransfer", diff --git a/packages/stargate/src/aminotypes.ts b/packages/stargate/src/aminotypes.ts index 646a7d8b..41a48277 100644 --- a/packages/stargate/src/aminotypes.ts +++ b/packages/stargate/src/aminotypes.ts @@ -345,11 +345,11 @@ function createDefaultTypes(prefix: string): Record { receiver: receiver, timeout_height: timeoutHeight ? { - revision_height: timeoutHeight.revisionHeight.toNumber(), - revision_number: timeoutHeight.revisionNumber.toNumber(), + revision_height: timeoutHeight.revisionHeight.toString(), + revision_number: timeoutHeight.revisionNumber.toString(), } : undefined, - timeout_timestamp: timeoutTimestamp.toNumber(), + timeout_timestamp: timeoutTimestamp.toString(), }), fromAmino: ({ source_port, @@ -367,11 +367,11 @@ function createDefaultTypes(prefix: string): Record { receiver: receiver, timeoutHeight: timeout_height ? { - revisionHeight: Long.fromNumber(timeout_height.revision_height, true), - revisionNumber: Long.fromNumber(timeout_height.revision_number, true), + revisionHeight: Long.fromString(timeout_height.revision_height, true), + revisionNumber: Long.fromString(timeout_height.revision_number, true), } : undefined, - timeoutTimestamp: Long.fromNumber(timeout_timestamp, true), + timeoutTimestamp: Long.fromString(timeout_timestamp, true), }), }, };