From 8da37cd2e56e7778b34f973a9163749c663c33b1 Mon Sep 17 00:00:00 2001 From: Milan Steiner Date: Wed, 6 Apr 2022 10:44:55 +0200 Subject: [PATCH] Adding vesting module to stargate --- CHANGELOG.md | 1 + packages/stargate/src/modules/index.ts | 6 ++ .../src/modules/vesting/aminomessages.ts | 57 +++++++++++++++++++ .../stargate/src/modules/vesting/messages.ts | 6 ++ 4 files changed, 70 insertions(+) create mode 100644 packages/stargate/src/modules/vesting/aminomessages.ts create mode 100644 packages/stargate/src/modules/vesting/messages.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index d83dce78..ddfd548f 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 755fe9ef..d8ff595a 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 00000000..46fa54f1 --- /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 00000000..5fd99567 --- /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], +];