Merge pull request #631 from cosmos/629-distribution-amino-signing
Add Amino types for distribution msgs
This commit is contained in:
commit
886f59b51c
@ -50,6 +50,9 @@
|
||||
|
||||
### Added
|
||||
|
||||
- @cosmjs/launchpad: Export distribution module msg types
|
||||
`MsgFundCommunityPool`, `MsgSetWithdrawAddress`, `MsgWithdrawDelegatorReward`,
|
||||
`MsgWithdrawValidatorCommission` and type checker helper functions.
|
||||
- @cosmjs/utils: Added `assertDefinedAndNotNull`.
|
||||
|
||||
### Changed
|
||||
|
||||
@ -104,17 +104,25 @@ export {
|
||||
isMsgCreateValidator,
|
||||
isMsgDelegate,
|
||||
isMsgEditValidator,
|
||||
isMsgFundCommunityPool,
|
||||
isMsgMultiSend,
|
||||
isMsgSend,
|
||||
isMsgSetWithdrawAddress,
|
||||
isMsgUndelegate,
|
||||
isMsgWithdrawDelegatorReward,
|
||||
isMsgWithdrawValidatorCommission,
|
||||
Msg,
|
||||
MsgBeginRedelegate,
|
||||
MsgCreateValidator,
|
||||
MsgDelegate,
|
||||
MsgEditValidator,
|
||||
MsgFundCommunityPool,
|
||||
MsgMultiSend,
|
||||
MsgSend,
|
||||
MsgSetWithdrawAddress,
|
||||
MsgUndelegate,
|
||||
MsgWithdrawDelegatorReward,
|
||||
MsgWithdrawValidatorCommission,
|
||||
} from "./msgs";
|
||||
export {
|
||||
decodeAminoPubkey,
|
||||
|
||||
8
packages/launchpad/types/index.d.ts
vendored
8
packages/launchpad/types/index.d.ts
vendored
@ -102,17 +102,25 @@ export {
|
||||
isMsgCreateValidator,
|
||||
isMsgDelegate,
|
||||
isMsgEditValidator,
|
||||
isMsgFundCommunityPool,
|
||||
isMsgMultiSend,
|
||||
isMsgSend,
|
||||
isMsgSetWithdrawAddress,
|
||||
isMsgUndelegate,
|
||||
isMsgWithdrawDelegatorReward,
|
||||
isMsgWithdrawValidatorCommission,
|
||||
Msg,
|
||||
MsgBeginRedelegate,
|
||||
MsgCreateValidator,
|
||||
MsgDelegate,
|
||||
MsgEditValidator,
|
||||
MsgFundCommunityPool,
|
||||
MsgMultiSend,
|
||||
MsgSend,
|
||||
MsgSetWithdrawAddress,
|
||||
MsgUndelegate,
|
||||
MsgWithdrawDelegatorReward,
|
||||
MsgWithdrawValidatorCommission,
|
||||
} from "./msgs";
|
||||
export {
|
||||
decodeAminoPubkey,
|
||||
|
||||
@ -12,12 +12,22 @@ import {
|
||||
MsgSend,
|
||||
MsgUndelegate,
|
||||
} from "@cosmjs/launchpad";
|
||||
import {
|
||||
MsgFundCommunityPool,
|
||||
MsgSetWithdrawAddress,
|
||||
MsgWithdrawDelegatorReward,
|
||||
MsgWithdrawValidatorCommission,
|
||||
} from "@cosmjs/launchpad/types/msgs";
|
||||
|
||||
import { AminoTypes } from "./aminotypes";
|
||||
import { cosmos } from "./codec";
|
||||
|
||||
type IMsgSend = cosmos.bank.v1beta1.IMsgSend;
|
||||
type IMsgMultiSend = cosmos.bank.v1beta1.IMsgMultiSend;
|
||||
type IMsgFundCommunityPool = cosmos.distribution.v1beta1.IMsgFundCommunityPool;
|
||||
type IMsgSetWithdrawAddress = cosmos.distribution.v1beta1.IMsgSetWithdrawAddress;
|
||||
type IMsgWithdrawDelegatorReward = cosmos.distribution.v1beta1.IMsgWithdrawDelegatorReward;
|
||||
type IMsgWithdrawValidatorCommission = cosmos.distribution.v1beta1.IMsgWithdrawValidatorCommission;
|
||||
type IMsgBeginRedelegate = cosmos.staking.v1beta1.IMsgBeginRedelegate;
|
||||
type IMsgCreateValidator = cosmos.staking.v1beta1.IMsgCreateValidator;
|
||||
type IMsgDelegate = cosmos.staking.v1beta1.IMsgDelegate;
|
||||
@ -78,6 +88,80 @@ describe("AminoTypes", () => {
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgFundCommunityPool", async () => {
|
||||
const msg: IMsgFundCommunityPool = {
|
||||
amount: coins(1234, "ucosm"),
|
||||
depositor: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
};
|
||||
const aminoMsg = new AminoTypes().toAmino({
|
||||
typeUrl: "/cosmos.distribution.v1beta1.MsgFundCommunityPool",
|
||||
value: msg,
|
||||
});
|
||||
const expected: MsgFundCommunityPool = {
|
||||
type: "cosmos-sdk/MsgFundCommunityPool",
|
||||
value: {
|
||||
amount: coins(1234, "ucosm"),
|
||||
depositor: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgSetWithdrawAddress", async () => {
|
||||
const msg: IMsgSetWithdrawAddress = {
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
withdrawAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
};
|
||||
const aminoMsg = new AminoTypes().toAmino({
|
||||
typeUrl: "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress",
|
||||
value: msg,
|
||||
});
|
||||
const expected: MsgSetWithdrawAddress = {
|
||||
type: "cosmos-sdk/MsgSetWithdrawAddress",
|
||||
value: {
|
||||
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
withdraw_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgWithdrawDelegatorReward", async () => {
|
||||
const msg: IMsgWithdrawDelegatorReward = {
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
};
|
||||
const aminoMsg = new AminoTypes().toAmino({
|
||||
typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
|
||||
value: msg,
|
||||
});
|
||||
const expected: MsgWithdrawDelegatorReward = {
|
||||
type: "cosmos-sdk/MsgWithdrawDelegatorReward",
|
||||
value: {
|
||||
delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgWithdrawValidatorCommission", async () => {
|
||||
const msg: IMsgWithdrawValidatorCommission = {
|
||||
validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
};
|
||||
const aminoMsg = new AminoTypes().toAmino({
|
||||
typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission",
|
||||
value: msg,
|
||||
});
|
||||
const expected: MsgWithdrawValidatorCommission = {
|
||||
type: "cosmos-sdk/MsgWithdrawValidatorCommission",
|
||||
value: {
|
||||
validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5",
|
||||
},
|
||||
};
|
||||
expect(aminoMsg).toEqual(expected);
|
||||
});
|
||||
|
||||
it("works for MsgBeginRedelegate", () => {
|
||||
const msg: IMsgBeginRedelegate = {
|
||||
delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
|
||||
|
||||
@ -8,9 +8,13 @@ import {
|
||||
MsgCreateValidator,
|
||||
MsgDelegate,
|
||||
MsgEditValidator,
|
||||
MsgFundCommunityPool,
|
||||
MsgMultiSend,
|
||||
MsgSend,
|
||||
MsgSetWithdrawAddress,
|
||||
MsgUndelegate,
|
||||
MsgWithdrawDelegatorReward,
|
||||
MsgWithdrawValidatorCommission,
|
||||
} from "@cosmjs/launchpad";
|
||||
import { EncodeObject } from "@cosmjs/proto-signing";
|
||||
import { assertDefinedAndNotNull } from "@cosmjs/utils";
|
||||
@ -20,6 +24,10 @@ import { coinFromProto } from "./stargateclient";
|
||||
|
||||
type IMsgSend = cosmos.bank.v1beta1.IMsgSend;
|
||||
type IMsgMultiSend = cosmos.bank.v1beta1.IMsgMultiSend;
|
||||
type IMsgFundCommunityPool = cosmos.distribution.v1beta1.IMsgFundCommunityPool;
|
||||
type IMsgSetWithdrawAddress = cosmos.distribution.v1beta1.IMsgSetWithdrawAddress;
|
||||
type IMsgWithdrawDelegatorReward = cosmos.distribution.v1beta1.IMsgWithdrawDelegatorReward;
|
||||
type IMsgWithdrawValidatorCommission = cosmos.distribution.v1beta1.IMsgWithdrawValidatorCommission;
|
||||
type IMsgBeginRedelegate = cosmos.staking.v1beta1.IMsgBeginRedelegate;
|
||||
type IMsgCreateValidator = cosmos.staking.v1beta1.IMsgCreateValidator;
|
||||
type IMsgDelegate = cosmos.staking.v1beta1.IMsgDelegate;
|
||||
@ -87,6 +95,79 @@ function createDefaultTypes(prefix: string): Record<string, AminoConverter> {
|
||||
})),
|
||||
}),
|
||||
},
|
||||
"/cosmos.distribution.v1beta1.MsgFundCommunityPool": {
|
||||
aminoType: "cosmos-sdk/MsgFundCommunityPool",
|
||||
toAmino: ({ amount, depositor }: IMsgFundCommunityPool): MsgFundCommunityPool["value"] => {
|
||||
assertDefinedAndNotNull(amount);
|
||||
assertDefinedAndNotNull(depositor);
|
||||
return {
|
||||
amount: amount.map(coinFromProto),
|
||||
depositor: depositor,
|
||||
};
|
||||
},
|
||||
fromAmino: ({ amount, depositor }: MsgFundCommunityPool["value"]): IMsgFundCommunityPool => ({
|
||||
amount: [...amount],
|
||||
depositor: depositor,
|
||||
}),
|
||||
},
|
||||
"/cosmos.distribution.v1beta1.MsgSetWithdrawAddress": {
|
||||
aminoType: "cosmos-sdk/MsgSetWithdrawAddress",
|
||||
toAmino: ({
|
||||
delegatorAddress,
|
||||
withdrawAddress,
|
||||
}: IMsgSetWithdrawAddress): MsgSetWithdrawAddress["value"] => {
|
||||
assertDefinedAndNotNull(delegatorAddress);
|
||||
assertDefinedAndNotNull(withdrawAddress);
|
||||
return {
|
||||
delegator_address: delegatorAddress,
|
||||
withdraw_address: withdrawAddress,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
withdraw_address,
|
||||
}: MsgSetWithdrawAddress["value"]): IMsgSetWithdrawAddress => ({
|
||||
delegatorAddress: delegator_address,
|
||||
withdrawAddress: withdraw_address,
|
||||
}),
|
||||
},
|
||||
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward": {
|
||||
aminoType: "cosmos-sdk/MsgWithdrawDelegatorReward",
|
||||
toAmino: ({
|
||||
delegatorAddress,
|
||||
validatorAddress,
|
||||
}: IMsgWithdrawDelegatorReward): MsgWithdrawDelegatorReward["value"] => {
|
||||
assertDefinedAndNotNull(delegatorAddress);
|
||||
assertDefinedAndNotNull(validatorAddress);
|
||||
return {
|
||||
delegator_address: delegatorAddress,
|
||||
validator_address: validatorAddress,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
delegator_address,
|
||||
validator_address,
|
||||
}: MsgWithdrawDelegatorReward["value"]): IMsgWithdrawDelegatorReward => ({
|
||||
delegatorAddress: delegator_address,
|
||||
validatorAddress: validator_address,
|
||||
}),
|
||||
},
|
||||
"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission": {
|
||||
aminoType: "cosmos-sdk/MsgWithdrawValidatorCommission",
|
||||
toAmino: ({
|
||||
validatorAddress,
|
||||
}: IMsgWithdrawValidatorCommission): MsgWithdrawValidatorCommission["value"] => {
|
||||
assertDefinedAndNotNull(validatorAddress);
|
||||
return {
|
||||
validator_address: validatorAddress,
|
||||
};
|
||||
},
|
||||
fromAmino: ({
|
||||
validator_address,
|
||||
}: MsgWithdrawValidatorCommission["value"]): IMsgWithdrawValidatorCommission => ({
|
||||
validatorAddress: validator_address,
|
||||
}),
|
||||
},
|
||||
"/cosmos.staking.v1beta1.MsgBeginRedelegate": {
|
||||
aminoType: "cosmos-sdk/MsgBeginRedelegate",
|
||||
toAmino: ({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user