diff --git a/integration-tests/decodeMsgVerifyInvariant.ts b/integration-tests/decodeMsgVerifyInvariant.ts new file mode 100644 index 000000000..b9c24758f --- /dev/null +++ b/integration-tests/decodeMsgVerifyInvariant.ts @@ -0,0 +1,25 @@ +import { LCDClient, MsgSend, MnemonicKey } from '../src'; +import { SignMode } from '@terra-money/terra.proto/cosmos/tx/signing/v1beta1/signing'; +import { TxBody } from '@terra-money/terra.proto/cosmos/tx/v1beta1/tx'; + +async function main() { + const bombay = new LCDClient({ + chainID: 'bombay-12', + URL: 'https://bombay-lcd.terra.dev', + gasPrices: { uusd: 0.15 }, + }); + + (await bombay.tx.txInfosByHeight(8152638)). + map((tx) => { + console.log(JSON.stringify(tx)); + }); + + + (await bombay.tx.txInfosByHeight(8153558)). + map((tx) => { + console.log(JSON.stringify(tx)); + }); + +} + +main().catch(console.error); diff --git a/src/core/Msg.ts b/src/core/Msg.ts index e6447d636..0de6e4c4f 100644 --- a/src/core/Msg.ts +++ b/src/core/Msg.ts @@ -78,6 +78,7 @@ import { MsgTimeoutOnClose, IbcChannelMsg, } from './ibc/msgs/channel'; +import { MsgVerifyInvariant, CrisisMsg } from './crisis'; import { Any } from '@terra-money/terra.proto/google/protobuf/any'; export type Msg = @@ -94,7 +95,8 @@ export type Msg = | IbcTransferMsg | IbcClientMsg | IbcConnectionMsg - | IbcChannelMsg; + | IbcChannelMsg + | CrisisMsg; export namespace Msg { export type Amino = @@ -108,7 +110,8 @@ export namespace Msg { | SlashingMsg.Amino | StakingMsg.Amino | WasmMsg.Amino - | IbcTransferMsg.Amino; + | IbcTransferMsg.Amino + | CrisisMsg.Amino; export type Data = | BankMsg.Data @@ -124,7 +127,8 @@ export namespace Msg { | IbcTransferMsg.Data | IbcClientMsg.Data | IbcConnectionMsg.Data - | IbcChannelMsg.Data; + | IbcChannelMsg.Data + | CrisisMsg.Data; export type Proto = | BankMsg.Proto @@ -140,7 +144,8 @@ export namespace Msg { | IbcTransferMsg.Proto | IbcClientMsg.Proto | IbcConnectionMsg.Proto - | IbcChannelMsg.Proto; + | IbcChannelMsg.Proto + | CrisisMsg.Proto; export function fromAmino(data: Msg.Amino): Msg { switch (data.type) { @@ -233,6 +238,10 @@ export namespace Msg { // ibc-transfer case 'cosmos-sdk/MsgTransfer': return MsgTransfer.fromAmino(data); + + // crisis + case 'crisis/MsgVerifyInvariant': + return MsgVerifyInvariant.fromAmino(data); } } export function fromData(data: Msg.Data): Msg { @@ -368,6 +377,10 @@ export namespace Msg { return MsgTimeout.fromData(data); case '/ibc.core.channel.v1.MsgTimeoutOnClose': return MsgTimeoutOnClose.fromData(data); + + // crisis + case '/cosmos.crisis.v1beta1.MsgVerifyInvariant': + return MsgVerifyInvariant.fromData(data); } } @@ -502,6 +515,11 @@ export namespace Msg { return MsgTimeout.unpackAny(proto); case '/ibc.core.channel.v1.MsgTimeoutOnClose': return MsgTimeoutOnClose.unpackAny(proto); + + // crisis + case '/cosmos.crisis.v1beta1.MsgVerifyInvariant': + return MsgVerifyInvariant.unpackAny(proto); + default: throw Error(`not supported msg ${proto.typeUrl}`); } diff --git a/src/core/crisis/MsgVerifyInvariant.spec.ts b/src/core/crisis/MsgVerifyInvariant.spec.ts new file mode 100644 index 000000000..dc46c01a9 --- /dev/null +++ b/src/core/crisis/MsgVerifyInvariant.spec.ts @@ -0,0 +1,51 @@ +import { MsgVerifyInvariant } from './MsgVerifyInvariant'; + +describe('MsgVerifyInvariant', () => { + it('deserialize correctly', () => { + const send = MsgVerifyInvariant.fromAmino({ + type: 'crisis/MsgVerifyInvariant', + value: { + sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', + invariantModuleName: 'bank', + invariantRoute: 'nonnegative-outstanding-supply', + }, + }); + + expect(send).toMatchObject({ + sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', + invariantModuleName: 'bank', + invariantRoute: 'nonnegative-outstanding-supply', + }); + + expect(send.toAmino()).toMatchObject({ + type: 'crisis/MsgVerifyInvariant', + value: { + sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', + invariantModuleName: 'bank', + invariantRoute: 'nonnegative-outstanding-supply', + }, + }); + }); + + it('deserialize correctly proto', () => { + const send = MsgVerifyInvariant.fromData({ + '@type': '/cosmos.crisis.v1beta1.MsgVerifyInvariant', + sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', + invariantModuleName: 'bank', + invariantRoute: 'nonnegative-outstanding-supply', + }); + + expect(send).toMatchObject({ + sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', + invariantModuleName: 'bank', + invariantRoute: 'nonnegative-outstanding-supply', + }); + + expect(send.toData()).toMatchObject({ + '@type': '/cosmos.crisis.v1beta1.MsgVerifyInvariant', + sender: 'terra1x46rqay4d3cssq8gxxvqz8xt6nwlz4td20k38v', + invariantModuleName: 'bank', + invariantRoute: 'nonnegative-outstanding-supply', + }); + }); +}); diff --git a/src/core/crisis/MsgVerifyInvariant.ts b/src/core/crisis/MsgVerifyInvariant.ts new file mode 100644 index 000000000..eadcd6ccf --- /dev/null +++ b/src/core/crisis/MsgVerifyInvariant.ts @@ -0,0 +1,111 @@ +import { JSONSerializable } from '../../util/json'; +import { Any } from '@terra-money/terra.proto/google/protobuf/any'; +import { MsgVerifyInvariant as MsgVerifyInvariant_pb } from '@terra-money/terra.proto/cosmos/crisis/v1beta1/tx'; +import { AccAddress } from '../bech32'; + +/** + * MsgVerifyInvariant represents a message to verify a particular invariance. + */ +export class MsgVerifyInvariant extends JSONSerializable< + MsgVerifyInvariant.Amino, + MsgVerifyInvariant.Data, + MsgVerifyInvariant.Proto +> { + /** + * @param sender sender's address + * @param invariantModuleName module name to verify invariant + * @param invariantRoute route to verify + */ + constructor( + public sender: AccAddress, + public invariantModuleName: string, + public invariantRoute: string + ) { + super(); + } + + public static fromAmino(data: MsgVerifyInvariant.Amino): MsgVerifyInvariant { + const { + value: { sender, invariantModuleName, invariantRoute }, + } = data; + return new MsgVerifyInvariant(sender, invariantModuleName, invariantRoute); + } + + public toAmino(): MsgVerifyInvariant.Amino { + const { sender, invariantModuleName, invariantRoute } = this; + return { + type: 'crisis/MsgVerifyInvariant', + value: { + sender, + invariantModuleName, + invariantRoute, + }, + }; + } + + public static fromData(data: MsgVerifyInvariant.Data): MsgVerifyInvariant { + const { sender, invariantModuleName, invariantRoute } = data; + + return new MsgVerifyInvariant(sender, invariantModuleName, invariantRoute); + } + + public toData(): MsgVerifyInvariant.Data { + const { sender, invariantModuleName, invariantRoute } = this; + return { + '@type': '/cosmos.crisis.v1beta1.MsgVerifyInvariant', + sender, + invariantModuleName, + invariantRoute, + }; + } + + public static fromProto(proto: MsgVerifyInvariant.Proto): MsgVerifyInvariant { + return new MsgVerifyInvariant( + proto.sender, + proto.invariantModuleName, + proto.invariantRoute + ); + } + + public toProto(): MsgVerifyInvariant.Proto { + const { sender, invariantModuleName, invariantRoute } = this; + return MsgVerifyInvariant_pb.fromPartial({ + sender, + invariantModuleName, + invariantRoute, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/cosmos.crisis.v1beta1.MsgVerifyInvariant', + value: MsgVerifyInvariant_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgVerifyInvariant { + return MsgVerifyInvariant.fromProto( + MsgVerifyInvariant_pb.decode(msgAny.value) + ); + } +} + +export namespace MsgVerifyInvariant { + export interface Amino { + type: 'crisis/MsgVerifyInvariant'; + value: { + sender: AccAddress; + invariantModuleName: string; + invariantRoute: string; + }; + } + + export interface Data { + '@type': '/cosmos.crisis.v1beta1.MsgVerifyInvariant'; + sender: AccAddress; + invariantModuleName: string; + invariantRoute: string; + } + + export type Proto = MsgVerifyInvariant_pb; +} diff --git a/src/core/crisis/index.ts b/src/core/crisis/index.ts new file mode 100644 index 000000000..92b320918 --- /dev/null +++ b/src/core/crisis/index.ts @@ -0,0 +1,10 @@ +import { MsgVerifyInvariant } from './MsgVerifyInvariant'; + +export * from './MsgVerifyInvariant'; + +export type CrisisMsg = MsgVerifyInvariant; +export namespace CrisisMsg { + export type Amino = MsgVerifyInvariant.Amino; + export type Data = MsgVerifyInvariant.Data; + export type Proto = MsgVerifyInvariant.Proto; +}