From 1573f8a5ad1fd10713e7129cdef9fdc946cf6365 Mon Sep 17 00:00:00 2001 From: Yun Yeo Date: Wed, 17 Nov 2021 16:17:18 +0900 Subject: [PATCH 1/4] v3.0.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index ec43efda9..13aa2090b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@terra-money/terra.js", - "version": "3.0.0-beta.1", + "version": "3.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@terra-money/terra.js", - "version": "3.0.0-beta.1", + "version": "3.0.0", "license": "MIT", "dependencies": { "@terra-money/terra.proto": "^0.1.7", diff --git a/package.json b/package.json index dfcc560de..ddfbef8f5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@terra-money/terra.js", - "version": "3.0.0-beta.1", + "version": "3.0.0", "description": "The JavaScript SDK for Terra", "license": "MIT", "author": "Terraform Labs, PTE.", From e6b217a96ab96f3ee7b0aa9ed105748de285510c Mon Sep 17 00:00:00 2001 From: Geoff Lee Date: Thu, 20 Jan 2022 15:15:38 +0900 Subject: [PATCH 2/4] add spec for MsgTransfer --- .../ibc-transfer/msgs/MsgTransfer.spec.ts | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/core/ibc-transfer/msgs/MsgTransfer.spec.ts b/src/core/ibc-transfer/msgs/MsgTransfer.spec.ts index 4820e4481..f1ef12e48 100644 --- a/src/core/ibc-transfer/msgs/MsgTransfer.spec.ts +++ b/src/core/ibc-transfer/msgs/MsgTransfer.spec.ts @@ -1,5 +1,6 @@ import { MsgTransfer } from './MsgTransfer'; import { Coin } from '../../Coin'; +import { Height } from '../../ibc/msgs/client/Height'; describe('MsgTransfer', () => { it('deserializes correctly', () => { @@ -29,6 +30,66 @@ describe('MsgTransfer', () => { }, timeout_timestamp: 1631618921, }); + }); + + it('deserializes amino without timeout_height', () => { + const send = MsgTransfer.fromData({ + '@type': '/ibc.applications.transfer.v1.MsgTransfer', + source_port: 'sourceport-01', + source_channel: 'sourcehannel-01', + token: { denom: 'uluna', amount: '1024' }, + sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', + receiver: 'recvr17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp', + timeout_height: { + revision_number: '0', + revision_height: '0', + }, + timeout_timestamp: '1631618921', + }); + const aminoSend = send.toAmino(); + + expect(aminoSend).toMatchObject({ + type: 'cosmos-sdk/MsgTransfer', + value: { + source_port: 'sourceport-01', + source_channel: 'sourcehannel-01', + token: new Coin('uluna', '1024').toAmino(), + sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', + receiver: 'recvr17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp', + timeout_timestamp: '1631618921', + }, + }); + + expect(send.toData()).toMatchObject({}); + }); + + it('deserializes amino without timeout_timestamp', () => { + const send = MsgTransfer.fromData({ + '@type': '/ibc.applications.transfer.v1.MsgTransfer', + source_port: 'sourceport-01', + source_channel: 'sourcehannel-01', + token: { denom: 'uluna', amount: '1024' }, + sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', + receiver: 'recvr17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp', + timeout_height: { + revision_number: '5', + revision_height: '57240001', + }, + timeout_timestamp: '0', + }); + const aminoSend = send.toAmino(); + + expect(aminoSend).toMatchObject({ + type: 'cosmos-sdk/MsgTransfer', + value: { + source_port: 'sourceport-01', + source_channel: 'sourcehannel-01', + token: new Coin('uluna', '1024').toAmino(), + sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', + receiver: 'recvr17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp', + timeout_height: new Height(5, 57240001).toAmino(), + }, + }); expect(send.toData()).toMatchObject({}); }); From 154e48212a60d0a9cbceabdb5359ad853eddaf28 Mon Sep 17 00:00:00 2001 From: Geoff Lee Date: Mon, 24 Jan 2022 14:18:07 +0900 Subject: [PATCH 3/4] fix conversion error of timestamp in MsgTransfer --- .../ibc-transfer/msgs/MsgTransfer.spec.ts | 16 +++---- src/core/ibc-transfer/msgs/MsgTransfer.ts | 42 ++++++++++++++----- src/core/ibc/msgs/client/Height.ts | 6 ++- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/core/ibc-transfer/msgs/MsgTransfer.spec.ts b/src/core/ibc-transfer/msgs/MsgTransfer.spec.ts index f1ef12e48..7fae0ed0f 100644 --- a/src/core/ibc-transfer/msgs/MsgTransfer.spec.ts +++ b/src/core/ibc-transfer/msgs/MsgTransfer.spec.ts @@ -1,6 +1,7 @@ import { MsgTransfer } from './MsgTransfer'; import { Coin } from '../../Coin'; import { Height } from '../../ibc/msgs/client/Height'; +import { Numeric } from '../..'; describe('MsgTransfer', () => { it('deserializes correctly', () => { @@ -15,7 +16,7 @@ describe('MsgTransfer', () => { revision_number: '0', revision_height: '0', }, - timeout_timestamp: '1631618921', + timeout_timestamp: '1642663176848000000', }); expect(send).toMatchObject({ @@ -28,7 +29,7 @@ describe('MsgTransfer', () => { revision_number: 0, revision_height: 0, }, - timeout_timestamp: 1631618921, + timeout_timestamp: Numeric.parse('1642663176848000000'), }); }); @@ -40,11 +41,8 @@ describe('MsgTransfer', () => { token: { denom: 'uluna', amount: '1024' }, sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', receiver: 'recvr17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp', - timeout_height: { - revision_number: '0', - revision_height: '0', - }, - timeout_timestamp: '1631618921', + timeout_height: new Height(0, 0).toData(), + timeout_timestamp: '1642663176848000000', }); const aminoSend = send.toAmino(); @@ -56,7 +54,8 @@ describe('MsgTransfer', () => { token: new Coin('uluna', '1024').toAmino(), sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', receiver: 'recvr17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp', - timeout_timestamp: '1631618921', + timeout_height: {}, + timeout_timestamp: '1642663176848000000', }, }); @@ -88,6 +87,7 @@ describe('MsgTransfer', () => { sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', receiver: 'recvr17lmam6zguazs5q5u6z5mmx76uj63gldnse2pdp', timeout_height: new Height(5, 57240001).toAmino(), + timeout_timestamp: undefined, }, }); diff --git a/src/core/ibc-transfer/msgs/MsgTransfer.ts b/src/core/ibc-transfer/msgs/MsgTransfer.ts index 2e7e1cbe3..a74f783fd 100644 --- a/src/core/ibc-transfer/msgs/MsgTransfer.ts +++ b/src/core/ibc-transfer/msgs/MsgTransfer.ts @@ -5,6 +5,7 @@ import * as Long from 'long'; import { Any } from '@terra-money/terra.proto/google/protobuf/any'; import { MsgTransfer as MsgTransfer_pb } from '@terra-money/terra.proto/ibc/applications/transfer/v1/tx'; import { Height } from '../../ibc/msgs/client/Height'; +import { Numeric } from '../../..'; /** * A basic message for transfer [[Coin]] via IBC. */ @@ -19,7 +20,7 @@ export class MsgTransfer extends JSONSerializable< public sender: AccAddress; public receiver: string; // destination chain can be non-cosmos-based public timeout_height?: Height; // 0 to disable - public timeout_timestamp: number; // 0 to disable + public timeout_timestamp?: Numeric.Output; // 0 to disable /** * @param source_port the port on which the packet will be sent * @param source_channel the channel by which the packet will be sent @@ -36,16 +37,23 @@ export class MsgTransfer extends JSONSerializable< sender: AccAddress, receiver: string, timeout_height: Height | undefined, - timeout_timestamp: number + timeout_timestamp: Numeric.Input | undefined ) { super(); + + if (!timeout_height && !timeout_timestamp) { + throw 'both of timeout_height and timeout_timestamp are undefined'; + } + this.source_port = source_port; this.source_channel = source_channel; this.token = token; this.sender = sender; this.receiver = receiver; this.timeout_height = timeout_height; - this.timeout_timestamp = timeout_timestamp; + this.timeout_timestamp = timeout_timestamp + ? Numeric.parse(timeout_timestamp) + : undefined; } public static fromAmino(data: MsgTransfer.Amino): MsgTransfer { @@ -60,6 +68,11 @@ export class MsgTransfer extends JSONSerializable< timeout_timestamp, }, } = data; + + if (!timeout_height && !timeout_timestamp) { + throw 'both of timeout_height and timeout_timestamp are undefined'; + } + return new MsgTransfer( source_port, source_channel, @@ -67,7 +80,7 @@ export class MsgTransfer extends JSONSerializable< sender, receiver, timeout_height ? Height.fromAmino(timeout_height) : undefined, - Number.parseInt(timeout_timestamp || '0') + timeout_timestamp ? Numeric.parse(timeout_timestamp) : undefined ); } @@ -89,8 +102,8 @@ export class MsgTransfer extends JSONSerializable< token: token ? token.toAmino() : undefined, sender, receiver, - timeout_height: timeout_height?.toAmino(), - timeout_timestamp: timeout_timestamp.toFixed(), + timeout_height: timeout_height?.toAmino() || {}, + timeout_timestamp: timeout_timestamp?.toFixed() || undefined, }, }; } @@ -105,6 +118,11 @@ export class MsgTransfer extends JSONSerializable< timeout_timestamp, timeout_height, } = data; + + if (!timeout_height && !timeout_timestamp) { + throw 'both of timeout_height and timeout_timestamp are undefined'; + } + return new MsgTransfer( source_port, source_channel, @@ -112,7 +130,7 @@ export class MsgTransfer extends JSONSerializable< sender, receiver, timeout_height ? Height.fromData(timeout_height) : undefined, - Number.parseInt(timeout_timestamp) + timeout_timestamp ? Number.parseInt(timeout_timestamp) : undefined ); } @@ -136,11 +154,15 @@ export class MsgTransfer extends JSONSerializable< timeout_height: timeout_height ? timeout_height.toData() : new Height(0, 0).toData(), - timeout_timestamp: timeout_timestamp.toFixed(), + timeout_timestamp: timeout_timestamp?.toFixed() || '0', }; } public static fromProto(proto: MsgTransfer.Proto): MsgTransfer { + if (!proto.timeoutHeight && proto.timeoutTimestamp.toNumber() == 0) { + throw 'both of timeout_height and timeout_timestamp are empty'; + } + return new MsgTransfer( proto.sourcePort, proto.sourceChannel, @@ -169,7 +191,7 @@ export class MsgTransfer extends JSONSerializable< sender, receiver, timeoutHeight: timeout_height ? timeout_height.toProto() : undefined, - timeoutTimestamp: Long.fromNumber(timeout_timestamp), + timeoutTimestamp: Long.fromString(timeout_timestamp?.toFixed() || '0'), }); } @@ -194,7 +216,7 @@ export namespace MsgTransfer { token?: Coin.Amino; sender: AccAddress; receiver: string; - timeout_height?: Height.Amino; + timeout_height: Height.Amino; timeout_timestamp?: string; }; } diff --git a/src/core/ibc/msgs/client/Height.ts b/src/core/ibc/msgs/client/Height.ts index 35ad90208..58e109c09 100644 --- a/src/core/ibc/msgs/client/Height.ts +++ b/src/core/ibc/msgs/client/Height.ts @@ -38,8 +38,10 @@ export class Height extends JSONSerializable< public toAmino(): Height.Amino { const { revision_number, revision_height } = this; const res: Height.Amino = { - revision_number: revision_number.toFixed(), - revision_height: revision_height.toFixed(), + revision_number: + revision_number > 0 ? revision_number.toFixed() : undefined, + revision_height: + revision_height > 0 ? revision_height.toFixed() : undefined, }; return res; } From 550c34cc0fdd20a361bcbd9a639ca013b7f53686 Mon Sep 17 00:00:00 2001 From: Geoff Lee Date: Mon, 24 Jan 2022 17:53:03 +0900 Subject: [PATCH 4/4] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c7112bd13..c4dd29a50 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@terra-money/terra.js", - "version": "3.0.4", + "version": "3.0.5", "description": "The JavaScript SDK for Terra", "license": "MIT", "author": "Terraform Labs, PTE.",