From aa998d58d4aae014a6854ebb33f635989900213c Mon Sep 17 00:00:00 2001 From: joon9823 <joon9823@gmail.com> Date: Fri, 10 Jan 2025 15:36:48 +0900 Subject: [PATCH] Fix errors on amino conversions --- package-lock.json | 4 ++-- package.json | 2 +- .../nft-transfer/msgs/MsgNftTransfer.ts | 8 +++---- .../applications/transfer/msgs/MsgTransfer.ts | 8 +++---- src/core/wasm/msgs/MsgExecuteContract.ts | 23 ++++++++++++++----- src/core/wasm/msgs/MsgInstantiateContract.ts | 12 +++++----- .../wasm/msgs/MsgInstantiateContractV2.ts | 12 +++++----- src/core/wasm/msgs/MsgMigrateContract.ts | 23 ++++++++++++++----- .../msgs/MsgStoreAndInstantiateContract.ts | 12 +++++----- .../wasm/msgs/MsgStoreAndMigrateContract.ts | 12 +++++----- src/core/wasm/msgs/MsgSudoContract.ts | 20 +++++++++++----- 11 files changed, 83 insertions(+), 53 deletions(-) diff --git a/package-lock.json b/package-lock.json index f93d6e7..08c0ee2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@initia/initia.js", - "version": "0.2.25", + "version": "0.2.26", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@initia/initia.js", - "version": "0.2.25", + "version": "0.2.26", "license": "Apache-2.0", "dependencies": { "@bitcoinerlab/secp256k1": "^1.1.1", diff --git a/package.json b/package.json index 9fddfa9..d173315 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@initia/initia.js", - "version": "0.2.25", + "version": "0.2.26", "description": "The JavaScript SDK for Initia", "license": "Apache-2.0", "author": "Initia Foundation", diff --git a/src/core/ibc/applications/nft-transfer/msgs/MsgNftTransfer.ts b/src/core/ibc/applications/nft-transfer/msgs/MsgNftTransfer.ts index f64e06c..417c27e 100644 --- a/src/core/ibc/applications/nft-transfer/msgs/MsgNftTransfer.ts +++ b/src/core/ibc/applications/nft-transfer/msgs/MsgNftTransfer.ts @@ -92,7 +92,7 @@ export class MsgNftTransfer extends JSONSerializable< token_ids, sender, receiver, - timeout_height ? Height.fromAmino(timeout_height) : undefined, + Height.fromAmino(timeout_height), timeout_timestamp, memo ) @@ -119,9 +119,9 @@ export class MsgNftTransfer extends JSONSerializable< token_ids, sender, receiver, - timeout_height: timeout_height?.toAmino(), + timeout_height: timeout_height?.toAmino() ?? {}, timeout_timestamp, - memo, + memo: memo === '' ? undefined : memo, }, } } @@ -253,7 +253,7 @@ export namespace MsgNftTransfer { token_ids: string[] sender: AccAddress receiver: string - timeout_height?: Height.Amino + timeout_height: Height.Amino timeout_timestamp?: string memo?: string } diff --git a/src/core/ibc/applications/transfer/msgs/MsgTransfer.ts b/src/core/ibc/applications/transfer/msgs/MsgTransfer.ts index 2f87a1e..a722055 100644 --- a/src/core/ibc/applications/transfer/msgs/MsgTransfer.ts +++ b/src/core/ibc/applications/transfer/msgs/MsgTransfer.ts @@ -87,7 +87,7 @@ export class MsgTransfer extends JSONSerializable< token ? Coin.fromAmino(token) : undefined, sender, receiver, - timeout_height ? Height.fromAmino(timeout_height) : undefined, + Height.fromAmino(timeout_height), timeout_timestamp, memo ) @@ -112,9 +112,9 @@ export class MsgTransfer extends JSONSerializable< token: token?.toAmino(), sender, receiver, - timeout_height: timeout_height?.toAmino(), + timeout_height: timeout_height?.toAmino() ?? {}, timeout_timestamp, - memo, + memo: memo === '' ? undefined : memo, }, } } @@ -238,7 +238,7 @@ export namespace MsgTransfer { token?: Coin.Amino sender: AccAddress receiver: string - timeout_height?: Height.Amino + timeout_height: Height.Amino timeout_timestamp?: string memo?: string } diff --git a/src/core/wasm/msgs/MsgExecuteContract.ts b/src/core/wasm/msgs/MsgExecuteContract.ts index 8abf07e..ee994d9 100644 --- a/src/core/wasm/msgs/MsgExecuteContract.ts +++ b/src/core/wasm/msgs/MsgExecuteContract.ts @@ -34,7 +34,12 @@ export class MsgExecuteContract extends JSONSerializable< value: { sender, contract, msg, funds }, } = data - return new MsgExecuteContract(sender, contract, msg, Coins.fromAmino(funds)) + return new MsgExecuteContract( + sender, + contract, + Buffer.from(JSON.stringify(msg)).toString('base64'), + Coins.fromAmino(funds) + ) } public toAmino(): MsgExecuteContract.Amino { @@ -44,7 +49,7 @@ export class MsgExecuteContract extends JSONSerializable< value: { sender, contract, - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), funds: funds.toAmino(), }, } @@ -52,7 +57,13 @@ export class MsgExecuteContract extends JSONSerializable< public static fromData(data: MsgExecuteContract.Data): MsgExecuteContract { const { sender, contract, msg, funds } = data - return new MsgExecuteContract(sender, contract, msg, Coins.fromData(funds)) + + return new MsgExecuteContract( + sender, + contract, + Buffer.from(JSON.stringify(msg)).toString('base64'), + Coins.fromData(funds) + ) } public toData(): MsgExecuteContract.Data { @@ -61,7 +72,7 @@ export class MsgExecuteContract extends JSONSerializable< '@type': '/cosmwasm.wasm.v1.MsgExecuteContract', sender, contract, - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), funds: funds.toData(), } } @@ -105,7 +116,7 @@ export namespace MsgExecuteContract { value: { sender: AccAddress contract: AccAddress - msg: string + msg: JSON funds: Coins.Amino } } @@ -114,7 +125,7 @@ export namespace MsgExecuteContract { '@type': '/cosmwasm.wasm.v1.MsgExecuteContract' sender: AccAddress contract: AccAddress - msg: string + msg: JSON funds: Coins.Data } diff --git a/src/core/wasm/msgs/MsgInstantiateContract.ts b/src/core/wasm/msgs/MsgInstantiateContract.ts index 5185093..a592023 100644 --- a/src/core/wasm/msgs/MsgInstantiateContract.ts +++ b/src/core/wasm/msgs/MsgInstantiateContract.ts @@ -45,7 +45,7 @@ export class MsgInstantiateContract extends JSONSerializable< admin, parseInt(code_id), label, - msg, + Buffer.from(JSON.stringify(msg)).toString('base64'), Coins.fromAmino(funds) ) } @@ -59,7 +59,7 @@ export class MsgInstantiateContract extends JSONSerializable< admin, code_id: code_id.toFixed(), label, - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), funds: funds.toAmino(), }, } @@ -74,7 +74,7 @@ export class MsgInstantiateContract extends JSONSerializable< admin, parseInt(code_id), label, - msg, + Buffer.from(JSON.stringify(msg)).toString('base64'), Coins.fromData(funds) ) } @@ -87,7 +87,7 @@ export class MsgInstantiateContract extends JSONSerializable< admin, code_id: code_id.toFixed(), label, - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), funds: funds.toData(), } } @@ -139,7 +139,7 @@ export namespace MsgInstantiateContract { admin?: AccAddress code_id: string label?: string - msg: string + msg: JSON funds: Coins.Amino } } @@ -150,7 +150,7 @@ export namespace MsgInstantiateContract { admin?: AccAddress code_id: string label?: string - msg: string + msg: JSON funds: Coins.Data } diff --git a/src/core/wasm/msgs/MsgInstantiateContractV2.ts b/src/core/wasm/msgs/MsgInstantiateContractV2.ts index 71b7129..e2f1573 100644 --- a/src/core/wasm/msgs/MsgInstantiateContractV2.ts +++ b/src/core/wasm/msgs/MsgInstantiateContractV2.ts @@ -49,7 +49,7 @@ export class MsgInstantiateContractV2 extends JSONSerializable< admin, parseInt(code_id), label, - msg, + Buffer.from(JSON.stringify(msg)).toString('base64'), Coins.fromAmino(funds), salt, fix_msg @@ -65,7 +65,7 @@ export class MsgInstantiateContractV2 extends JSONSerializable< admin, code_id: code_id.toFixed(), label, - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), funds: funds.toAmino(), salt, fix_msg, @@ -82,7 +82,7 @@ export class MsgInstantiateContractV2 extends JSONSerializable< admin, parseInt(code_id), label, - msg, + Buffer.from(JSON.stringify(msg)).toString('base64'), Coins.fromData(funds), salt, fix_msg @@ -97,7 +97,7 @@ export class MsgInstantiateContractV2 extends JSONSerializable< admin, code_id: code_id.toFixed(), label, - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), funds: funds.toData(), salt, fix_msg, @@ -155,7 +155,7 @@ export namespace MsgInstantiateContractV2 { admin?: AccAddress code_id: string label?: string - msg: string + msg: JSON funds: Coins.Amino salt: string fix_msg: boolean @@ -168,7 +168,7 @@ export namespace MsgInstantiateContractV2 { admin?: AccAddress code_id: string label?: string - msg: string + msg: JSON funds: Coins.Data salt: string fix_msg: boolean diff --git a/src/core/wasm/msgs/MsgMigrateContract.ts b/src/core/wasm/msgs/MsgMigrateContract.ts index c16ece8..a5d358d 100644 --- a/src/core/wasm/msgs/MsgMigrateContract.ts +++ b/src/core/wasm/msgs/MsgMigrateContract.ts @@ -31,7 +31,12 @@ export class MsgMigrateContract extends JSONSerializable< value: { sender, contract, code_id, msg }, } = data - return new MsgMigrateContract(sender, contract, parseInt(code_id), msg) + return new MsgMigrateContract( + sender, + contract, + parseInt(code_id), + Buffer.from(JSON.stringify(msg)).toString('base64') + ) } public toAmino(): MsgMigrateContract.Amino { @@ -42,14 +47,20 @@ export class MsgMigrateContract extends JSONSerializable< sender, contract, code_id: code_id.toFixed(), - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), }, } } public static fromData(data: MsgMigrateContract.Data): MsgMigrateContract { const { sender, contract, code_id, msg } = data - return new MsgMigrateContract(sender, contract, parseInt(code_id), msg) + + return new MsgMigrateContract( + sender, + contract, + parseInt(code_id), + Buffer.from(JSON.stringify(msg)).toString('base64') + ) } public toData(): MsgMigrateContract.Data { @@ -59,7 +70,7 @@ export class MsgMigrateContract extends JSONSerializable< sender, contract, code_id: code_id.toFixed(), - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), } } @@ -103,7 +114,7 @@ export namespace MsgMigrateContract { sender: AccAddress contract: AccAddress code_id: string - msg: string + msg: JSON } } @@ -112,7 +123,7 @@ export namespace MsgMigrateContract { sender: AccAddress contract: AccAddress code_id: string - msg: string + msg: JSON } export type Proto = MsgMigrateContract_pb diff --git a/src/core/wasm/msgs/MsgStoreAndInstantiateContract.ts b/src/core/wasm/msgs/MsgStoreAndInstantiateContract.ts index c945e27..57c7777 100644 --- a/src/core/wasm/msgs/MsgStoreAndInstantiateContract.ts +++ b/src/core/wasm/msgs/MsgStoreAndInstantiateContract.ts @@ -73,7 +73,7 @@ export class MsgStoreAndInstantiateContract extends JSONSerializable< unpin_code, admin, label, - msg, + Buffer.from(JSON.stringify(msg)).toString('base64'), Coins.fromAmino(funds), source, builder, @@ -105,7 +105,7 @@ export class MsgStoreAndInstantiateContract extends JSONSerializable< unpin_code, admin, label, - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), funds: funds.toAmino(), source, builder, @@ -140,7 +140,7 @@ export class MsgStoreAndInstantiateContract extends JSONSerializable< unpin_code, admin, label, - msg, + Buffer.from(JSON.stringify(msg)).toString('base64'), Coins.fromData(funds), source, builder, @@ -171,7 +171,7 @@ export class MsgStoreAndInstantiateContract extends JSONSerializable< unpin_code, admin, label, - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), funds: funds.toData(), source, builder, @@ -253,7 +253,7 @@ export namespace MsgStoreAndInstantiateContract { unpin_code?: boolean admin?: AccAddress label?: string - msg: string + msg: JSON funds: Coins.Amino source: string builder: string @@ -269,7 +269,7 @@ export namespace MsgStoreAndInstantiateContract { unpin_code?: boolean admin?: AccAddress label?: string - msg: string + msg: JSON funds: Coins.Amino source: string builder: string diff --git a/src/core/wasm/msgs/MsgStoreAndMigrateContract.ts b/src/core/wasm/msgs/MsgStoreAndMigrateContract.ts index 0e75c4a..404f4ee 100644 --- a/src/core/wasm/msgs/MsgStoreAndMigrateContract.ts +++ b/src/core/wasm/msgs/MsgStoreAndMigrateContract.ts @@ -50,7 +50,7 @@ export class MsgStoreAndMigrateContract extends JSONSerializable< ? AccessConfig.fromAmino(instantiate_permission) : undefined, contract, - msg + Buffer.from(JSON.stringify(msg)).toString('base64') ) } @@ -65,7 +65,7 @@ export class MsgStoreAndMigrateContract extends JSONSerializable< wasm_byte_code, instantiate_permission: instantiate_permission?.toAmino(), contract, - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), }, } } @@ -83,7 +83,7 @@ export class MsgStoreAndMigrateContract extends JSONSerializable< ? AccessConfig.fromData(instantiate_permission) : undefined, contract, - msg + Buffer.from(JSON.stringify(msg)).toString('base64') ) } @@ -97,7 +97,7 @@ export class MsgStoreAndMigrateContract extends JSONSerializable< wasm_byte_code, instantiate_permission: instantiate_permission?.toData(), contract, - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), } } @@ -150,7 +150,7 @@ export namespace MsgStoreAndMigrateContract { wasm_byte_code: string instantiate_permission?: AccessConfig.Amino contract: AccAddress - msg: string + msg: JSON } } @@ -160,7 +160,7 @@ export namespace MsgStoreAndMigrateContract { wasm_byte_code: string instantiate_permission?: AccessConfig.Data contract: AccAddress - msg: string + msg: JSON } export type Proto = MsgStoreAndMigrateContract_pb diff --git a/src/core/wasm/msgs/MsgSudoContract.ts b/src/core/wasm/msgs/MsgSudoContract.ts index 0cbb65c..6f3c471 100644 --- a/src/core/wasm/msgs/MsgSudoContract.ts +++ b/src/core/wasm/msgs/MsgSudoContract.ts @@ -29,7 +29,11 @@ export class MsgSudoContract extends JSONSerializable< const { value: { authority, contract, msg }, } = data - return new MsgSudoContract(authority, contract, msg) + return new MsgSudoContract( + authority, + contract, + Buffer.from(JSON.stringify(msg)).toString('base64') + ) } public toAmino(): MsgSudoContract.Amino { @@ -39,14 +43,18 @@ export class MsgSudoContract extends JSONSerializable< value: { authority, contract, - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), }, } } public static fromData(data: MsgSudoContract.Data): MsgSudoContract { const { authority, contract, msg } = data - return new MsgSudoContract(authority, contract, msg) + return new MsgSudoContract( + authority, + contract, + Buffer.from(JSON.stringify(msg)).toString('base64') + ) } public toData(): MsgSudoContract.Data { @@ -55,7 +63,7 @@ export class MsgSudoContract extends JSONSerializable< '@type': '/cosmwasm.wasm.v1.MsgSudoContract', authority, contract, - msg, + msg: JSON.parse(Buffer.from(msg, 'base64').toString()), } } @@ -94,7 +102,7 @@ export namespace MsgSudoContract { value: { authority: AccAddress contract: AccAddress - msg: string + msg: JSON } } @@ -102,7 +110,7 @@ export namespace MsgSudoContract { '@type': '/cosmwasm.wasm.v1.MsgSudoContract' authority: AccAddress contract: AccAddress - msg: string + msg: JSON } export type Proto = MsgSudoContract_pb