From 707cc7c8a5dc314b158ef1fc4ad2f544df47d07a Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Thu, 11 Mar 2021 11:08:36 +0100 Subject: [PATCH] Update x/wasm proto types --- packages/cosmwasm-stargate/package.json | 2 +- .../cosmwasm-stargate/src/aminotypes.spec.ts | 8 +- packages/cosmwasm-stargate/src/aminotypes.ts | 61 ++++++++------ .../src/codec/x/wasm/internal/types/tx.ts | 82 +++++++++++-------- .../src/codec/x/wasm/internal/types/types.ts | 22 ++++- .../src/queries/wasm.spec.ts | 6 +- .../src/signingcosmwasmclient.ts | 4 +- 7 files changed, 118 insertions(+), 67 deletions(-) diff --git a/packages/cosmwasm-stargate/package.json b/packages/cosmwasm-stargate/package.json index 456b074f..d560760b 100644 --- a/packages/cosmwasm-stargate/package.json +++ b/packages/cosmwasm-stargate/package.json @@ -37,7 +37,7 @@ "coverage": "nyc --reporter=text --reporter=lcov yarn test --quiet", "pack-web": "yarn build-or-skip && webpack --mode development --config webpack.web.config.js", "preget-proto": "shx rm -rf proto", - "get-proto": "WASM_REF=v0.14.0 COSMOS_REF=v0.40.0 ./scripts/get-proto.sh", + "get-proto": "WASM_REF=v0.16.0-alpha1 COSMOS_REF=v0.42.0 ./scripts/get-proto.sh", "define-proto": "./scripts/define-proto.sh", "postdefine-proto": "prettier --write \"src/codec/**/*.ts\"" }, diff --git a/packages/cosmwasm-stargate/src/aminotypes.spec.ts b/packages/cosmwasm-stargate/src/aminotypes.spec.ts index ded26a7b..c73bfec7 100644 --- a/packages/cosmwasm-stargate/src/aminotypes.spec.ts +++ b/packages/cosmwasm-stargate/src/aminotypes.spec.ts @@ -58,7 +58,7 @@ describe("AminoTypes", () => { foo: "bar", }), ), - initFunds: coins(1234, "ucosm"), + funds: coins(1234, "ucosm"), admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", }; const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({ @@ -130,7 +130,7 @@ describe("AminoTypes", () => { foo: "bar", }), ), - sentFunds: coins(1234, "ucosm"), + funds: coins(1234, "ucosm"), }; const aminoMsg = new AminoTypes({ additions: cosmWasmTypes }).toAmino({ typeUrl: "/cosmwasm.wasm.v1beta1.MsgExecuteContract", @@ -229,7 +229,7 @@ describe("AminoTypes", () => { foo: "bar", }), ), - initFunds: coins(1234, "ucosm"), + funds: coins(1234, "ucosm"), admin: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", }; expect(msg).toEqual({ @@ -299,7 +299,7 @@ describe("AminoTypes", () => { foo: "bar", }), ), - sentFunds: coins(1234, "ucosm"), + funds: coins(1234, "ucosm"), }; expect(msg).toEqual({ typeUrl: "/cosmwasm.wasm.v1beta1.MsgExecuteContract", diff --git a/packages/cosmwasm-stargate/src/aminotypes.ts b/packages/cosmwasm-stargate/src/aminotypes.ts index 326dffbf..36a9928f 100644 --- a/packages/cosmwasm-stargate/src/aminotypes.ts +++ b/packages/cosmwasm-stargate/src/aminotypes.ts @@ -1,13 +1,12 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { MsgClearAdmin as LaunchpadMsgClearAdmin, - MsgExecuteContract as LaunchpadMsgExecuteContract, - MsgInstantiateContract as LaunchpadMsgInstantiateContract, MsgMigrateContract as LaunchpadMsgMigrateContract, MsgStoreCode as LaunchpadMsgStoreCode, MsgUpdateAdmin as LaunchpadMsgUpdateAdmin, } from "@cosmjs/cosmwasm-launchpad"; import { fromBase64, fromUtf8, toBase64, toUtf8 } from "@cosmjs/encoding"; +import { Coin } from "@cosmjs/launchpad"; import { AminoConverter, coinFromProto } from "@cosmjs/stargate"; import { assertDefinedAndNotNull } from "@cosmjs/utils"; import Long from "long"; @@ -21,6 +20,30 @@ import { MsgUpdateAdmin, } from "./codec/x/wasm/internal/types/tx"; +interface MsgExecuteContractValueAmino { + /** Bech32 account address */ + readonly sender: string; + /** Bech32 account address */ + readonly contract: string; + /** Handle message as JavaScript object */ + readonly msg: any; + readonly funds: readonly Coin[]; +} + +interface MsgInstantiateContractValueAmino { + /** Bech32 account address */ + readonly sender: string; + /** ID of the Wasm code that was uploaded before */ + readonly code_id: string; + /** Human-readable label for this contract */ + readonly label: string; + /** Init message as JavaScript object */ + readonly init_msg: any; + readonly funds: readonly Coin[]; + /** Bech32-encoded admin address */ + readonly admin?: string; +} + export const cosmWasmTypes: Record = { "/cosmwasm.wasm.v1beta1.MsgStoreCode": { aminoType: "wasm/MsgStoreCode", @@ -56,20 +79,20 @@ export const cosmWasmTypes: Record = { codeId, label, initMsg, - initFunds, + funds, admin, - }: MsgInstantiateContract): LaunchpadMsgInstantiateContract["value"] => { + }: MsgInstantiateContract): MsgInstantiateContractValueAmino => { assertDefinedAndNotNull(sender, "missing sender"); assertDefinedAndNotNull(codeId, "missing codeId"); assertDefinedAndNotNull(label, "missing label"); assertDefinedAndNotNull(initMsg, "missing initMsg"); - assertDefinedAndNotNull(initFunds, "missing initFunds"); + assertDefinedAndNotNull(funds, "missing funds"); return { sender: sender, code_id: codeId.toString(), label: label, init_msg: JSON.parse(fromUtf8(initMsg)), - init_funds: initFunds.map(coinFromProto), + funds: funds.map(coinFromProto), admin: admin ?? undefined, }; }, @@ -78,14 +101,14 @@ export const cosmWasmTypes: Record = { code_id, label, init_msg, - init_funds, + funds, admin, - }: LaunchpadMsgInstantiateContract["value"]): MsgInstantiateContract => ({ + }: MsgInstantiateContractValueAmino): MsgInstantiateContract => ({ sender: sender, codeId: Long.fromString(code_id), label: label, initMsg: toUtf8(JSON.stringify(init_msg)), - initFunds: [...init_funds], + funds: [...funds], admin: admin ?? "", }), }, @@ -124,33 +147,23 @@ export const cosmWasmTypes: Record = { }, "/cosmwasm.wasm.v1beta1.MsgExecuteContract": { aminoType: "wasm/MsgExecuteContract", - toAmino: ({ - sender, - contract, - msg, - sentFunds, - }: MsgExecuteContract): LaunchpadMsgExecuteContract["value"] => { + toAmino: ({ sender, contract, msg, funds }: MsgExecuteContract): MsgExecuteContractValueAmino => { assertDefinedAndNotNull(sender, "missing sender"); assertDefinedAndNotNull(contract, "missing contract"); assertDefinedAndNotNull(msg, "missing msg"); - assertDefinedAndNotNull(sentFunds, "missing sentFunds"); + assertDefinedAndNotNull(funds, "missing funds"); return { sender: sender, contract: contract, msg: JSON.parse(fromUtf8(msg)), - sent_funds: sentFunds.map(coinFromProto), + funds: funds.map(coinFromProto), }; }, - fromAmino: ({ - sender, - contract, - msg, - sent_funds, - }: LaunchpadMsgExecuteContract["value"]): MsgExecuteContract => ({ + fromAmino: ({ sender, contract, msg, funds }: MsgExecuteContractValueAmino): MsgExecuteContract => ({ sender: sender, contract: contract, msg: toUtf8(JSON.stringify(msg)), - sentFunds: [...sent_funds], + funds: [...funds], }), }, "/cosmwasm.wasm.v1beta1.MsgMigrateContract": { diff --git a/packages/cosmwasm-stargate/src/codec/x/wasm/internal/types/tx.ts b/packages/cosmwasm-stargate/src/codec/x/wasm/internal/types/tx.ts index 63e0a243..5eb69bbf 100644 --- a/packages/cosmwasm-stargate/src/codec/x/wasm/internal/types/tx.ts +++ b/packages/cosmwasm-stargate/src/codec/x/wasm/internal/types/tx.ts @@ -38,14 +38,16 @@ export interface MsgInstantiateContract { label: string; /** InitMsg json encoded message to be passed to the contract on instantiation */ initMsg: Uint8Array; - /** InitFunds coins that are transferred to the contract on instantiation */ - initFunds: Coin[]; + /** Funds coins that are transferred to the contract on instantiation */ + funds: Coin[]; } /** MsgInstantiateContractResponse return instantiation result data */ export interface MsgInstantiateContractResponse { /** Address is the bech32 address of the new contract instance. */ address: string; + /** Data contains base64-encoded bytes to returned from the contract */ + data: Uint8Array; } /** MsgExecuteContract submits the given message data to a smart contract */ @@ -56,8 +58,8 @@ export interface MsgExecuteContract { contract: string; /** Msg json encoded message to be passed to the contract */ msg: Uint8Array; - /** SentFunds coins that are transferred to the contract on execution */ - sentFunds: Coin[]; + /** Funds coins that are transferred to the contract on execution */ + funds: Coin[]; } /** MsgExecuteContractResponse returns execution result data. */ @@ -312,7 +314,7 @@ export const MsgInstantiateContract = { if (message.initMsg.length !== 0) { writer.uint32(42).bytes(message.initMsg); } - for (const v of message.initFunds) { + for (const v of message.funds) { Coin.encode(v!, writer.uint32(50).fork()).ldelim(); } return writer; @@ -322,7 +324,7 @@ export const MsgInstantiateContract = { const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; let end = length === undefined ? reader.len : reader.pos + length; const message = { ...baseMsgInstantiateContract } as MsgInstantiateContract; - message.initFunds = []; + message.funds = []; while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -342,7 +344,7 @@ export const MsgInstantiateContract = { message.initMsg = reader.bytes(); break; case 6: - message.initFunds.push(Coin.decode(reader, reader.uint32())); + message.funds.push(Coin.decode(reader, reader.uint32())); break; default: reader.skipType(tag & 7); @@ -354,7 +356,7 @@ export const MsgInstantiateContract = { fromJSON(object: any): MsgInstantiateContract { const message = { ...baseMsgInstantiateContract } as MsgInstantiateContract; - message.initFunds = []; + message.funds = []; if (object.sender !== undefined && object.sender !== null) { message.sender = String(object.sender); } else { @@ -378,9 +380,9 @@ export const MsgInstantiateContract = { if (object.initMsg !== undefined && object.initMsg !== null) { message.initMsg = bytesFromBase64(object.initMsg); } - if (object.initFunds !== undefined && object.initFunds !== null) { - for (const e of object.initFunds) { - message.initFunds.push(Coin.fromJSON(e)); + if (object.funds !== undefined && object.funds !== null) { + for (const e of object.funds) { + message.funds.push(Coin.fromJSON(e)); } } return message; @@ -394,17 +396,17 @@ export const MsgInstantiateContract = { message.label !== undefined && (obj.label = message.label); message.initMsg !== undefined && (obj.initMsg = base64FromBytes(message.initMsg !== undefined ? message.initMsg : new Uint8Array())); - if (message.initFunds) { - obj.initFunds = message.initFunds.map((e) => (e ? Coin.toJSON(e) : undefined)); + if (message.funds) { + obj.funds = message.funds.map((e) => (e ? Coin.toJSON(e) : undefined)); } else { - obj.initFunds = []; + obj.funds = []; } return obj; }, fromPartial(object: DeepPartial): MsgInstantiateContract { const message = { ...baseMsgInstantiateContract } as MsgInstantiateContract; - message.initFunds = []; + message.funds = []; if (object.sender !== undefined && object.sender !== null) { message.sender = object.sender; } else { @@ -430,9 +432,9 @@ export const MsgInstantiateContract = { } else { message.initMsg = new Uint8Array(); } - if (object.initFunds !== undefined && object.initFunds !== null) { - for (const e of object.initFunds) { - message.initFunds.push(Coin.fromPartial(e)); + if (object.funds !== undefined && object.funds !== null) { + for (const e of object.funds) { + message.funds.push(Coin.fromPartial(e)); } } return message; @@ -446,6 +448,9 @@ export const MsgInstantiateContractResponse = { if (message.address !== "") { writer.uint32(10).string(message.address); } + if (message.data.length !== 0) { + writer.uint32(18).bytes(message.data); + } return writer; }, @@ -459,6 +464,9 @@ export const MsgInstantiateContractResponse = { case 1: message.address = reader.string(); break; + case 2: + message.data = reader.bytes(); + break; default: reader.skipType(tag & 7); break; @@ -474,12 +482,17 @@ export const MsgInstantiateContractResponse = { } else { message.address = ""; } + if (object.data !== undefined && object.data !== null) { + message.data = bytesFromBase64(object.data); + } return message; }, toJSON(message: MsgInstantiateContractResponse): unknown { const obj: any = {}; message.address !== undefined && (obj.address = message.address); + message.data !== undefined && + (obj.data = base64FromBytes(message.data !== undefined ? message.data : new Uint8Array())); return obj; }, @@ -490,6 +503,11 @@ export const MsgInstantiateContractResponse = { } else { message.address = ""; } + if (object.data !== undefined && object.data !== null) { + message.data = object.data; + } else { + message.data = new Uint8Array(); + } return message; }, }; @@ -507,7 +525,7 @@ export const MsgExecuteContract = { if (message.msg.length !== 0) { writer.uint32(26).bytes(message.msg); } - for (const v of message.sentFunds) { + for (const v of message.funds) { Coin.encode(v!, writer.uint32(42).fork()).ldelim(); } return writer; @@ -517,7 +535,7 @@ export const MsgExecuteContract = { const reader = input instanceof Uint8Array ? new _m0.Reader(input) : input; let end = length === undefined ? reader.len : reader.pos + length; const message = { ...baseMsgExecuteContract } as MsgExecuteContract; - message.sentFunds = []; + message.funds = []; while (reader.pos < end) { const tag = reader.uint32(); switch (tag >>> 3) { @@ -531,7 +549,7 @@ export const MsgExecuteContract = { message.msg = reader.bytes(); break; case 5: - message.sentFunds.push(Coin.decode(reader, reader.uint32())); + message.funds.push(Coin.decode(reader, reader.uint32())); break; default: reader.skipType(tag & 7); @@ -543,7 +561,7 @@ export const MsgExecuteContract = { fromJSON(object: any): MsgExecuteContract { const message = { ...baseMsgExecuteContract } as MsgExecuteContract; - message.sentFunds = []; + message.funds = []; if (object.sender !== undefined && object.sender !== null) { message.sender = String(object.sender); } else { @@ -557,9 +575,9 @@ export const MsgExecuteContract = { if (object.msg !== undefined && object.msg !== null) { message.msg = bytesFromBase64(object.msg); } - if (object.sentFunds !== undefined && object.sentFunds !== null) { - for (const e of object.sentFunds) { - message.sentFunds.push(Coin.fromJSON(e)); + if (object.funds !== undefined && object.funds !== null) { + for (const e of object.funds) { + message.funds.push(Coin.fromJSON(e)); } } return message; @@ -571,17 +589,17 @@ export const MsgExecuteContract = { message.contract !== undefined && (obj.contract = message.contract); message.msg !== undefined && (obj.msg = base64FromBytes(message.msg !== undefined ? message.msg : new Uint8Array())); - if (message.sentFunds) { - obj.sentFunds = message.sentFunds.map((e) => (e ? Coin.toJSON(e) : undefined)); + if (message.funds) { + obj.funds = message.funds.map((e) => (e ? Coin.toJSON(e) : undefined)); } else { - obj.sentFunds = []; + obj.funds = []; } return obj; }, fromPartial(object: DeepPartial): MsgExecuteContract { const message = { ...baseMsgExecuteContract } as MsgExecuteContract; - message.sentFunds = []; + message.funds = []; if (object.sender !== undefined && object.sender !== null) { message.sender = object.sender; } else { @@ -597,9 +615,9 @@ export const MsgExecuteContract = { } else { message.msg = new Uint8Array(); } - if (object.sentFunds !== undefined && object.sentFunds !== null) { - for (const e of object.sentFunds) { - message.sentFunds.push(Coin.fromPartial(e)); + if (object.funds !== undefined && object.funds !== null) { + for (const e of object.funds) { + message.funds.push(Coin.fromPartial(e)); } } return message; diff --git a/packages/cosmwasm-stargate/src/codec/x/wasm/internal/types/types.ts b/packages/cosmwasm-stargate/src/codec/x/wasm/internal/types/types.ts index e9e3b7c6..1e0f3bbb 100644 --- a/packages/cosmwasm-stargate/src/codec/x/wasm/internal/types/types.ts +++ b/packages/cosmwasm-stargate/src/codec/x/wasm/internal/types/types.ts @@ -122,7 +122,7 @@ export interface Params { /** CodeInfo is data for the uploaded contract WASM code */ export interface CodeInfo { - /** CodeHash is the unique CodeID */ + /** CodeHash is the unique identifier created by wasmvm */ codeHash: Uint8Array; /** Creator address who initially stored the code */ creator: string; @@ -149,6 +149,7 @@ export interface ContractInfo { * This data should kept internal and not be exposed via query results. Just use for sorting */ created?: AbsoluteTxPosition; + ibcPortId: string; } /** ContractCodeHistoryEntry metadata to a contract. */ @@ -523,7 +524,7 @@ export const CodeInfo = { }, }; -const baseContractInfo: object = { codeId: Long.UZERO, creator: "", admin: "", label: "" }; +const baseContractInfo: object = { codeId: Long.UZERO, creator: "", admin: "", label: "", ibcPortId: "" }; export const ContractInfo = { encode(message: ContractInfo, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { @@ -542,6 +543,9 @@ export const ContractInfo = { if (message.created !== undefined) { AbsoluteTxPosition.encode(message.created, writer.uint32(42).fork()).ldelim(); } + if (message.ibcPortId !== "") { + writer.uint32(50).string(message.ibcPortId); + } return writer; }, @@ -567,6 +571,9 @@ export const ContractInfo = { case 5: message.created = AbsoluteTxPosition.decode(reader, reader.uint32()); break; + case 6: + message.ibcPortId = reader.string(); + break; default: reader.skipType(tag & 7); break; @@ -602,6 +609,11 @@ export const ContractInfo = { } else { message.created = undefined; } + if (object.ibcPortId !== undefined && object.ibcPortId !== null) { + message.ibcPortId = String(object.ibcPortId); + } else { + message.ibcPortId = ""; + } return message; }, @@ -613,6 +625,7 @@ export const ContractInfo = { message.label !== undefined && (obj.label = message.label); message.created !== undefined && (obj.created = message.created ? AbsoluteTxPosition.toJSON(message.created) : undefined); + message.ibcPortId !== undefined && (obj.ibcPortId = message.ibcPortId); return obj; }, @@ -643,6 +656,11 @@ export const ContractInfo = { } else { message.created = undefined; } + if (object.ibcPortId !== undefined && object.ibcPortId !== null) { + message.ibcPortId = object.ibcPortId; + } else { + message.ibcPortId = ""; + } return message; }, }; diff --git a/packages/cosmwasm-stargate/src/queries/wasm.spec.ts b/packages/cosmwasm-stargate/src/queries/wasm.spec.ts index 407b5926..829d9cae 100644 --- a/packages/cosmwasm-stargate/src/queries/wasm.spec.ts +++ b/packages/cosmwasm-stargate/src/queries/wasm.spec.ts @@ -84,7 +84,7 @@ async function instantiateContract( beneficiary: beneficiaryAddress, }), ), - initFunds: transferAmount ? [...transferAmount] : [], + funds: transferAmount ? [...transferAmount] : [], }), }; const fee: StdFee = { @@ -109,7 +109,7 @@ async function executeContract( sender: alice.address0, contract: contractAddress, msg: toAscii(JSON.stringify(msg)), - sentFunds: [], + funds: [], }), }; const fee: StdFee = { @@ -219,6 +219,7 @@ describe("WasmExtension", () => { creator: alice.address0, label: "my escrow", admin: "", + ibcPortId: "", }); const { contractInfo } = await client.unverified.wasm.getContractInfo(myAddress); @@ -228,6 +229,7 @@ describe("WasmExtension", () => { creator: alice.address0, label: "my escrow", admin: "", + ibcPortId: "", }); expect(contractInfo.admin).toEqual(""); }); diff --git a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts index cf81a5d9..b98355aa 100644 --- a/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts +++ b/packages/cosmwasm-stargate/src/signingcosmwasmclient.ts @@ -191,7 +191,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { codeId: Long.fromString(new Uint53(codeId).toString()), label: label, initMsg: toUtf8(JSON.stringify(initMsg)), - initFunds: [...(options.transferAmount || [])], + funds: [...(options.transferAmount || [])], admin: options.admin, }), }; @@ -293,7 +293,7 @@ export class SigningCosmWasmClient extends CosmWasmClient { sender: senderAddress, contract: contractAddress, msg: toUtf8(JSON.stringify(handleMsg)), - sentFunds: [...(transferAmount || [])], + funds: [...(transferAmount || [])], }), }; const result = await this.signAndBroadcast(senderAddress, [executeMsg], this.fees.exec, memo);