diff --git a/CHANGELOG.md b/CHANGELOG.md index d83dce783b..ddfd548ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to - @cosmjs/stargate: Added the ability to specify a custom account parser for `StargateClient` +- @cosmjs/stargate: Added support for vesting messages. ### Fixed diff --git a/packages/stargate/src/modules/index.ts b/packages/stargate/src/modules/index.ts index 755fe9ef22..d8ff595acd 100644 --- a/packages/stargate/src/modules/index.ts +++ b/packages/stargate/src/modules/index.ts @@ -86,3 +86,9 @@ export { } from "./staking/messages"; export { setupStakingExtension, StakingExtension } from "./staking/queries"; export { setupTxExtension, TxExtension } from "./tx/queries"; +export { + AminoMsgCreateVestingAccount, + createVestingAminoConverters, + isAminoMsgCreateVestingAccount, +} from "./vesting/aminomessages"; +export { vestingTypes } from "./vesting/messages"; diff --git a/packages/stargate/src/modules/vesting/aminomessages.ts b/packages/stargate/src/modules/vesting/aminomessages.ts new file mode 100644 index 0000000000..46fa54f184 --- /dev/null +++ b/packages/stargate/src/modules/vesting/aminomessages.ts @@ -0,0 +1,57 @@ +/* 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, + }), + }, + }; +} diff --git a/packages/stargate/src/modules/vesting/messages.ts b/packages/stargate/src/modules/vesting/messages.ts new file mode 100644 index 0000000000..5fd99567ee --- /dev/null +++ b/packages/stargate/src/modules/vesting/messages.ts @@ -0,0 +1,6 @@ +import { GeneratedType } from "@cosmjs/proto-signing"; +import { MsgCreateVestingAccount } from "cosmjs-types/cosmos/vesting/v1beta1/tx"; + +export const vestingTypes: ReadonlyArray<[string, GeneratedType]> = [ + ["/cosmos.vesting.v1beta1.MsgCreateVestingAccount", MsgCreateVestingAccount], +];