From 0b423e443818bd9ed4601e25d795559c5506d66f Mon Sep 17 00:00:00 2001 From: willclarktech Date: Tue, 26 Jan 2021 15:32:35 +0000 Subject: [PATCH] stargate: Add Amino type conversions for distribution msgs --- packages/stargate/src/aminotypes.ts | 81 +++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/packages/stargate/src/aminotypes.ts b/packages/stargate/src/aminotypes.ts index 8d424d72..11b217ef 100644 --- a/packages/stargate/src/aminotypes.ts +++ b/packages/stargate/src/aminotypes.ts @@ -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 { })), }), }, + "/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: ({