Merge pull request #1111 from cosmos/add-vesting-module

Adding vesting module to stargate
This commit is contained in:
Milan Steiner 2022-04-07 10:55:59 +02:00 committed by GitHub
commit dc56aacc00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 0 deletions

View File

@ -9,6 +9,7 @@ and this project adheres to
### Added
- @cosmjs/encoding: Create `normalizeBech32`.
- @cosmjs/stargate: Added support for vesting messages.
## [0.28.1] - 2022-03-30

View File

@ -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";

View File

@ -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,
}),
},
};
}

View File

@ -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],
];

View File

@ -38,6 +38,7 @@ import {
MsgUndelegateEncodeObject,
MsgWithdrawDelegatorRewardEncodeObject,
stakingTypes,
vestingTypes,
} from "./modules";
import {
createAuthzAminoConverters,
@ -47,6 +48,7 @@ import {
createGovAminoConverters,
createIbcAminoConverters,
createStakingAminoConverters,
createVestingAminoConverters,
} from "./modules";
import { DeliverTxResponse, StargateClient, StargateClientOptions } from "./stargateclient";
@ -59,6 +61,7 @@ export const defaultRegistryTypes: ReadonlyArray<[string, GeneratedType]> = [
...govTypes,
...stakingTypes,
...ibcTypes,
...vestingTypes,
];
function createDefaultRegistry(): Registry {
@ -99,6 +102,7 @@ function createDefaultTypes(prefix: string): AminoConverters {
...createStakingAminoConverters(prefix),
...createIbcAminoConverters(),
...createFreegrantAminoConverters(),
...createVestingAminoConverters(),
};
}