mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
Merge pull request #1114 from cosmos/fix-vesting-amino-message
Use correct data format in vesting aminomessage
This commit is contained in:
commit
b13f72a5f3
@ -86,9 +86,5 @@ export {
|
||||
} from "./staking/messages";
|
||||
export { setupStakingExtension, StakingExtension } from "./staking/queries";
|
||||
export { setupTxExtension, TxExtension } from "./tx/queries";
|
||||
export {
|
||||
AminoMsgCreateVestingAccount,
|
||||
createVestingAminoConverters,
|
||||
isAminoMsgCreateVestingAccount,
|
||||
} from "./vesting/aminomessages";
|
||||
export { createVestingAminoConverters } from "./vesting/aminomessages";
|
||||
export { vestingTypes } from "./vesting/messages";
|
||||
|
@ -1,57 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { AminoMsg, Coin } from "@cosmjs/amino";
|
||||
import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx";
|
||||
import Long from "long";
|
||||
|
||||
import { AminoConverters } from "../../aminotypes";
|
||||
|
||||
export interface AminoMsgCreateVestingAccount extends AminoMsg {
|
||||
readonly type: "cosmos-sdk/MsgCreateVestingAccount";
|
||||
readonly value: {
|
||||
/** Bech32 account address */
|
||||
readonly from_address: string;
|
||||
/** Bech32 account address */
|
||||
readonly to_address: string;
|
||||
readonly amount: readonly Coin[];
|
||||
readonly end_time: Long;
|
||||
readonly delayed: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export function isAminoMsgCreateVestingAccount(msg: AminoMsg): msg is AminoMsgCreateVestingAccount {
|
||||
return msg.type === "cosmos-sdk/MsgCreateVestingAccount";
|
||||
}
|
||||
|
||||
export function createVestingAminoConverters(): AminoConverters {
|
||||
return {
|
||||
"/cosmos.vesting.v1beta1.MsgCreateVestingAccount": {
|
||||
aminoType: "cosmos-sdk/MsgCreateVestingAccount",
|
||||
toAmino: ({
|
||||
fromAddress,
|
||||
toAddress,
|
||||
amount,
|
||||
endTime,
|
||||
delayed,
|
||||
}: MsgCreateVestingAccount): AminoMsgCreateVestingAccount["value"] => ({
|
||||
from_address: fromAddress,
|
||||
to_address: toAddress,
|
||||
amount: [...amount],
|
||||
end_time: endTime,
|
||||
delayed: delayed,
|
||||
}),
|
||||
fromAmino: ({
|
||||
from_address,
|
||||
to_address,
|
||||
amount,
|
||||
end_time,
|
||||
delayed,
|
||||
}: AminoMsgCreateVestingAccount["value"]): MsgCreateVestingAccount => ({
|
||||
fromAddress: from_address,
|
||||
toAddress: to_address,
|
||||
amount: [...amount],
|
||||
endTime: end_time,
|
||||
delayed: delayed,
|
||||
}),
|
||||
},
|
||||
"/cosmos.vesting.v1beta1.MsgCreateVestingAccount": "not_supported_by_chain",
|
||||
};
|
||||
}
|
||||
|
45
packages/stargate/src/modules/vesting/messages.spec.ts
Normal file
45
packages/stargate/src/modules/vesting/messages.spec.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import { coins } from "@cosmjs/amino";
|
||||
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
|
||||
import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx";
|
||||
import Long from "long";
|
||||
|
||||
import { SigningStargateClient } from "../../signingstargateclient";
|
||||
import { isDeliverTxSuccess } from "../../stargateclient";
|
||||
import {
|
||||
defaultSigningClientOptions,
|
||||
faucet,
|
||||
makeRandomAddress,
|
||||
pendingWithoutSimapp,
|
||||
simapp,
|
||||
} from "../../testutils.spec";
|
||||
|
||||
describe("VestingExtension direct", () => {
|
||||
it("works with direct signing", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic);
|
||||
const client = await SigningStargateClient.connectWithSigner(
|
||||
simapp.tendermintUrl,
|
||||
wallet,
|
||||
defaultSigningClientOptions,
|
||||
);
|
||||
const memo = "Vesting is cool!";
|
||||
const fee = {
|
||||
amount: coins(2000, "ucosm"),
|
||||
gas: "180000", // 180k
|
||||
};
|
||||
|
||||
const vestingMsg = {
|
||||
typeUrl: "/cosmos.vesting.v1beta1.MsgCreateVestingAccount",
|
||||
value: MsgCreateVestingAccount.fromPartial({
|
||||
fromAddress: faucet.address0,
|
||||
toAddress: makeRandomAddress(),
|
||||
amount: coins(1234, "ucosm"),
|
||||
endTime: Long.fromString("1838718434"),
|
||||
delayed: true,
|
||||
}),
|
||||
};
|
||||
|
||||
const result = await client.signAndBroadcast(faucet.address0, [vestingMsg], fee, memo);
|
||||
expect(isDeliverTxSuccess(result)).toEqual(true);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user