mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
cosmwasm-stargate: Add EncodeObject types/helpers
This commit is contained in:
parent
04f88ac05c
commit
b6ddf0fc77
@ -6,6 +6,7 @@ import {
|
||||
makeAuthInfoBytes,
|
||||
makeSignDoc,
|
||||
Registry,
|
||||
TxBodyEncodeObject,
|
||||
} from "@cosmjs/proto-signing";
|
||||
import {
|
||||
BroadcastTxResponse,
|
||||
@ -13,6 +14,7 @@ import {
|
||||
coins,
|
||||
isBroadcastTxFailure,
|
||||
isBroadcastTxSuccess,
|
||||
isMsgSendEncodeObject,
|
||||
} from "@cosmjs/stargate";
|
||||
import { Tx, TxRaw } from "@cosmjs/stargate/build/codec/cosmos/tx/v1beta1/tx";
|
||||
import { assert, sleep } from "@cosmjs/utils";
|
||||
@ -51,7 +53,7 @@ async function sendTokens(
|
||||
type: "tendermint/PubKeySecp256k1",
|
||||
value: toBase64(pubkeyBytes),
|
||||
});
|
||||
const txBodyFields = {
|
||||
const txBodyFields: TxBodyEncodeObject = {
|
||||
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
||||
value: {
|
||||
messages: [
|
||||
@ -231,9 +233,9 @@ describe("CosmWasmClient.getTx and .searchTx", () => {
|
||||
// Check basic structure of all results
|
||||
for (const result of results) {
|
||||
const tx = Tx.decode(result.tx);
|
||||
const filteredMsgs = tx.body!.messages.filter(({ typeUrl: typeUrl, value }) => {
|
||||
if (typeUrl !== "/cosmos.bank.v1beta1.MsgSend") return false;
|
||||
const decoded = registry.decode({ typeUrl: typeUrl, value: value });
|
||||
const filteredMsgs = tx.body!.messages.filter((msg) => {
|
||||
if (!isMsgSendEncodeObject(msg)) return false;
|
||||
const decoded = registry.decode(msg);
|
||||
return decoded.fromAddress === sendSuccessful?.sender;
|
||||
});
|
||||
expect(filteredMsgs.length).toBeGreaterThanOrEqual(1);
|
||||
@ -259,9 +261,9 @@ describe("CosmWasmClient.getTx and .searchTx", () => {
|
||||
// Check basic structure of all results
|
||||
for (const result of results) {
|
||||
const tx = Tx.decode(result.tx);
|
||||
const filteredMsgs = tx.body!.messages.filter(({ typeUrl: typeUrl, value }) => {
|
||||
if (typeUrl !== "/cosmos.bank.v1beta1.MsgSend") return false;
|
||||
const decoded = registry.decode({ typeUrl: typeUrl, value: value });
|
||||
const filteredMsgs = tx.body!.messages.filter((msg) => {
|
||||
if (!isMsgSendEncodeObject(msg)) return false;
|
||||
const decoded = registry.decode(msg);
|
||||
return decoded.toAddress === sendSuccessful?.recipient;
|
||||
});
|
||||
expect(filteredMsgs.length).toBeGreaterThanOrEqual(1);
|
||||
@ -345,9 +347,9 @@ describe("CosmWasmClient.getTx and .searchTx", () => {
|
||||
// Check basic structure of all results
|
||||
for (const result of results) {
|
||||
const tx = Tx.decode(result.tx);
|
||||
const { typeUrl, value } = fromOneElementArray(tx.body!.messages);
|
||||
expect(typeUrl).toEqual("/cosmos.bank.v1beta1.MsgSend");
|
||||
const decoded = registry.decode({ typeUrl: typeUrl, value: value });
|
||||
const msg = fromOneElementArray(tx.body!.messages);
|
||||
expect(msg.typeUrl).toEqual("/cosmos.bank.v1beta1.MsgSend");
|
||||
const decoded = registry.decode(msg);
|
||||
expect(decoded.toAddress).toEqual(sendSuccessful.recipient);
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,9 @@ import {
|
||||
makeAuthInfoBytes,
|
||||
makeSignDoc,
|
||||
Registry,
|
||||
TxBodyEncodeObject,
|
||||
} from "@cosmjs/proto-signing";
|
||||
import { assertIsBroadcastTxSuccess, coins, logs, StdFee } from "@cosmjs/stargate";
|
||||
import { assertIsBroadcastTxSuccess, coins, logs, MsgSendEncodeObject, StdFee } from "@cosmjs/stargate";
|
||||
import { TxRaw } from "@cosmjs/stargate/build/codec/cosmos/tx/v1beta1/tx";
|
||||
import { assert, sleep } from "@cosmjs/utils";
|
||||
import { ReadonlyDate } from "readonly-date";
|
||||
@ -173,7 +174,7 @@ describe("CosmWasmClient", () => {
|
||||
const registry = new Registry();
|
||||
|
||||
const memo = "My first contract on chain";
|
||||
const sendMsg = {
|
||||
const sendMsg: MsgSendEncodeObject = {
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: {
|
||||
fromAddress: alice.address0,
|
||||
@ -191,14 +192,14 @@ describe("CosmWasmClient", () => {
|
||||
assert(sequenceResponse);
|
||||
const { accountNumber, sequence } = sequenceResponse;
|
||||
const pubkeyAny = encodePubkey(alice.pubkey0);
|
||||
const txBody = {
|
||||
messages: [sendMsg],
|
||||
memo: memo,
|
||||
};
|
||||
const txBodyBytes = registry.encode({
|
||||
const txBody: TxBodyEncodeObject = {
|
||||
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
||||
value: txBody,
|
||||
});
|
||||
value: {
|
||||
messages: [sendMsg],
|
||||
memo: memo,
|
||||
},
|
||||
};
|
||||
const txBodyBytes = registry.encode(txBody);
|
||||
const gasLimit = Int53.fromString(fee.gas).toNumber();
|
||||
const authInfoBytes = makeAuthInfoBytes([pubkeyAny], fee.amount, gasLimit, sequence);
|
||||
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
|
||||
|
83
packages/cosmwasm-stargate/src/encodeobjects.ts
Normal file
83
packages/cosmwasm-stargate/src/encodeobjects.ts
Normal file
@ -0,0 +1,83 @@
|
||||
import { EncodeObject } from "@cosmjs/proto-signing";
|
||||
|
||||
import {
|
||||
MsgClearAdmin,
|
||||
MsgExecuteContract,
|
||||
MsgInstantiateContract,
|
||||
MsgMigrateContract,
|
||||
MsgStoreCode,
|
||||
MsgUpdateAdmin,
|
||||
} from "./codec/x/wasm/internal/types/tx";
|
||||
|
||||
export interface MsgStoreCodeEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1beta1.MsgStoreCode";
|
||||
readonly value: Partial<MsgStoreCode>;
|
||||
}
|
||||
|
||||
export function isMsgStoreCodeEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgStoreCodeEncodeObject {
|
||||
return (encodeObject as MsgStoreCodeEncodeObject).typeUrl === "/cosmwasm.wasm.v1beta1.MsgStoreCode";
|
||||
}
|
||||
|
||||
export interface MsgInstantiateContractEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1beta1.MsgInstantiateContract";
|
||||
readonly value: Partial<MsgInstantiateContract>;
|
||||
}
|
||||
|
||||
export function isMsgInstantiateContractEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgInstantiateContractEncodeObject {
|
||||
return (
|
||||
(encodeObject as MsgInstantiateContractEncodeObject).typeUrl ===
|
||||
"/cosmwasm.wasm.v1beta1.MsgInstantiateContract"
|
||||
);
|
||||
}
|
||||
|
||||
export interface MsgUpdateAdminEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1beta1.MsgUpdateAdmin";
|
||||
readonly value: Partial<MsgUpdateAdmin>;
|
||||
}
|
||||
|
||||
export function isMsgUpdateAdminEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgUpdateAdminEncodeObject {
|
||||
return (encodeObject as MsgUpdateAdminEncodeObject).typeUrl === "/cosmwasm.wasm.v1beta1.MsgUpdateAdmin";
|
||||
}
|
||||
|
||||
export interface MsgClearAdminEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1beta1.MsgClearAdmin";
|
||||
readonly value: Partial<MsgClearAdmin>;
|
||||
}
|
||||
|
||||
export function isMsgClearAdminEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgClearAdminEncodeObject {
|
||||
return (encodeObject as MsgClearAdminEncodeObject).typeUrl === "/cosmwasm.wasm.v1beta1.MsgClearAdmin";
|
||||
}
|
||||
|
||||
export interface MsgMigrateContractEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1beta1.MsgMigrateContract";
|
||||
readonly value: Partial<MsgMigrateContract>;
|
||||
}
|
||||
|
||||
export function isMsgMigrateEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgMigrateContractEncodeObject {
|
||||
return (
|
||||
(encodeObject as MsgMigrateContractEncodeObject).typeUrl === "/cosmwasm.wasm.v1beta1.MsgMigrateContract"
|
||||
);
|
||||
}
|
||||
|
||||
export interface MsgExecuteContractEncodeObject extends EncodeObject {
|
||||
readonly typeUrl: "/cosmwasm.wasm.v1beta1.MsgExecuteContract";
|
||||
readonly value: Partial<MsgExecuteContract>;
|
||||
}
|
||||
|
||||
export function isMsgExecuteEncodeObject(
|
||||
encodeObject: EncodeObject,
|
||||
): encodeObject is MsgExecuteContractEncodeObject {
|
||||
return (
|
||||
(encodeObject as MsgExecuteContractEncodeObject).typeUrl === "/cosmwasm.wasm.v1beta1.MsgExecuteContract"
|
||||
);
|
||||
}
|
@ -1,5 +1,19 @@
|
||||
export { cosmWasmTypes } from "./aminotypes";
|
||||
export { CosmWasmClient } from "./cosmwasmclient";
|
||||
export {
|
||||
isMsgClearAdminEncodeObject,
|
||||
isMsgExecuteEncodeObject,
|
||||
isMsgInstantiateContractEncodeObject,
|
||||
isMsgMigrateEncodeObject,
|
||||
isMsgStoreCodeEncodeObject,
|
||||
isMsgUpdateAdminEncodeObject,
|
||||
MsgClearAdminEncodeObject,
|
||||
MsgExecuteContractEncodeObject,
|
||||
MsgInstantiateContractEncodeObject,
|
||||
MsgMigrateContractEncodeObject,
|
||||
MsgStoreCodeEncodeObject,
|
||||
MsgUpdateAdminEncodeObject,
|
||||
} from "./encodeobjects";
|
||||
export {
|
||||
defaultGasLimits,
|
||||
SigningCosmWasmClient,
|
||||
|
@ -17,6 +17,11 @@ import Long from "long";
|
||||
|
||||
import { MsgExecuteContract, MsgInstantiateContract, MsgStoreCode } from "../codec/x/wasm/internal/types/tx";
|
||||
import { ContractCodeHistoryOperationType } from "../codec/x/wasm/internal/types/types";
|
||||
import {
|
||||
MsgExecuteContractEncodeObject,
|
||||
MsgInstantiateContractEncodeObject,
|
||||
MsgStoreCodeEncodeObject,
|
||||
} from "../encodeobjects";
|
||||
import { SigningCosmWasmClient } from "../signingcosmwasmclient";
|
||||
import {
|
||||
alice,
|
||||
@ -42,7 +47,7 @@ async function uploadContract(
|
||||
contract: ContractUploadInstructions,
|
||||
): Promise<BroadcastTxResponse> {
|
||||
const memo = "My first contract on chain";
|
||||
const theMsg = {
|
||||
const theMsg: MsgStoreCodeEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1beta1.MsgStoreCode",
|
||||
value: MsgStoreCode.fromPartial({
|
||||
sender: alice.address0,
|
||||
@ -67,7 +72,7 @@ async function instantiateContract(
|
||||
transferAmount?: readonly Coin[],
|
||||
): Promise<BroadcastTxResponse> {
|
||||
const memo = "Create an escrow instance";
|
||||
const theMsg = {
|
||||
const theMsg: MsgInstantiateContractEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1beta1.MsgInstantiateContract",
|
||||
value: MsgInstantiateContract.fromPartial({
|
||||
sender: alice.address0,
|
||||
@ -98,7 +103,7 @@ async function executeContract(
|
||||
msg: Record<string, unknown>,
|
||||
): Promise<BroadcastTxResponse> {
|
||||
const memo = "Time for action";
|
||||
const theMsg = {
|
||||
const theMsg: MsgExecuteContractEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1beta1.MsgExecuteContract",
|
||||
value: MsgExecuteContract.fromPartial({
|
||||
sender: alice.address0,
|
||||
|
@ -11,6 +11,8 @@ import {
|
||||
coin,
|
||||
coins,
|
||||
GasPrice,
|
||||
MsgDelegateEncodeObject,
|
||||
MsgSendEncodeObject,
|
||||
} from "@cosmjs/stargate";
|
||||
import { DeepPartial, MsgSend } from "@cosmjs/stargate/build/codec/cosmos/bank/v1beta1/tx";
|
||||
import { Coin } from "@cosmjs/stargate/build/codec/cosmos/base/v1beta1/coin";
|
||||
@ -22,6 +24,7 @@ import pako from "pako";
|
||||
import protobuf from "protobufjs/minimal";
|
||||
|
||||
import { MsgStoreCode } from "./codec/x/wasm/internal/types/tx";
|
||||
import { MsgStoreCodeEncodeObject } from "./encodeobjects";
|
||||
import { PrivateSigningCosmWasmClient, SigningCosmWasmClient } from "./signingcosmwasmclient";
|
||||
import {
|
||||
alice,
|
||||
@ -557,7 +560,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
validatorAddress: validator.validatorAddress,
|
||||
amount: coin(1234, "ustake"),
|
||||
});
|
||||
const msgAny = {
|
||||
const msgAny: MsgDelegateEncodeObject = {
|
||||
typeUrl: msgDelegateTypeUrl,
|
||||
value: msg,
|
||||
};
|
||||
@ -582,7 +585,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
validatorAddress: validator.validatorAddress,
|
||||
amount: coin(1234, "ustake"),
|
||||
});
|
||||
const msgAny = {
|
||||
const msgAny: MsgDelegateEncodeObject = {
|
||||
typeUrl: msgDelegateTypeUrl,
|
||||
value: msg,
|
||||
};
|
||||
@ -618,7 +621,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
toAddress: makeRandomAddress(),
|
||||
amount: coins(1234, "ucosm"),
|
||||
};
|
||||
const msgAny = {
|
||||
const msgAny: MsgSendEncodeObject = {
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: msgSend,
|
||||
};
|
||||
@ -642,7 +645,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
validatorAddress: validator.validatorAddress,
|
||||
amount: coin(1234, "ustake"),
|
||||
};
|
||||
const msgAny = {
|
||||
const msgAny: MsgDelegateEncodeObject = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
||||
value: msgDelegate,
|
||||
};
|
||||
@ -669,7 +672,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
builder: builder ?? "",
|
||||
instantiatePermission: undefined,
|
||||
};
|
||||
const msgAny = {
|
||||
const msgAny: MsgStoreCodeEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1beta1.MsgStoreCode",
|
||||
value: msgStoreCode,
|
||||
};
|
||||
@ -811,7 +814,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
validatorAddress: validator.validatorAddress,
|
||||
amount: coin(1234, "ustake"),
|
||||
};
|
||||
const msgAny = {
|
||||
const msgAny: MsgDelegateEncodeObject = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
||||
value: msg,
|
||||
};
|
||||
@ -849,7 +852,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
validatorAddress: validator.validatorAddress,
|
||||
amount: coin(1234, "ustake"),
|
||||
});
|
||||
const msgAny = {
|
||||
const msgAny: MsgDelegateEncodeObject = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
||||
value: msg,
|
||||
};
|
||||
@ -876,7 +879,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
validatorAddress: validator.validatorAddress,
|
||||
amount: coin(1234, "ustake"),
|
||||
});
|
||||
const msgAny = {
|
||||
const msgAny: MsgDelegateEncodeObject = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
||||
value: msg,
|
||||
};
|
||||
@ -912,7 +915,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
toAddress: makeRandomAddress(),
|
||||
amount: coins(1234, "ucosm"),
|
||||
};
|
||||
const msgAny = {
|
||||
const msgAny: MsgSendEncodeObject = {
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: msgSend,
|
||||
};
|
||||
@ -939,7 +942,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
validatorAddress: validator.validatorAddress,
|
||||
amount: coin(1234, "ustake"),
|
||||
};
|
||||
const msgAny = {
|
||||
const msgAny: MsgDelegateEncodeObject = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
||||
value: msgDelegate,
|
||||
};
|
||||
@ -1085,7 +1088,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
validatorAddress: validator.validatorAddress,
|
||||
amount: coin(1234, "ustake"),
|
||||
};
|
||||
const msgAny = {
|
||||
const msgAny: MsgDelegateEncodeObject = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
||||
value: msg,
|
||||
};
|
||||
|
@ -21,6 +21,7 @@ import {
|
||||
makeSignDoc,
|
||||
OfflineSigner,
|
||||
Registry,
|
||||
TxBodyEncodeObject,
|
||||
} from "@cosmjs/proto-signing";
|
||||
import {
|
||||
AminoTypes,
|
||||
@ -36,6 +37,10 @@ import {
|
||||
GasPrice,
|
||||
isBroadcastTxFailure,
|
||||
logs,
|
||||
MsgDelegateEncodeObject,
|
||||
MsgSendEncodeObject,
|
||||
MsgUndelegateEncodeObject,
|
||||
MsgWithdrawDelegatorRewardEncodeObject,
|
||||
SignerData,
|
||||
StdFee,
|
||||
} from "@cosmjs/stargate";
|
||||
@ -58,6 +63,14 @@ import {
|
||||
MsgUpdateAdmin,
|
||||
} from "./codec/x/wasm/internal/types/tx";
|
||||
import { CosmWasmClient } from "./cosmwasmclient";
|
||||
import {
|
||||
MsgClearAdminEncodeObject,
|
||||
MsgExecuteContractEncodeObject,
|
||||
MsgInstantiateContractEncodeObject,
|
||||
MsgMigrateContractEncodeObject,
|
||||
MsgStoreCodeEncodeObject,
|
||||
MsgUpdateAdminEncodeObject,
|
||||
} from "./encodeobjects";
|
||||
|
||||
/**
|
||||
* These fees are used by the higher level methods of SigningCosmWasmClient
|
||||
@ -179,7 +192,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
const source = meta.source || "";
|
||||
const builder = prepareBuilder(meta.builder);
|
||||
const compressed = pako.gzip(wasmCode, { level: 9 });
|
||||
const storeCodeMsg = {
|
||||
const storeCodeMsg: MsgStoreCodeEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1beta1.MsgStoreCode",
|
||||
value: MsgStoreCode.fromPartial({
|
||||
sender: senderAddress,
|
||||
@ -213,7 +226,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
label: string,
|
||||
options: InstantiateOptions = {},
|
||||
): Promise<InstantiateResult> {
|
||||
const instantiateMsg = {
|
||||
const instantiateContractMsg: MsgInstantiateContractEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1beta1.MsgInstantiateContract",
|
||||
value: MsgInstantiateContract.fromPartial({
|
||||
sender: senderAddress,
|
||||
@ -224,7 +237,12 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
admin: options.admin,
|
||||
}),
|
||||
};
|
||||
const result = await this.signAndBroadcast(senderAddress, [instantiateMsg], this.fees.init, options.memo);
|
||||
const result = await this.signAndBroadcast(
|
||||
senderAddress,
|
||||
[instantiateContractMsg],
|
||||
this.fees.init,
|
||||
options.memo,
|
||||
);
|
||||
if (isBroadcastTxFailure(result)) {
|
||||
throw new Error(createBroadcastTxErrorMessage(result));
|
||||
}
|
||||
@ -243,7 +261,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
newAdmin: string,
|
||||
memo = "",
|
||||
): Promise<ChangeAdminResult> {
|
||||
const updateAdminMsg = {
|
||||
const updateAdminMsg: MsgUpdateAdminEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1beta1.MsgUpdateAdmin",
|
||||
value: MsgUpdateAdmin.fromPartial({
|
||||
sender: senderAddress,
|
||||
@ -266,7 +284,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
contractAddress: string,
|
||||
memo = "",
|
||||
): Promise<ChangeAdminResult> {
|
||||
const clearAdminMsg = {
|
||||
const clearAdminMsg: MsgClearAdminEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1beta1.MsgClearAdmin",
|
||||
value: MsgClearAdmin.fromPartial({
|
||||
sender: senderAddress,
|
||||
@ -290,7 +308,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
migrateMsg: Record<string, unknown>,
|
||||
memo = "",
|
||||
): Promise<MigrateResult> {
|
||||
const msg = {
|
||||
const migrateContractMsg: MsgMigrateContractEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1beta1.MsgMigrateContract",
|
||||
value: MsgMigrateContract.fromPartial({
|
||||
sender: senderAddress,
|
||||
@ -299,7 +317,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
migrateMsg: toUtf8(JSON.stringify(migrateMsg)),
|
||||
}),
|
||||
};
|
||||
const result = await this.signAndBroadcast(senderAddress, [msg], this.fees.migrate, memo);
|
||||
const result = await this.signAndBroadcast(senderAddress, [migrateContractMsg], this.fees.migrate, memo);
|
||||
if (isBroadcastTxFailure(result)) {
|
||||
throw new Error(createBroadcastTxErrorMessage(result));
|
||||
}
|
||||
@ -316,7 +334,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
memo = "",
|
||||
transferAmount?: readonly Coin[],
|
||||
): Promise<ExecuteResult> {
|
||||
const executeMsg = {
|
||||
const executeContractMsg: MsgExecuteContractEncodeObject = {
|
||||
typeUrl: "/cosmwasm.wasm.v1beta1.MsgExecuteContract",
|
||||
value: MsgExecuteContract.fromPartial({
|
||||
sender: senderAddress,
|
||||
@ -325,7 +343,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
funds: [...(transferAmount || [])],
|
||||
}),
|
||||
};
|
||||
const result = await this.signAndBroadcast(senderAddress, [executeMsg], this.fees.exec, memo);
|
||||
const result = await this.signAndBroadcast(senderAddress, [executeContractMsg], this.fees.exec, memo);
|
||||
if (isBroadcastTxFailure(result)) {
|
||||
throw new Error(createBroadcastTxErrorMessage(result));
|
||||
}
|
||||
@ -341,12 +359,12 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
transferAmount: readonly Coin[],
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
const sendMsg = {
|
||||
const sendMsg: MsgSendEncodeObject = {
|
||||
typeUrl: "/cosmos.bank.v1beta1.MsgSend",
|
||||
value: {
|
||||
fromAddress: senderAddress,
|
||||
toAddress: recipientAddress,
|
||||
amount: transferAmount,
|
||||
amount: [...transferAmount],
|
||||
},
|
||||
};
|
||||
return this.signAndBroadcast(senderAddress, [sendMsg], this.fees.send, memo);
|
||||
@ -358,7 +376,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
amount: Coin,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
const delegateMsg = {
|
||||
const delegateMsg: MsgDelegateEncodeObject = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgDelegate",
|
||||
value: MsgDelegate.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress, amount }),
|
||||
};
|
||||
@ -371,7 +389,7 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
amount: Coin,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
const undelegateMsg = {
|
||||
const undelegateMsg: MsgUndelegateEncodeObject = {
|
||||
typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate",
|
||||
value: MsgUndelegate.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress, amount }),
|
||||
};
|
||||
@ -383,11 +401,11 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
validatorAddress: string,
|
||||
memo = "",
|
||||
): Promise<BroadcastTxResponse> {
|
||||
const withdrawMsg = {
|
||||
const withdrawDelegatorRewardMsg: MsgWithdrawDelegatorRewardEncodeObject = {
|
||||
typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
|
||||
value: MsgWithdrawDelegatorReward.fromPartial({ delegatorAddress: delegatorAddress, validatorAddress }),
|
||||
};
|
||||
return this.signAndBroadcast(delegatorAddress, [withdrawMsg], this.fees.withdraw, memo);
|
||||
return this.signAndBroadcast(delegatorAddress, [withdrawDelegatorRewardMsg], this.fees.withdraw, memo);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -453,14 +471,14 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
const msgs = messages.map((msg) => this.aminoTypes.toAmino(msg));
|
||||
const signDoc = makeSignDocAmino(msgs, fee, chainId, memo, accountNumber, sequence);
|
||||
const { signature, signed } = await this.signer.signAmino(signerAddress, signDoc);
|
||||
const signedTxBody = {
|
||||
messages: signed.msgs.map((msg) => this.aminoTypes.fromAmino(msg)),
|
||||
memo: signed.memo,
|
||||
};
|
||||
const signedTxBodyBytes = this.registry.encode({
|
||||
const signedTxBody: TxBodyEncodeObject = {
|
||||
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
||||
value: signedTxBody,
|
||||
});
|
||||
value: {
|
||||
messages: signed.msgs.map((msg) => this.aminoTypes.fromAmino(msg)),
|
||||
memo: signed.memo,
|
||||
},
|
||||
};
|
||||
const signedTxBodyBytes = this.registry.encode(signedTxBody);
|
||||
const signedGasLimit = Int53.fromString(signed.fee.gas).toNumber();
|
||||
const signedSequence = Int53.fromString(signed.sequence).toNumber();
|
||||
const signedAuthInfoBytes = makeAuthInfoBytes(
|
||||
@ -492,14 +510,14 @@ export class SigningCosmWasmClient extends CosmWasmClient {
|
||||
throw new Error("Failed to retrieve account from signer");
|
||||
}
|
||||
const pubkey = encodePubkey(encodeSecp256k1Pubkey(accountFromSigner.pubkey));
|
||||
const txBody = {
|
||||
messages: messages,
|
||||
memo: memo,
|
||||
};
|
||||
const txBodyBytes = this.registry.encode({
|
||||
const txBody: TxBodyEncodeObject = {
|
||||
typeUrl: "/cosmos.tx.v1beta1.TxBody",
|
||||
value: txBody,
|
||||
});
|
||||
value: {
|
||||
messages: messages,
|
||||
memo: memo,
|
||||
},
|
||||
};
|
||||
const txBodyBytes = this.registry.encode(txBody);
|
||||
const gasLimit = Int53.fromString(fee.gas).toNumber();
|
||||
const authInfoBytes = makeAuthInfoBytes([pubkey], fee.amount, gasLimit, sequence);
|
||||
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber);
|
||||
|
Loading…
x
Reference in New Issue
Block a user