diff --git a/packages/stargate/src/aminotypes.spec.ts b/packages/stargate/src/aminotypes.spec.ts index eb6e2f24..0c768341 100644 --- a/packages/stargate/src/aminotypes.spec.ts +++ b/packages/stargate/src/aminotypes.spec.ts @@ -4,40 +4,39 @@ import { coin, coins, encodeBech32Pubkey, - MsgBeginRedelegate, - MsgCreateValidator, - MsgDelegate, - MsgEditValidator, - MsgMultiSend, - MsgSend, - MsgUndelegate, + MsgBeginRedelegate as LaunchpadMsgBeginRedelegate, + MsgCreateValidator as LaunchpadMsgCreateValidator, + MsgDelegate as LaunchpadMsgDelegate, + MsgEditValidator as LaunchpadMsgEditValidator, + MsgFundCommunityPool as LaunchpadMsgFundCommunityPool, + MsgMultiSend as LaunchpadMsgMultiSend, + MsgSend as LaunchpadMsgSend, + MsgSetWithdrawAddress as LaunchpadMsgSetWithdrawAddress, + MsgUndelegate as LaunchpadMsgUndelegate, + MsgWithdrawDelegatorReward as LaunchpadMsgWithdrawDelegatorReward, + MsgWithdrawValidatorCommission as LaunchpadMsgWithdrawValidatorCommission, } from "@cosmjs/launchpad"; + +import { AminoTypes } from "./aminotypes"; +import { MsgMultiSend, MsgSend } from "./codec/cosmos/bank/v1beta1/tx"; 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; -type IMsgEditValidator = cosmos.staking.v1beta1.IMsgEditValidator; -type IMsgUndelegate = cosmos.staking.v1beta1.IMsgUndelegate; +} from "./codec/cosmos/distribution/v1beta1/tx"; +import { + MsgBeginRedelegate, + MsgCreateValidator, + MsgDelegate, + MsgEditValidator, + MsgUndelegate, +} from "./codec/cosmos/staking/v1beta1/tx"; describe("AminoTypes", () => { describe("toAmino", () => { it("works for MsgSend", () => { - const msg: IMsgSend = { + const msg: MsgSend = { fromAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", toAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", amount: coins(1234, "ucosm"), @@ -46,7 +45,7 @@ describe("AminoTypes", () => { typeUrl: "/cosmos.bank.v1beta1.MsgSend", value: msg, }); - const expected: MsgSend = { + const expected: LaunchpadMsgSend = { type: "cosmos-sdk/MsgSend", value: { from_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", @@ -58,7 +57,7 @@ describe("AminoTypes", () => { }); it("works for MsgMultiSend", () => { - const msg: IMsgMultiSend = { + const msg: MsgMultiSend = { inputs: [ { address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", coins: coins(1234, "ucosm") }, { address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", coins: coins(5678, "ucosm") }, @@ -72,7 +71,7 @@ describe("AminoTypes", () => { typeUrl: "/cosmos.bank.v1beta1.MsgMultiSend", value: msg, }); - const expected: MsgMultiSend = { + const expected: LaunchpadMsgMultiSend = { type: "cosmos-sdk/MsgMultiSend", value: { inputs: [ @@ -89,7 +88,7 @@ describe("AminoTypes", () => { }); it("works for MsgFundCommunityPool", async () => { - const msg: IMsgFundCommunityPool = { + const msg: MsgFundCommunityPool = { amount: coins(1234, "ucosm"), depositor: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", }; @@ -97,7 +96,7 @@ describe("AminoTypes", () => { typeUrl: "/cosmos.distribution.v1beta1.MsgFundCommunityPool", value: msg, }); - const expected: MsgFundCommunityPool = { + const expected: LaunchpadMsgFundCommunityPool = { type: "cosmos-sdk/MsgFundCommunityPool", value: { amount: coins(1234, "ucosm"), @@ -108,7 +107,7 @@ describe("AminoTypes", () => { }); it("works for MsgSetWithdrawAddress", async () => { - const msg: IMsgSetWithdrawAddress = { + const msg: MsgSetWithdrawAddress = { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", withdrawAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", }; @@ -116,7 +115,7 @@ describe("AminoTypes", () => { typeUrl: "/cosmos.distribution.v1beta1.MsgSetWithdrawAddress", value: msg, }); - const expected: MsgSetWithdrawAddress = { + const expected: LaunchpadMsgSetWithdrawAddress = { type: "cosmos-sdk/MsgModifyWithdrawAddress", value: { delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", @@ -127,7 +126,7 @@ describe("AminoTypes", () => { }); it("works for MsgWithdrawDelegatorReward", async () => { - const msg: IMsgWithdrawDelegatorReward = { + const msg: MsgWithdrawDelegatorReward = { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", }; @@ -135,7 +134,7 @@ describe("AminoTypes", () => { typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward", value: msg, }); - const expected: MsgWithdrawDelegatorReward = { + const expected: LaunchpadMsgWithdrawDelegatorReward = { type: "cosmos-sdk/MsgWithdrawDelegationReward", value: { delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", @@ -146,14 +145,14 @@ describe("AminoTypes", () => { }); it("works for MsgWithdrawValidatorCommission", async () => { - const msg: IMsgWithdrawValidatorCommission = { + const msg: MsgWithdrawValidatorCommission = { validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", }; const aminoMsg = new AminoTypes().toAmino({ typeUrl: "/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission", value: msg, }); - const expected: MsgWithdrawValidatorCommission = { + const expected: LaunchpadMsgWithdrawValidatorCommission = { type: "cosmos-sdk/MsgWithdrawValidatorCommission", value: { validator_address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", @@ -163,7 +162,7 @@ describe("AminoTypes", () => { }); it("works for MsgBeginRedelegate", () => { - const msg: IMsgBeginRedelegate = { + const msg: MsgBeginRedelegate = { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", validatorSrcAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", validatorDstAddress: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", @@ -173,7 +172,7 @@ describe("AminoTypes", () => { typeUrl: "/cosmos.staking.v1beta1.MsgBeginRedelegate", value: msg, }); - const expected: MsgBeginRedelegate = { + const expected: LaunchpadMsgBeginRedelegate = { type: "cosmos-sdk/MsgBeginRedelegate", value: { delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", @@ -186,7 +185,7 @@ describe("AminoTypes", () => { }); it("works for MsgCreateValidator", () => { - const msg: IMsgCreateValidator = { + const msg: MsgCreateValidator = { description: { moniker: "validator", identity: "me", @@ -203,7 +202,7 @@ describe("AminoTypes", () => { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", pubkey: { - type_url: "/cosmos.crypto.secp256k1.PubKey", + typeUrl: "/cosmos.crypto.secp256k1.PubKey", value: fromBase64("A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ"), }, value: coin(1234, "ucosm"), @@ -212,7 +211,7 @@ describe("AminoTypes", () => { typeUrl: "/cosmos.staking.v1beta1.MsgCreateValidator", value: msg, }); - const expected: MsgCreateValidator = { + const expected: LaunchpadMsgCreateValidator = { type: "cosmos-sdk/MsgCreateValidator", value: { description: { @@ -241,7 +240,7 @@ describe("AminoTypes", () => { }); it("works for MsgDelegate", () => { - const msg: IMsgDelegate = { + const msg: MsgDelegate = { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", amount: coin(1234, "ucosm"), @@ -250,7 +249,7 @@ describe("AminoTypes", () => { typeUrl: "/cosmos.staking.v1beta1.MsgDelegate", value: msg, }); - const expected: MsgDelegate = { + const expected: LaunchpadMsgDelegate = { type: "cosmos-sdk/MsgDelegate", value: { delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", @@ -262,7 +261,7 @@ describe("AminoTypes", () => { }); it("works for MsgEditValidator", () => { - const msg: IMsgEditValidator = { + const msg: MsgEditValidator = { description: { moniker: "validator", identity: "me", @@ -278,7 +277,7 @@ describe("AminoTypes", () => { typeUrl: "/cosmos.staking.v1beta1.MsgEditValidator", value: msg, }); - const expected: MsgEditValidator = { + const expected: LaunchpadMsgEditValidator = { type: "cosmos-sdk/MsgEditValidator", value: { description: { @@ -297,7 +296,7 @@ describe("AminoTypes", () => { }); it("works for MsgUndelegate", () => { - const msg: IMsgUndelegate = { + const msg: MsgUndelegate = { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", amount: coin(1234, "ucosm"), @@ -306,7 +305,7 @@ describe("AminoTypes", () => { typeUrl: "/cosmos.staking.v1beta1.MsgUndelegate", value: msg, }); - const expected: MsgUndelegate = { + const expected: LaunchpadMsgUndelegate = { type: "cosmos-sdk/MsgUndelegate", value: { delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", @@ -347,7 +346,7 @@ describe("AminoTypes", () => { }); it("works with overridden type url", () => { - const msg: IMsgDelegate = { + const msg: MsgDelegate = { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", amount: coin(1234, "ucosm"), @@ -356,7 +355,7 @@ describe("AminoTypes", () => { additions: { "/cosmos.staking.v1beta1.MsgDelegate": { aminoType: "my-override/MsgDelegate", - toAmino: (m: IMsgDelegate): { readonly foo: string } => ({ + toAmino: (m: MsgDelegate): { readonly foo: string } => ({ foo: m.delegatorAddress ?? "", }), fromAmino: () => {}, @@ -384,7 +383,7 @@ describe("AminoTypes", () => { describe("fromAmino", () => { it("works for MsgSend", () => { - const aminoMsg: MsgSend = { + const aminoMsg: LaunchpadMsgSend = { type: "cosmos-sdk/MsgSend", value: { from_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", @@ -393,7 +392,7 @@ describe("AminoTypes", () => { }, }; const msg = new AminoTypes().fromAmino(aminoMsg); - const expectedValue: IMsgSend = { + const expectedValue: MsgSend = { fromAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", toAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", amount: coins(1234, "ucosm"), @@ -405,7 +404,7 @@ describe("AminoTypes", () => { }); it("works for MsgMultiSend", () => { - const aminoMsg: MsgMultiSend = { + const aminoMsg: LaunchpadMsgMultiSend = { type: "cosmos-sdk/MsgMultiSend", value: { inputs: [ @@ -419,7 +418,7 @@ describe("AminoTypes", () => { }, }; const msg = new AminoTypes().fromAmino(aminoMsg); - const expectedValue: IMsgMultiSend = { + const expectedValue: MsgMultiSend = { inputs: [ { address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", coins: coins(1234, "ucosm") }, { address: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", coins: coins(5678, "ucosm") }, @@ -436,7 +435,7 @@ describe("AminoTypes", () => { }); it("works for MsgBeginRedelegate", () => { - const aminoMsg: MsgBeginRedelegate = { + const aminoMsg: LaunchpadMsgBeginRedelegate = { type: "cosmos-sdk/MsgBeginRedelegate", value: { delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", @@ -446,7 +445,7 @@ describe("AminoTypes", () => { }, }; const msg = new AminoTypes().fromAmino(aminoMsg); - const expectedValue: IMsgBeginRedelegate = { + const expectedValue: MsgBeginRedelegate = { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", validatorSrcAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", validatorDstAddress: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k", @@ -459,7 +458,7 @@ describe("AminoTypes", () => { }); it("works for MsgCreateValidator", () => { - const aminoMsg: MsgCreateValidator = { + const aminoMsg: LaunchpadMsgCreateValidator = { type: "cosmos-sdk/MsgCreateValidator", value: { description: { @@ -485,7 +484,7 @@ describe("AminoTypes", () => { }, }; const msg = new AminoTypes().fromAmino(aminoMsg); - const expectedValue: IMsgCreateValidator = { + const expectedValue: MsgCreateValidator = { description: { moniker: "validator", identity: "me", @@ -502,7 +501,7 @@ describe("AminoTypes", () => { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", pubkey: { - type_url: "/cosmos.crypto.secp256k1.PubKey", + typeUrl: "/cosmos.crypto.secp256k1.PubKey", value: fromBase64("A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ"), }, value: coin(1234, "ucosm"), @@ -514,7 +513,7 @@ describe("AminoTypes", () => { }); it("works for MsgDelegate", () => { - const aminoMsg: MsgDelegate = { + const aminoMsg: LaunchpadMsgDelegate = { type: "cosmos-sdk/MsgDelegate", value: { delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", @@ -523,7 +522,7 @@ describe("AminoTypes", () => { }, }; const msg = new AminoTypes().fromAmino(aminoMsg); - const expectedValue: IMsgDelegate = { + const expectedValue: MsgDelegate = { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", amount: coin(1234, "ucosm"), @@ -535,7 +534,7 @@ describe("AminoTypes", () => { }); it("works for MsgEditValidator", () => { - const aminoMsg: MsgEditValidator = { + const aminoMsg: LaunchpadMsgEditValidator = { type: "cosmos-sdk/MsgEditValidator", value: { description: { @@ -551,7 +550,7 @@ describe("AminoTypes", () => { }, }; const msg = new AminoTypes().fromAmino(aminoMsg); - const expectedValue: IMsgEditValidator = { + const expectedValue: MsgEditValidator = { description: { moniker: "validator", identity: "me", @@ -570,7 +569,7 @@ describe("AminoTypes", () => { }); it("works for MsgUndelegate", () => { - const aminoMsg: MsgUndelegate = { + const aminoMsg: LaunchpadMsgUndelegate = { type: "cosmos-sdk/MsgUndelegate", value: { delegator_address: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", @@ -579,7 +578,7 @@ describe("AminoTypes", () => { }, }; const msg = new AminoTypes().fromAmino(aminoMsg); - const expectedValue: IMsgUndelegate = { + const expectedValue: MsgUndelegate = { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", amount: coin(1234, "ucosm"), @@ -624,7 +623,7 @@ describe("AminoTypes", () => { "/my.OverrideType": { aminoType: "cosmos-sdk/MsgDelegate", toAmino: () => {}, - fromAmino: ({ foo }: { readonly foo: string }): IMsgDelegate => ({ + fromAmino: ({ foo }: { readonly foo: string }): MsgDelegate => ({ delegatorAddress: foo, validatorAddress: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", amount: coin(1234, "ucosm"), @@ -637,7 +636,7 @@ describe("AminoTypes", () => { foo: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", }, }); - const expected: { readonly typeUrl: "/my.OverrideType"; readonly value: IMsgDelegate } = { + const expected: { readonly typeUrl: "/my.OverrideType"; readonly value: MsgDelegate } = { typeUrl: "/my.OverrideType", value: { delegatorAddress: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", diff --git a/packages/stargate/src/aminotypes.ts b/packages/stargate/src/aminotypes.ts index 3f7a6978..b79edf93 100644 --- a/packages/stargate/src/aminotypes.ts +++ b/packages/stargate/src/aminotypes.ts @@ -4,36 +4,37 @@ import { decodeBech32Pubkey, encodeBech32Pubkey, Msg, - MsgBeginRedelegate, - MsgCreateValidator, - MsgDelegate, - MsgEditValidator, - MsgFundCommunityPool, - MsgMultiSend, - MsgSend, - MsgSetWithdrawAddress, - MsgUndelegate, - MsgWithdrawDelegatorReward, - MsgWithdrawValidatorCommission, + MsgBeginRedelegate as LaunchpadMsgBeginRedelegate, + MsgCreateValidator as LaunchpadMsgCreateValidator, + MsgDelegate as LaunchpadMsgDelegate, + MsgEditValidator as LaunchpadMsgEditValidator, + MsgFundCommunityPool as LaunchpadMsgFundCommunityPool, + MsgMultiSend as LaunchpadMsgMultiSend, + MsgSend as LaunchpadMsgSend, + MsgSetWithdrawAddress as LaunchpadMsgSetWithdrawAddress, + MsgUndelegate as LaunchpadMsgUndelegate, + MsgWithdrawDelegatorReward as LaunchpadMsgWithdrawDelegatorReward, + MsgWithdrawValidatorCommission as LaunchpadMsgWithdrawValidatorCommission, } from "@cosmjs/launchpad"; import { EncodeObject } from "@cosmjs/proto-signing"; import { assertDefinedAndNotNull } from "@cosmjs/utils"; -import { cosmos } from "./codec"; +import { MsgMultiSend, MsgSend } from "./codec/cosmos/bank/v1beta1/tx"; +import { + MsgFundCommunityPool, + MsgSetWithdrawAddress, + MsgWithdrawDelegatorReward, + MsgWithdrawValidatorCommission, +} from "./codec/cosmos/distribution/v1beta1/tx"; +import { + MsgBeginRedelegate, + MsgCreateValidator, + MsgDelegate, + MsgEditValidator, + MsgUndelegate, +} from "./codec/cosmos/staking/v1beta1/tx"; 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; -type IMsgEditValidator = cosmos.staking.v1beta1.IMsgEditValidator; -type IMsgUndelegate = cosmos.staking.v1beta1.IMsgUndelegate; - export interface AminoConverter { readonly aminoType: string; readonly toAmino: (value: any) => any; @@ -44,7 +45,7 @@ function createDefaultTypes(prefix: string): Record { return { "/cosmos.bank.v1beta1.MsgSend": { aminoType: "cosmos-sdk/MsgSend", - toAmino: ({ fromAddress, toAddress, amount }: IMsgSend): MsgSend["value"] => { + toAmino: ({ fromAddress, toAddress, amount }: MsgSend): LaunchpadMsgSend["value"] => { assertDefinedAndNotNull(fromAddress, "missing fromAddress"); assertDefinedAndNotNull(toAddress, "missing toAddress"); assertDefinedAndNotNull(amount, "missing amount"); @@ -54,7 +55,7 @@ function createDefaultTypes(prefix: string): Record { amount: amount.map(coinFromProto), }; }, - fromAmino: ({ from_address, to_address, amount }: MsgSend["value"]): IMsgSend => ({ + fromAmino: ({ from_address, to_address, amount }: LaunchpadMsgSend["value"]): MsgSend => ({ fromAddress: from_address, toAddress: to_address, amount: [...amount], @@ -62,7 +63,7 @@ function createDefaultTypes(prefix: string): Record { }, "/cosmos.bank.v1beta1.MsgMultiSend": { aminoType: "cosmos-sdk/MsgMultiSend", - toAmino: ({ inputs, outputs }: IMsgMultiSend): MsgMultiSend["value"] => { + toAmino: ({ inputs, outputs }: MsgMultiSend): LaunchpadMsgMultiSend["value"] => { assertDefinedAndNotNull(inputs, "missing inputs"); assertDefinedAndNotNull(outputs, "missing outputs"); return { @@ -84,7 +85,7 @@ function createDefaultTypes(prefix: string): Record { }), }; }, - fromAmino: ({ inputs, outputs }: MsgMultiSend["value"]): IMsgMultiSend => ({ + fromAmino: ({ inputs, outputs }: LaunchpadMsgMultiSend["value"]): MsgMultiSend => ({ inputs: inputs.map((input) => ({ address: input.address, coins: [...input.coins], @@ -97,7 +98,7 @@ function createDefaultTypes(prefix: string): Record { }, "/cosmos.distribution.v1beta1.MsgFundCommunityPool": { aminoType: "cosmos-sdk/MsgFundCommunityPool", - toAmino: ({ amount, depositor }: IMsgFundCommunityPool): MsgFundCommunityPool["value"] => { + toAmino: ({ amount, depositor }: MsgFundCommunityPool): LaunchpadMsgFundCommunityPool["value"] => { assertDefinedAndNotNull(amount); assertDefinedAndNotNull(depositor); return { @@ -105,7 +106,7 @@ function createDefaultTypes(prefix: string): Record { depositor: depositor, }; }, - fromAmino: ({ amount, depositor }: MsgFundCommunityPool["value"]): IMsgFundCommunityPool => ({ + fromAmino: ({ amount, depositor }: LaunchpadMsgFundCommunityPool["value"]): MsgFundCommunityPool => ({ amount: [...amount], depositor: depositor, }), @@ -115,7 +116,7 @@ function createDefaultTypes(prefix: string): Record { toAmino: ({ delegatorAddress, withdrawAddress, - }: IMsgSetWithdrawAddress): MsgSetWithdrawAddress["value"] => { + }: MsgSetWithdrawAddress): LaunchpadMsgSetWithdrawAddress["value"] => { assertDefinedAndNotNull(delegatorAddress); assertDefinedAndNotNull(withdrawAddress); return { @@ -126,7 +127,7 @@ function createDefaultTypes(prefix: string): Record { fromAmino: ({ delegator_address, withdraw_address, - }: MsgSetWithdrawAddress["value"]): IMsgSetWithdrawAddress => ({ + }: LaunchpadMsgSetWithdrawAddress["value"]): MsgSetWithdrawAddress => ({ delegatorAddress: delegator_address, withdrawAddress: withdraw_address, }), @@ -136,7 +137,7 @@ function createDefaultTypes(prefix: string): Record { toAmino: ({ delegatorAddress, validatorAddress, - }: IMsgWithdrawDelegatorReward): MsgWithdrawDelegatorReward["value"] => { + }: MsgWithdrawDelegatorReward): LaunchpadMsgWithdrawDelegatorReward["value"] => { assertDefinedAndNotNull(delegatorAddress); assertDefinedAndNotNull(validatorAddress); return { @@ -147,7 +148,7 @@ function createDefaultTypes(prefix: string): Record { fromAmino: ({ delegator_address, validator_address, - }: MsgWithdrawDelegatorReward["value"]): IMsgWithdrawDelegatorReward => ({ + }: LaunchpadMsgWithdrawDelegatorReward["value"]): MsgWithdrawDelegatorReward => ({ delegatorAddress: delegator_address, validatorAddress: validator_address, }), @@ -156,7 +157,7 @@ function createDefaultTypes(prefix: string): Record { aminoType: "cosmos-sdk/MsgWithdrawValidatorCommission", toAmino: ({ validatorAddress, - }: IMsgWithdrawValidatorCommission): MsgWithdrawValidatorCommission["value"] => { + }: MsgWithdrawValidatorCommission): LaunchpadMsgWithdrawValidatorCommission["value"] => { assertDefinedAndNotNull(validatorAddress); return { validator_address: validatorAddress, @@ -164,7 +165,7 @@ function createDefaultTypes(prefix: string): Record { }, fromAmino: ({ validator_address, - }: MsgWithdrawValidatorCommission["value"]): IMsgWithdrawValidatorCommission => ({ + }: LaunchpadMsgWithdrawValidatorCommission["value"]): MsgWithdrawValidatorCommission => ({ validatorAddress: validator_address, }), }, @@ -175,7 +176,7 @@ function createDefaultTypes(prefix: string): Record { validatorSrcAddress, validatorDstAddress, amount, - }: IMsgBeginRedelegate): MsgBeginRedelegate["value"] => { + }: MsgBeginRedelegate): LaunchpadMsgBeginRedelegate["value"] => { assertDefinedAndNotNull(delegatorAddress, "missing delegatorAddress"); assertDefinedAndNotNull(validatorSrcAddress, "missing validatorSrcAddress"); assertDefinedAndNotNull(validatorDstAddress, "missing validatorDstAddress"); @@ -192,7 +193,7 @@ function createDefaultTypes(prefix: string): Record { validator_src_address, validator_dst_address, amount, - }: MsgBeginRedelegate["value"]): IMsgBeginRedelegate => ({ + }: LaunchpadMsgBeginRedelegate["value"]): MsgBeginRedelegate => ({ delegatorAddress: delegator_address, validatorSrcAddress: validator_src_address, validatorDstAddress: validator_dst_address, @@ -209,7 +210,7 @@ function createDefaultTypes(prefix: string): Record { validatorAddress, pubkey, value, - }: IMsgCreateValidator): MsgCreateValidator["value"] => { + }: MsgCreateValidator): LaunchpadMsgCreateValidator["value"] => { assertDefinedAndNotNull(description, "missing description"); assertDefinedAndNotNull(description.moniker, "missing description.moniker"); assertDefinedAndNotNull(description.identity, "missing description.identity"); @@ -260,7 +261,7 @@ function createDefaultTypes(prefix: string): Record { validator_address, pubkey, value, - }: MsgCreateValidator["value"]): IMsgCreateValidator => { + }: LaunchpadMsgCreateValidator["value"]): MsgCreateValidator => { const decodedPubkey = decodeBech32Pubkey(pubkey); if (decodedPubkey.type !== "tendermint/PubKeySecp256k1") { throw new Error("Only Secp256k1 public keys are supported"); @@ -282,7 +283,7 @@ function createDefaultTypes(prefix: string): Record { delegatorAddress: delegator_address, validatorAddress: validator_address, pubkey: { - type_url: "/cosmos.crypto.secp256k1.PubKey", + typeUrl: "/cosmos.crypto.secp256k1.PubKey", value: fromBase64(decodedPubkey.value), }, value: value, @@ -291,7 +292,11 @@ function createDefaultTypes(prefix: string): Record { }, "/cosmos.staking.v1beta1.MsgDelegate": { aminoType: "cosmos-sdk/MsgDelegate", - toAmino: ({ delegatorAddress, validatorAddress, amount }: IMsgDelegate): MsgDelegate["value"] => { + toAmino: ({ + delegatorAddress, + validatorAddress, + amount, + }: MsgDelegate): LaunchpadMsgDelegate["value"] => { assertDefinedAndNotNull(delegatorAddress, "missing delegatorAddress"); assertDefinedAndNotNull(validatorAddress, "missing validatorAddress"); assertDefinedAndNotNull(amount, "missing amount"); @@ -301,7 +306,11 @@ function createDefaultTypes(prefix: string): Record { amount: coinFromProto(amount), }; }, - fromAmino: ({ delegator_address, validator_address, amount }: MsgDelegate["value"]): IMsgDelegate => ({ + fromAmino: ({ + delegator_address, + validator_address, + amount, + }: LaunchpadMsgDelegate["value"]): MsgDelegate => ({ delegatorAddress: delegator_address, validatorAddress: validator_address, amount: amount, @@ -314,7 +323,7 @@ function createDefaultTypes(prefix: string): Record { commissionRate, minSelfDelegation, validatorAddress, - }: IMsgEditValidator): MsgEditValidator["value"] => { + }: MsgEditValidator): LaunchpadMsgEditValidator["value"] => { assertDefinedAndNotNull(description, "missing description"); assertDefinedAndNotNull(description.moniker, "missing description.moniker"); assertDefinedAndNotNull(description.identity, "missing description.identity"); @@ -342,7 +351,7 @@ function createDefaultTypes(prefix: string): Record { commission_rate, min_self_delegation, validator_address, - }: MsgEditValidator["value"]): IMsgEditValidator => ({ + }: LaunchpadMsgEditValidator["value"]): MsgEditValidator => ({ description: { moniker: description.moniker, identity: description.identity, @@ -357,7 +366,11 @@ function createDefaultTypes(prefix: string): Record { }, "/cosmos.staking.v1beta1.MsgUndelegate": { aminoType: "cosmos-sdk/MsgUndelegate", - toAmino: ({ delegatorAddress, validatorAddress, amount }: IMsgUndelegate): MsgUndelegate["value"] => { + toAmino: ({ + delegatorAddress, + validatorAddress, + amount, + }: MsgUndelegate): LaunchpadMsgUndelegate["value"] => { assertDefinedAndNotNull(delegatorAddress, "missing delegatorAddress"); assertDefinedAndNotNull(validatorAddress, "missing validatorAddress"); assertDefinedAndNotNull(amount, "missing amount"); @@ -371,7 +384,7 @@ function createDefaultTypes(prefix: string): Record { delegator_address, validator_address, amount, - }: MsgUndelegate["value"]): IMsgUndelegate => ({ + }: LaunchpadMsgUndelegate["value"]): MsgUndelegate => ({ delegatorAddress: delegator_address, validatorAddress: validator_address, amount: amount, diff --git a/packages/stargate/src/index.ts b/packages/stargate/src/index.ts index 9f67b26e..240d94dd 100644 --- a/packages/stargate/src/index.ts +++ b/packages/stargate/src/index.ts @@ -1,4 +1,3 @@ -export * as codec from "./codec"; export { AminoConverter, AminoTypes } from "./aminotypes"; export { parseRawLog } from "./logs"; export { diff --git a/packages/stargate/src/queries/auth.spec.ts b/packages/stargate/src/queries/auth.spec.ts index 602b8f29..d1b1a93f 100644 --- a/packages/stargate/src/queries/auth.spec.ts +++ b/packages/stargate/src/queries/auth.spec.ts @@ -4,13 +4,11 @@ import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc"; import { assert } from "@cosmjs/utils"; import Long from "long"; -import { google } from "../codec"; +import { Any } from "../codec/google/protobuf/any"; import { nonExistentAddress, pendingWithoutSimapp, simapp, unused, validator } from "../testutils.spec"; import { AuthExtension, setupAuthExtension } from "./auth"; import { QueryClient } from "./queryclient"; -const { Any } = google.protobuf; - async function makeClientWithAuth(rpcUrl: string): Promise<[QueryClient & AuthExtension, TendermintClient]> { const tmClient = await TendermintClient.connect(rpcUrl, adaptor34); return [QueryClient.withExtensions(tmClient, setupAuthExtension), tmClient]; @@ -28,7 +26,7 @@ describe("AuthExtension", () => { address: unused.address, // pubKey not set accountNumber: Long.fromNumber(unused.accountNumber, true), - // sequence not set + sequence: Long.fromNumber(0), }); tmClient.disconnect(); @@ -43,8 +41,8 @@ describe("AuthExtension", () => { const pubkey = encodePubkey(validator.pubkey); expect(account).toEqual({ address: validator.delegatorAddress, - pubKey: Any.create(pubkey), - // accountNumber not set + pubKey: Any.fromPartial(pubkey), + accountNumber: Long.fromNumber(0), sequence: Long.fromNumber(validator.sequence, true), }); @@ -74,7 +72,7 @@ describe("AuthExtension", () => { address: unused.address, // pubKey not set accountNumber: Long.fromNumber(unused.accountNumber, true), - // sequence not set + sequence: Long.fromNumber(0), }); tmClient.disconnect(); @@ -89,8 +87,8 @@ describe("AuthExtension", () => { const pubkey = encodePubkey(validator.pubkey); expect(account).toEqual({ address: validator.delegatorAddress, - pubKey: Any.create(pubkey), - // accountNumber not set + pubKey: Any.fromPartial(pubkey), + accountNumber: Long.fromNumber(0), sequence: Long.fromNumber(validator.sequence, true), }); diff --git a/packages/stargate/src/queries/auth.ts b/packages/stargate/src/queries/auth.ts index ab23cbf0..b7be82eb 100644 --- a/packages/stargate/src/queries/auth.ts +++ b/packages/stargate/src/queries/auth.ts @@ -1,17 +1,17 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { assert } from "@cosmjs/utils"; -import { cosmos, google } from "../codec"; +import { BaseAccount } from "../codec/cosmos/auth/v1beta1/auth"; +import { QueryClientImpl } from "../codec/cosmos/auth/v1beta1/query"; +import { Any } from "../codec/google/protobuf/any"; import { QueryClient } from "./queryclient"; import { toAccAddress, toObject } from "./utils"; -const { BaseAccount, Query } = cosmos.auth.v1beta1; - export interface AuthExtension { readonly auth: { - readonly account: (address: string) => Promise; + readonly account: (address: string) => Promise; readonly unverified: { - readonly account: (address: string) => Promise; + readonly account: (address: string) => Promise; }; }; } @@ -19,13 +19,12 @@ export interface AuthExtension { export function setupAuthExtension(base: QueryClient): AuthExtension { // Use this service to get easy typed access to query methods // This cannot be used to for proof verification - const queryService = Query.create((method: any, requestData, callback) => { - // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 - const path = `/cosmos.auth.v1beta1.Query/${method.name}`; - base - .queryUnverified(path, requestData) - .then((response) => callback(null, response)) - .catch((error) => callback(error)); + const queryService = new QueryClientImpl({ + request: (service: string, method: string, data: Uint8Array): Promise => { + // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 + const path = `/cosmos.auth.v1beta1.Query/${method}`; + return base.queryUnverified(path, data); + }, }); return { @@ -35,26 +34,26 @@ export function setupAuthExtension(base: QueryClient): AuthExtension { const key = Uint8Array.from([0x01, ...toAccAddress(address)]); const responseData = await base.queryVerified("acc", key); if (responseData.length === 0) return null; - const account = google.protobuf.Any.decode(responseData); - switch (account.type_url) { + const account = Any.decode(responseData); + switch (account.typeUrl) { case "/cosmos.auth.v1beta1.BaseAccount": { return toObject(BaseAccount.decode(account.value)); } default: - throw new Error(`Unsupported type: '${account.type_url}'`); + throw new Error(`Unsupported type: '${account.typeUrl}'`); } }, unverified: { account: async (address: string) => { - const { account } = await queryService.account({ address: address }); + const { account } = await queryService.Account({ address: address }); if (!account) return null; - switch (account.type_url) { + switch (account.typeUrl) { case "/cosmos.auth.v1beta1.BaseAccount": { assert(account.value); return toObject(BaseAccount.decode(account.value)); } default: - throw new Error(`Unsupported type: '${account.type_url}'`); + throw new Error(`Unsupported type: '${account.typeUrl}'`); } }, }, diff --git a/packages/stargate/src/queries/bank.ts b/packages/stargate/src/queries/bank.ts index 8d85da61..cce25b48 100644 --- a/packages/stargate/src/queries/bank.ts +++ b/packages/stargate/src/queries/bank.ts @@ -2,21 +2,19 @@ import { toAscii } from "@cosmjs/encoding"; import { assert } from "@cosmjs/utils"; -import { cosmos } from "../codec"; +import { QueryClientImpl } from "../codec/cosmos/bank/v1beta1/query"; +import { Coin } from "../codec/cosmos/base/v1beta1/coin"; import { QueryClient } from "./queryclient"; import { toAccAddress, toObject } from "./utils"; -const { Coin } = cosmos.base.v1beta1; -const { Query } = cosmos.bank.v1beta1; - export interface BankExtension { readonly bank: { - readonly balance: (address: string, denom: string) => Promise; + readonly balance: (address: string, denom: string) => Promise; readonly unverified: { - readonly balance: (address: string, denom: string) => Promise; - readonly allBalances: (address: string) => Promise; - readonly totalSupply: () => Promise; - readonly supplyOf: (denom: string) => Promise; + readonly balance: (address: string, denom: string) => Promise; + readonly allBalances: (address: string) => Promise; + readonly totalSupply: () => Promise; + readonly supplyOf: (denom: string) => Promise; }; }; } @@ -24,13 +22,12 @@ export interface BankExtension { export function setupBankExtension(base: QueryClient): BankExtension { // Use this service to get easy typed access to query methods // This cannot be used to for proof verification - const queryService = Query.create((method: any, requestData, callback) => { - // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 - const path = `/cosmos.bank.v1beta1.Query/${method.name}`; - base - .queryUnverified(path, requestData) - .then((response) => callback(null, response)) - .catch((error) => callback(error)); + const queryService = new QueryClientImpl({ + request: (service: string, method: string, data: Uint8Array): Promise => { + // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 + const path = `/cosmos.bank.v1beta1.Query/${method}`; + return base.queryUnverified(path, data); + }, }); return { @@ -48,20 +45,20 @@ export function setupBankExtension(base: QueryClient): BankExtension { }, unverified: { balance: async (address: string, denom: string) => { - const { balance } = await queryService.balance({ address: address, denom: denom }); + const { balance } = await queryService.Balance({ address: address, denom: denom }); assert(balance); return toObject(balance); }, allBalances: async (address: string) => { - const { balances } = await queryService.allBalances({ address: address }); + const { balances } = await queryService.AllBalances({ address: address }); return balances.map(toObject); }, totalSupply: async () => { - const { supply } = await queryService.totalSupply({}); + const { supply } = await queryService.TotalSupply({}); return supply.map(toObject); }, supplyOf: async (denom: string) => { - const { amount } = await queryService.supplyOf({ denom: denom }); + const { amount } = await queryService.SupplyOf({ denom: denom }); assert(amount); return toObject(amount); }, diff --git a/packages/stargate/src/queries/distribution.spec.ts b/packages/stargate/src/queries/distribution.spec.ts index 8af17b0d..f4abe689 100644 --- a/packages/stargate/src/queries/distribution.spec.ts +++ b/packages/stargate/src/queries/distribution.spec.ts @@ -4,15 +4,13 @@ import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc"; import { sleep } from "@cosmjs/utils"; -import { cosmos } from "../codec"; +import { MsgDelegate } from "../codec/cosmos/staking/v1beta1/tx"; import { SigningStargateClient } from "../signingstargateclient"; import { assertIsBroadcastTxSuccess } from "../stargateclient"; import { faucet, pendingWithoutSimapp, simapp, simappEnabled, validator } from "../testutils.spec"; import { DistributionExtension, setupDistributionExtension } from "./distribution"; import { QueryClient } from "./queryclient"; -type IMsgDelegate = cosmos.staking.v1beta1.IMsgDelegate; - async function makeClientWithDistribution( rpcUrl: string, ): Promise<[QueryClient & DistributionExtension, TendermintClient]> { @@ -31,7 +29,7 @@ describe("DistributionExtension", () => { const wallet = await DirectSecp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet); - const msg: IMsgDelegate = { + const msg: MsgDelegate = { delegatorAddress: faucet.address0, validatorAddress: validator.validatorAddress, amount: coin(25000, "ustake"), diff --git a/packages/stargate/src/queries/distribution.ts b/packages/stargate/src/queries/distribution.ts index da3c809c..e23354a4 100644 --- a/packages/stargate/src/queries/distribution.ts +++ b/packages/stargate/src/queries/distribution.ts @@ -1,44 +1,43 @@ /* eslint-disable @typescript-eslint/naming-convention */ import Long from "long"; -import { cosmos } from "../codec"; +import { + QueryClientImpl, + QueryCommunityPoolResponse, + QueryDelegationRewardsResponse, + QueryDelegationTotalRewardsResponse, + QueryDelegatorValidatorsResponse, + QueryDelegatorWithdrawAddressResponse, + QueryParamsResponse, + QueryValidatorCommissionResponse, + QueryValidatorOutstandingRewardsResponse, + QueryValidatorSlashesResponse, +} from "../codec/cosmos/distribution/v1beta1/query"; import { QueryClient } from "./queryclient"; -import { toObject } from "./utils"; - -type IQueryCommunityPoolResponse = cosmos.distribution.v1beta1.IQueryCommunityPoolResponse; -type IQueryDelegationRewardsResponse = cosmos.distribution.v1beta1.IQueryDelegationRewardsResponse; -type IQueryDelegationTotalRewardsResponse = cosmos.distribution.v1beta1.IQueryDelegationTotalRewardsResponse; -type IQueryDelegatorValidatorsResponse = cosmos.distribution.v1beta1.IQueryDelegatorValidatorsResponse; -type IQueryDelegatorWithdrawAddressResponse = cosmos.distribution.v1beta1.IQueryDelegatorWithdrawAddressResponse; -type IQueryParamsResponse = cosmos.distribution.v1beta1.IQueryParamsResponse; -type IQueryValidatorCommissionResponse = cosmos.distribution.v1beta1.IQueryValidatorCommissionResponse; -type IQueryValidatorOutstandingRewardsResponse = cosmos.distribution.v1beta1.IQueryValidatorOutstandingRewardsResponse; -type IQueryValidatorSlashesResponse = cosmos.distribution.v1beta1.IQueryValidatorSlashesResponse; - -const { Query } = cosmos.distribution.v1beta1; +import { createPagination, toObject } from "./utils"; export interface DistributionExtension { readonly distribution: { unverified: { - communityPool: () => Promise; + communityPool: () => Promise; delegationRewards: ( delegatorAddress: string, validatorAddress: string, - ) => Promise; - delegationTotalRewards: (delegatorAddress: string) => Promise; - delegatorValidators: (delegatorAddress: string) => Promise; - delegatorWithdrawAddress: (delegatorAddress: string) => Promise; - params: () => Promise; - validatorCommission: (validatorAddress: string) => Promise; + ) => Promise; + delegationTotalRewards: (delegatorAddress: string) => Promise; + delegatorValidators: (delegatorAddress: string) => Promise; + delegatorWithdrawAddress: (delegatorAddress: string) => Promise; + params: () => Promise; + validatorCommission: (validatorAddress: string) => Promise; validatorOutstandingRewards: ( validatorAddress: string, - ) => Promise; + ) => Promise; validatorSlashes: ( validatorAddress: string, startingHeight: number, endingHeight: number, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; }; }; } @@ -46,58 +45,57 @@ export interface DistributionExtension { export function setupDistributionExtension(base: QueryClient): DistributionExtension { // Use this service to get easy typed access to query methods // This cannot be used to for proof verification - const queryService = Query.create((method: any, requestData, callback) => { - // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 - const path = `/cosmos.distribution.v1beta1.Query/${method.name}`; - base - .queryUnverified(path, requestData) - .then((response) => callback(null, response)) - .catch((error) => callback(error)); + const queryService = new QueryClientImpl({ + request: (service: string, method: string, data: Uint8Array): Promise => { + // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 + const path = `/cosmos.distribution.v1beta1.Query/${method}`; + return base.queryUnverified(path, data); + }, }); return { distribution: { unverified: { communityPool: async () => { - const response = await queryService.communityPool({}); + const response = await queryService.CommunityPool({}); return toObject(response); }, delegationRewards: async (delegatorAddress: string, validatorAddress: string) => { - const response = await queryService.delegationRewards({ + const response = await queryService.DelegationRewards({ delegatorAddress: delegatorAddress, validatorAddress: validatorAddress, }); return toObject(response); }, delegationTotalRewards: async (delegatorAddress: string) => { - const response = await queryService.delegationTotalRewards({ + const response = await queryService.DelegationTotalRewards({ delegatorAddress: delegatorAddress, }); return toObject(response); }, delegatorValidators: async (delegatorAddress: string) => { - const response = await queryService.delegatorValidators({ + const response = await queryService.DelegatorValidators({ delegatorAddress: delegatorAddress, }); return toObject(response); }, delegatorWithdrawAddress: async (delegatorAddress: string) => { - const response = await queryService.delegatorWithdrawAddress({ + const response = await queryService.DelegatorWithdrawAddress({ delegatorAddress: delegatorAddress, }); return toObject(response); }, params: async () => { - const response = await queryService.params({}); + const response = await queryService.Params({}); return toObject(response); }, validatorCommission: async (validatorAddress: string) => { - const response = await queryService.validatorCommission({ + const response = await queryService.ValidatorCommission({ validatorAddress: validatorAddress, }); return toObject(response); }, validatorOutstandingRewards: async (validatorAddress: string) => { - const response = await queryService.validatorOutstandingRewards({ + const response = await queryService.ValidatorOutstandingRewards({ validatorAddress: validatorAddress, }); return toObject(response); @@ -108,11 +106,11 @@ export function setupDistributionExtension(base: QueryClient): DistributionExten endingHeight: number, paginationKey?: Uint8Array, ) => { - const response = await queryService.validatorSlashes({ + const response = await queryService.ValidatorSlashes({ validatorAddress: validatorAddress, startingHeight: Long.fromNumber(startingHeight), endingHeight: Long.fromNumber(endingHeight), - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }); return toObject(response); }, diff --git a/packages/stargate/src/queries/ibc.spec.ts b/packages/stargate/src/queries/ibc.spec.ts index 16c46057..3b1d4ceb 100644 --- a/packages/stargate/src/queries/ibc.spec.ts +++ b/packages/stargate/src/queries/ibc.spec.ts @@ -1,7 +1,6 @@ import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc"; import Long from "long"; -import { cosmos, ibc } from "../codec"; import { pendingWithoutSimapp, simapp } from "../testutils.spec"; import { IbcExtension, setupIbcExtension } from "./ibc"; import * as ibcTest from "./ibctestdata.spec"; @@ -21,7 +20,8 @@ describe("IbcExtension", () => { const response = await client.ibc.unverified.channel(ibcTest.portId, ibcTest.channelId); expect(response.channel).toEqual(ibcTest.channel); - expect(response.proofHeight).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); tmClient.disconnect(); }); @@ -34,8 +34,10 @@ describe("IbcExtension", () => { const response = await client.ibc.unverified.channels(); expect(response.channels).toEqual([ibcTest.identifiedChannel]); - expect(response.pagination).toBeInstanceOf(cosmos.base.query.v1beta1.PageResponse); - expect(response.height).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.pagination).toBeDefined(); + expect(response.pagination).not.toBeNull(); + expect(response.height).toBeDefined(); + expect(response.height).not.toBeNull(); tmClient.disconnect(); }); @@ -48,8 +50,10 @@ describe("IbcExtension", () => { const response = await client.ibc.unverified.connectionChannels(ibcTest.connectionId); expect(response.channels).toEqual([ibcTest.identifiedChannel]); - expect(response.pagination).toBeInstanceOf(cosmos.base.query.v1beta1.PageResponse); - expect(response.height).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.pagination).toBeDefined(); + expect(response.pagination).not.toBeNull(); + expect(response.height).toBeDefined(); + expect(response.height).not.toBeNull(); tmClient.disconnect(); }); @@ -66,7 +70,8 @@ describe("IbcExtension", () => { ibcTest.commitment.sequence, ); expect(response.commitment).toEqual(ibcTest.commitment.data); - expect(response.proofHeight).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); tmClient.disconnect(); }); @@ -79,8 +84,10 @@ describe("IbcExtension", () => { const response = await client.ibc.unverified.packetCommitments(ibcTest.portId, ibcTest.channelId); expect(response.commitments).toEqual([ibcTest.packetState]); - expect(response.pagination).toBeInstanceOf(cosmos.base.query.v1beta1.PageResponse); - expect(response.height).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.pagination).toBeDefined(); + expect(response.pagination).not.toBeNull(); + expect(response.height).toBeDefined(); + expect(response.height).not.toBeNull(); tmClient.disconnect(); }); @@ -98,7 +105,8 @@ describe("IbcExtension", () => { ibcTest.commitment.sequence, ); expect(response.acknowledgement).toEqual(ibcTest.packetAcknowledgements[0].data); - expect(response.proofHeight).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); tmClient.disconnect(); }); @@ -114,8 +122,10 @@ describe("IbcExtension", () => { ibcTest.channelId, ); expect(response.acknowledgements).toEqual(ibcTest.packetAcknowledgements); - expect(response.pagination).toBeInstanceOf(cosmos.base.query.v1beta1.PageResponse); - expect(response.height).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.pagination).toBeDefined(); + expect(response.pagination).not.toBeNull(); + expect(response.height).toBeDefined(); + expect(response.height).not.toBeNull(); tmClient.disconnect(); }); @@ -132,7 +142,8 @@ describe("IbcExtension", () => { 3, ]); expect(response.sequences).toEqual([1, 2, 3].map((n) => Long.fromInt(n, true))); - expect(response.height).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.height).toBeDefined(); + expect(response.height).not.toBeNull(); tmClient.disconnect(); }); @@ -153,7 +164,8 @@ describe("IbcExtension", () => { 7, ]); expect(response.sequences).toEqual([Long.fromInt(ibcTest.commitment.sequence, true)]); - expect(response.height).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.height).toBeDefined(); + expect(response.height).not.toBeNull(); tmClient.disconnect(); }); @@ -166,7 +178,8 @@ describe("IbcExtension", () => { const response = await client.ibc.unverified.nextSequenceReceive(ibcTest.portId, ibcTest.channelId); expect(response.nextSequenceReceive).toEqual(Long.fromInt(1, true)); - expect(response.proofHeight).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); tmClient.disconnect(); }); @@ -181,7 +194,8 @@ describe("IbcExtension", () => { const response = await client.ibc.unverified.connection(ibcTest.connectionId); expect(response.connection).toEqual(ibcTest.connection); - expect(response.proofHeight).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); tmClient.disconnect(); }); @@ -194,8 +208,10 @@ describe("IbcExtension", () => { const response = await client.ibc.unverified.connections(); expect(response.connections).toEqual([ibcTest.identifiedConnection]); - expect(response.pagination).toBeInstanceOf(cosmos.base.query.v1beta1.PageResponse); - expect(response.height).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.pagination).toBeDefined(); + expect(response.pagination).not.toBeNull(); + expect(response.height).toBeDefined(); + expect(response.height).not.toBeNull(); tmClient.disconnect(); }); @@ -208,7 +224,8 @@ describe("IbcExtension", () => { const response = await client.ibc.unverified.clientConnections(ibcTest.clientId); expect(response.connectionPaths).toEqual([ibcTest.connectionId]); - expect(response.proofHeight).toBeInstanceOf(ibc.core.client.v1.Height); + expect(response.proofHeight).toBeDefined(); + expect(response.proofHeight).not.toBeNull(); tmClient.disconnect(); }); diff --git a/packages/stargate/src/queries/ibc.ts b/packages/stargate/src/queries/ibc.ts index 0996fe78..581323ee 100644 --- a/packages/stargate/src/queries/ibc.ts +++ b/packages/stargate/src/queries/ibc.ts @@ -3,16 +3,32 @@ import { toAscii } from "@cosmjs/encoding"; import { Uint64 } from "@cosmjs/math"; import Long from "long"; -import { ibc } from "../codec"; +import { Channel } from "../codec/ibc/core/channel/v1/channel"; +import { + QueryChannelResponse, + QueryChannelsResponse, + QueryClientImpl as ChannelQuery, + QueryConnectionChannelsResponse, + QueryNextSequenceReceiveResponse, + QueryPacketAcknowledgementResponse, + QueryPacketAcknowledgementsResponse, + QueryPacketCommitmentResponse, + QueryPacketCommitmentsResponse, + QueryUnreceivedAcksResponse, + QueryUnreceivedPacketsResponse, +} from "../codec/ibc/core/channel/v1/query"; +import { + QueryClientConnectionsResponse, + QueryClientImpl as ConnectionQuery, + QueryConnectionResponse, + QueryConnectionsResponse, +} from "../codec/ibc/core/connection/v1/query"; import { QueryClient } from "./queryclient"; -import { toObject } from "./utils"; - -const { Query: ChannelQuery } = ibc.core.channel.v1; -const { Query: ConnectionQuery } = ibc.core.connection.v1; +import { createPagination, toObject } from "./utils"; export interface IbcExtension { readonly ibc: { - readonly channel: (portId: string, channelId: string) => Promise; + readonly channel: (portId: string, channelId: string) => Promise; readonly packetCommitment: (portId: string, channelId: string, sequence: number) => Promise; readonly packetAcknowledgement: ( portId: string, @@ -22,59 +38,52 @@ export interface IbcExtension { readonly nextSequenceReceive: (portId: string, channelId: string) => Promise; readonly unverified: { // Queries for ibc.core.channel.v1 - readonly channel: ( - portId: string, - channelId: string, - ) => Promise; - readonly channels: (paginationKey?: Uint8Array) => Promise; + readonly channel: (portId: string, channelId: string) => Promise; + readonly channels: (paginationKey?: Uint8Array) => Promise; readonly connectionChannels: ( connection: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; readonly packetCommitment: ( portId: string, channelId: string, sequence: number, - ) => Promise; + ) => Promise; readonly packetCommitments: ( portId: string, channelId: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; readonly packetAcknowledgement: ( portId: string, channelId: string, sequence: number, - ) => Promise; + ) => Promise; readonly packetAcknowledgements: ( portId: string, channelId: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; readonly unreceivedPackets: ( portId: string, channelId: string, packetCommitmentSequences: readonly number[], - ) => Promise; + ) => Promise; readonly unreceivedAcks: ( portId: string, channelId: string, packetCommitmentSequences: readonly number[], - ) => Promise; + ) => Promise; readonly nextSequenceReceive: ( portId: string, channelId: string, - ) => Promise; + ) => Promise; // Queries for ibc.core.connection.v1 - readonly connection: (connectionId: string) => Promise; - readonly connections: ( - paginationKey?: Uint8Array, - ) => Promise; - readonly clientConnections: ( - clientId: string, - ) => Promise; + readonly connection: (connectionId: string) => Promise; + readonly connections: (paginationKey?: Uint8Array) => Promise; + readonly clientConnections: (clientId: string) => Promise; }; }; } @@ -83,22 +92,20 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { // Use this service to get easy typed access to query methods // This cannot be used to for proof verification - const channelQueryService = ChannelQuery.create((method: any, requestData, callback) => { - // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 - const path = `/ibc.core.channel.v1.Query/${method.name}`; - base - .queryUnverified(path, requestData) - .then((response) => callback(null, response)) - .catch((error) => callback(error)); + const channelQueryService = new ChannelQuery({ + request: (service: string, method: string, data: Uint8Array): Promise => { + // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 + const path = `/Query/${method}`; + return base.queryUnverified(path, data); + }, }); - const connectionQueryService = ConnectionQuery.create((method: any, requestData, callback) => { - // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 - const path = `/ibc.core.connection.v1.Query/${method.name}`; - base - .queryUnverified(path, requestData) - .then((response) => callback(null, response)) - .catch((error) => callback(error)); + const connectionQueryService = new ConnectionQuery({ + request: (service: string, method: string, data: Uint8Array): Promise => { + // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 + const path = `/ibc.core.connection.v1.Query/${method}`; + return base.queryUnverified(path, data); + }, }); return { @@ -108,7 +115,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { // key: https://github.com/cosmos/cosmos-sdk/blob/ef0a7344af345882729598bc2958a21143930a6b/x/ibc/24-host/keys.go#L117-L120 const key = toAscii(`channelEnds/ports/${portId}/channels/${channelId}`); const responseData = await base.queryVerified("ibc", key); - return responseData.length ? toObject(ibc.core.channel.v1.Channel.decode(responseData)) : null; + return responseData.length ? toObject(Channel.decode(responseData)) : null; }, packetCommitment: async (portId: string, channelId: string, sequence: number) => { // keeper: https://github.com/cosmos/cosmos-sdk/blob/3bafd8255a502e5a9cee07391cf8261538245dfd/x/ibc/04-channel/keeper/keeper.go#L128-L133 @@ -137,26 +144,26 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { unverified: { // Queries for ibc.core.channel.v1 channel: async (portId: string, channelId: string) => { - const response = await channelQueryService.channel({ portId: portId, channelId: channelId }); + const response = await channelQueryService.Channel({ portId: portId, channelId: channelId }); return toObject(response); }, channels: async (paginationKey?: Uint8Array) => { const request = { - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }; - const response = await channelQueryService.channels(request); + const response = await channelQueryService.Channels(request); return toObject(response); }, connectionChannels: async (connection: string, paginationKey?: Uint8Array) => { const request = { connection: connection, - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }; - const response = await channelQueryService.connectionChannels(request); + const response = await channelQueryService.ConnectionChannels(request); return toObject(response); }, packetCommitment: async (portId: string, channelId: string, sequence: number) => { - const response = await channelQueryService.packetCommitment({ + const response = await channelQueryService.PacketCommitment({ portId: portId, channelId: channelId, sequence: Long.fromNumber(sequence), @@ -167,13 +174,13 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { const request = { channelId: channelId, portId: portId, - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }; - const response = await channelQueryService.packetCommitments(request); + const response = await channelQueryService.PacketCommitments(request); return toObject(response); }, packetAcknowledgement: async (portId: string, channelId: string, sequence: number) => { - const response = await channelQueryService.packetAcknowledgement({ + const response = await channelQueryService.PacketAcknowledgement({ portId: portId, channelId: channelId, sequence: Long.fromNumber(sequence), @@ -181,10 +188,10 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { return toObject(response); }, packetAcknowledgements: async (portId: string, channelId: string, paginationKey?: Uint8Array) => { - const response = await channelQueryService.packetAcknowledgements({ + const response = await channelQueryService.PacketAcknowledgements({ portId: portId, channelId: channelId, - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }); return toObject(response); }, @@ -193,7 +200,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { channelId: string, packetCommitmentSequences: readonly number[], ) => { - const response = await channelQueryService.unreceivedPackets({ + const response = await channelQueryService.UnreceivedPackets({ portId: portId, channelId: channelId, packetCommitmentSequences: packetCommitmentSequences.map((s) => Long.fromNumber(s)), @@ -201,7 +208,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { return toObject(response); }, unreceivedAcks: async (portId: string, channelId: string, packetAckSequences: readonly number[]) => { - const response = await channelQueryService.unreceivedAcks({ + const response = await channelQueryService.UnreceivedAcks({ portId: portId, channelId: channelId, packetAckSequences: packetAckSequences.map((s) => Long.fromNumber(s)), @@ -209,7 +216,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { return toObject(response); }, nextSequenceReceive: async (portId: string, channelId: string) => { - const response = await channelQueryService.nextSequenceReceive({ + const response = await channelQueryService.NextSequenceReceive({ portId: portId, channelId: channelId, }); @@ -219,18 +226,18 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { // Queries for ibc.core.connection.v1 connection: async (connectionId: string) => { - const response = await connectionQueryService.connection({ connectionId: connectionId }); + const response = await connectionQueryService.Connection({ connectionId: connectionId }); return toObject(response); }, connections: async (paginationKey?: Uint8Array) => { const request = { - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }; - const response = await connectionQueryService.connections(request); + const response = await connectionQueryService.Connections(request); return toObject(response); }, clientConnections: async (clientId: string) => { - const response = await connectionQueryService.clientConnections({ clientId: clientId }); + const response = await connectionQueryService.ClientConnections({ clientId: clientId }); return toObject(response); }, }, diff --git a/packages/stargate/src/queries/ibctestdata.spec.ts b/packages/stargate/src/queries/ibctestdata.spec.ts index 1e3c48eb..ae840c1c 100644 --- a/packages/stargate/src/queries/ibctestdata.spec.ts +++ b/packages/stargate/src/queries/ibctestdata.spec.ts @@ -1,7 +1,22 @@ import { fromBase64 } from "@cosmjs/encoding"; import Long from "long"; -import { ibc } from "../codec"; +import { + Channel, + Counterparty as ChannelCounterparty, + IdentifiedChannel, + Order, + PacketState, + State as ChannelState, +} from "../codec/ibc/core/channel/v1/channel"; +import { MerklePrefix } from "../codec/ibc/core/commitment/v1/commitment"; +import { + ConnectionEnd, + Counterparty as ConnectionCounterparty, + IdentifiedConnection, + State as ConnectionState, + Version, +} from "../codec/ibc/core/connection/v1/connection"; // From scripts/simapp/genesis-ibc.json @@ -10,10 +25,10 @@ export const channelId = "channel-0"; export const connectionId = "connection-0"; export const clientId = "07-tendermint-0"; -export const channel = ibc.core.channel.v1.Channel.create({ - state: ibc.core.channel.v1.State.STATE_OPEN, - ordering: ibc.core.channel.v1.Order.ORDER_UNORDERED, - counterparty: ibc.core.channel.v1.Counterparty.create({ +export const channel = Channel.fromPartial({ + state: ChannelState.STATE_OPEN, + ordering: Order.ORDER_UNORDERED, + counterparty: ChannelCounterparty.fromPartial({ portId: portId, channelId: channelId, }), @@ -21,10 +36,10 @@ export const channel = ibc.core.channel.v1.Channel.create({ version: "ics20-1", }); -export const identifiedChannel = ibc.core.channel.v1.IdentifiedChannel.create({ - state: ibc.core.channel.v1.State.STATE_OPEN, - ordering: ibc.core.channel.v1.Order.ORDER_UNORDERED, - counterparty: ibc.core.channel.v1.Counterparty.create({ +export const identifiedChannel = IdentifiedChannel.fromPartial({ + state: ChannelState.STATE_OPEN, + ordering: Order.ORDER_UNORDERED, + counterparty: ChannelCounterparty.fromPartial({ portId: portId, channelId: "channel-0", }), @@ -44,7 +59,7 @@ export const commitment = { data: fromBase64("hYz5Dx6o09DcSEWZR6xlJYwLgYUnLithsXMGtujic4I="), }; -export const packetState = ibc.core.channel.v1.PacketState.create({ +export const packetState = PacketState.fromPartial({ portId: portId, channelId: channelId, sequence: Long.fromInt(commitment.sequence, true), @@ -58,40 +73,40 @@ export const packetState = ibc.core.channel.v1.PacketState.create({ * jq ".channel_genesis.acknowledgements" scripts/simapp/genesis-ibc.json * ``` */ -export const packetAcknowledgements: ibc.core.channel.v1.PacketState[] = []; +export const packetAcknowledgements: PacketState[] = []; -export const connection = ibc.core.connection.v1.ConnectionEnd.create({ +export const connection = ConnectionEnd.fromPartial({ clientId: clientId, versions: [ - ibc.core.connection.v1.Version.create({ + Version.fromPartial({ identifier: "1", features: ["ORDER_ORDERED", "ORDER_UNORDERED"], }), ], - state: ibc.core.connection.v1.State.STATE_OPEN, - counterparty: ibc.core.connection.v1.Counterparty.create({ + state: ConnectionState.STATE_OPEN, + counterparty: ConnectionCounterparty.fromPartial({ clientId: "07-tendermint-0", connectionId: "connection-0", - prefix: ibc.core.commitment.v1.MerklePrefix.create({ + prefix: MerklePrefix.fromPartial({ keyPrefix: fromBase64("aWJj"), }), }), }); -export const identifiedConnection = ibc.core.connection.v1.IdentifiedConnection.create({ +export const identifiedConnection = IdentifiedConnection.fromPartial({ id: connectionId, clientId: clientId, versions: [ - ibc.core.connection.v1.Version.create({ + Version.fromPartial({ identifier: "1", features: ["ORDER_ORDERED", "ORDER_UNORDERED"], }), ], - state: ibc.core.connection.v1.State.STATE_OPEN, - counterparty: ibc.core.connection.v1.Counterparty.create({ + state: ConnectionState.STATE_OPEN, + counterparty: ConnectionCounterparty.fromPartial({ clientId: "07-tendermint-0", connectionId: "connection-0", - prefix: ibc.core.commitment.v1.MerklePrefix.create({ + prefix: MerklePrefix.fromPartial({ keyPrefix: fromBase64("aWJj"), }), }), diff --git a/packages/stargate/src/queries/queryclient.spec.ts b/packages/stargate/src/queries/queryclient.spec.ts index 2f75e4e4..9b3ea90d 100644 --- a/packages/stargate/src/queries/queryclient.spec.ts +++ b/packages/stargate/src/queries/queryclient.spec.ts @@ -2,14 +2,12 @@ import { toAscii } from "@cosmjs/encoding"; import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc"; -import { cosmos } from "../codec"; +import { QueryAllBalancesRequest, QueryAllBalancesResponse } from "../codec/cosmos/bank/v1beta1/query"; +import { Coin } from "../codec/cosmos/base/v1beta1/coin"; import { nonNegativeIntegerMatcher, pendingWithoutSimapp, simapp, unused } from "../testutils.spec"; import { QueryClient } from "./queryclient"; import { toAccAddress } from "./utils"; -const { Coin } = cosmos.base.v1beta1; -const { QueryAllBalancesRequest, QueryAllBalancesResponse } = cosmos.bank.v1beta1; - async function makeClient(rpcUrl: string): Promise<[QueryClient, TendermintClient]> { const tmClient = await TendermintClient.connect(rpcUrl, adaptor34); return [QueryClient.withExtensions(tmClient), tmClient]; diff --git a/packages/stargate/src/queries/staking.spec.ts b/packages/stargate/src/queries/staking.spec.ts index 363a7e71..e3bdd5af 100644 --- a/packages/stargate/src/queries/staking.spec.ts +++ b/packages/stargate/src/queries/staking.spec.ts @@ -4,16 +4,13 @@ import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"; import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc"; import { sleep } from "@cosmjs/utils"; -import { cosmos } from "../codec"; +import { MsgDelegate, MsgUndelegate } from "../codec/cosmos/staking/v1beta1/tx"; import { SigningStargateClient } from "../signingstargateclient"; import { assertIsBroadcastTxSuccess } from "../stargateclient"; import { faucet, pendingWithoutSimapp, simapp, simappEnabled, validator } from "../testutils.spec"; import { QueryClient } from "./queryclient"; import { setupStakingExtension, StakingExtension } from "./staking"; -type IMsgDelegate = cosmos.staking.v1beta1.IMsgDelegate; -type IMsgUndelegate = cosmos.staking.v1beta1.IMsgUndelegate; - async function makeClientWithStaking( rpcUrl: string, ): Promise<[QueryClient & StakingExtension, TendermintClient]> { @@ -33,7 +30,7 @@ describe("StakingExtension", () => { const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet); { - const msg: IMsgDelegate = { + const msg: MsgDelegate = { delegatorAddress: faucet.address0, validatorAddress: validator.validatorAddress, amount: coin(25000, "ustake"), @@ -47,7 +44,7 @@ describe("StakingExtension", () => { assertIsBroadcastTxSuccess(result); } { - const msg: IMsgUndelegate = { + const msg: MsgUndelegate = { delegatorAddress: faucet.address0, validatorAddress: validator.validatorAddress, amount: coin(100, "ustake"), diff --git a/packages/stargate/src/queries/staking.ts b/packages/stargate/src/queries/staking.ts index 0f40c036..d434e052 100644 --- a/packages/stargate/src/queries/staking.ts +++ b/packages/stargate/src/queries/staking.ts @@ -1,74 +1,72 @@ /* eslint-disable @typescript-eslint/naming-convention */ import Long from "long"; -import { cosmos } from "../codec"; +import { + QueryClientImpl, + QueryDelegationResponse, + QueryDelegatorDelegationsResponse, + QueryDelegatorUnbondingDelegationsResponse, + QueryDelegatorValidatorResponse, + QueryDelegatorValidatorsResponse, + QueryHistoricalInfoResponse, + QueryParamsResponse, + QueryPoolResponse, + QueryRedelegationsResponse, + QueryUnbondingDelegationResponse, + QueryValidatorDelegationsResponse, + QueryValidatorResponse, + QueryValidatorsResponse, + QueryValidatorUnbondingDelegationsResponse, +} from "../codec/cosmos/staking/v1beta1/query"; +import { BondStatus } from "../codec/cosmos/staking/v1beta1/staking"; import { QueryClient } from "./queryclient"; -import { toObject } from "./utils"; - -type IQueryDelegationResponse = cosmos.staking.v1beta1.IQueryDelegationResponse; -type IQueryDelegatorDelegationsResponse = cosmos.staking.v1beta1.IQueryDelegatorDelegationsResponse; -type IQueryDelegatorUnbondingDelegationsResponse = cosmos.staking.v1beta1.IQueryDelegatorUnbondingDelegationsResponse; -type IQueryDelegatorValidatorResponse = cosmos.staking.v1beta1.IQueryDelegatorValidatorResponse; -type IQueryDelegatorValidatorsResponse = cosmos.staking.v1beta1.IQueryDelegatorValidatorsResponse; -type IQueryHistoricalInfoResponse = cosmos.staking.v1beta1.IQueryHistoricalInfoResponse; -type IQueryParamsResponse = cosmos.staking.v1beta1.IQueryParamsResponse; -type IQueryPoolResponse = cosmos.staking.v1beta1.IQueryPoolResponse; -type IQueryRedelegationsResponse = cosmos.staking.v1beta1.IQueryRedelegationsResponse; -type IQueryUnbondingDelegationResponse = cosmos.staking.v1beta1.IQueryUnbondingDelegationResponse; -type IQueryValidatorResponse = cosmos.staking.v1beta1.IQueryValidatorResponse; -type IQueryValidatorDelegationsResponse = cosmos.staking.v1beta1.IQueryValidatorDelegationsResponse; -type IQueryValidatorsResponse = cosmos.staking.v1beta1.IQueryValidatorsResponse; -type IQueryValidatorUnbondingDelegationsResponse = cosmos.staking.v1beta1.IQueryValidatorUnbondingDelegationsResponse; - -// This needs to be exported otherwise TS won’t let you export BondStatusString -export const { BondStatus } = cosmos.staking.v1beta1; -const { Query } = cosmos.staking.v1beta1; +import { createPagination, toObject } from "./utils"; export type BondStatusString = Exclude; export interface StakingExtension { readonly staking: { readonly unverified: { - delegation: (delegatorAddress: string, validatorAddress: string) => Promise; + delegation: (delegatorAddress: string, validatorAddress: string) => Promise; delegatorDelegations: ( delegatorAddress: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; delegatorUnbondingDelegations: ( delegatorAddress: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; delegatorValidator: ( delegatorAddress: string, validatorAddress: string, - ) => Promise; + ) => Promise; delegatorValidators: ( delegatorAddress: string, paginationKey?: Uint8Array, - ) => Promise; - historicalInfo: (height: number) => Promise; - params: () => Promise; - pool: () => Promise; + ) => Promise; + historicalInfo: (height: number) => Promise; + params: () => Promise; + pool: () => Promise; redelegations: ( delegatorAddress: string, sourceValidatorAddress: string, destinationValidatorAddress: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; unbondingDelegation: ( delegatorAddress: string, validatorAddress: string, - ) => Promise; - validator: (validatorAddress: string) => Promise; + ) => Promise; + validator: (validatorAddress: string) => Promise; validatorDelegations: ( validatorAddress: string, paginationKey?: Uint8Array, - ) => Promise; - validators: (status: BondStatusString, paginationKey?: Uint8Array) => Promise; + ) => Promise; + validators: (status: BondStatusString, paginationKey?: Uint8Array) => Promise; validatorUnbondingDelegations: ( validatorAddress: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; }; }; } @@ -76,65 +74,64 @@ export interface StakingExtension { export function setupStakingExtension(base: QueryClient): StakingExtension { // Use this service to get easy typed access to query methods // This cannot be used to for proof verification - const queryService = Query.create((method: any, requestData, callback) => { - // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 - const path = `/cosmos.staking.v1beta1.Query/${method.name}`; - base - .queryUnverified(path, requestData) - .then((response) => callback(null, response)) - .catch((error) => callback(error)); + const queryService = new QueryClientImpl({ + request: (service: "string", method: string, data: Uint8Array): Promise => { + // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 + const path = `/cosmos.staking.v1beta1.Query/${method}`; + return base.queryUnverified(path, data); + }, }); return { staking: { unverified: { delegation: async (delegatorAddress: string, validatorAddress: string) => { - const response = await queryService.delegation({ + const response = await queryService.Delegation({ delegatorAddr: delegatorAddress, validatorAddr: validatorAddress, }); return toObject(response); }, delegatorDelegations: async (delegatorAddress: string, paginationKey?: Uint8Array) => { - const response = await queryService.delegatorDelegations({ + const response = await queryService.DelegatorDelegations({ delegatorAddr: delegatorAddress, - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }); return toObject(response); }, delegatorUnbondingDelegations: async (delegatorAddress: string, paginationKey?: Uint8Array) => { - const response = await queryService.delegatorUnbondingDelegations({ + const response = await queryService.DelegatorUnbondingDelegations({ delegatorAddr: delegatorAddress, - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }); return toObject(response); }, delegatorValidator: async (delegatorAddress: string, validatorAddress: string) => { - const response = await queryService.delegatorValidator({ + const response = await queryService.DelegatorValidator({ delegatorAddr: delegatorAddress, validatorAddr: validatorAddress, }); return toObject(response); }, delegatorValidators: async (delegatorAddress: string, paginationKey?: Uint8Array) => { - const response = await queryService.delegatorValidators({ + const response = await queryService.DelegatorValidators({ delegatorAddr: delegatorAddress, - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }); return toObject(response); }, historicalInfo: async (height: number) => { - const response = await queryService.historicalInfo({ + const response = await queryService.HistoricalInfo({ height: Long.fromNumber(height), }); return toObject(response); }, params: async () => { - const response = await queryService.params({}); + const response = await queryService.Params({}); return toObject(response); }, pool: async () => { - const response = await queryService.pool({}); + const response = await queryService.Pool({}); return toObject(response); }, redelegations: async ( @@ -143,43 +140,43 @@ export function setupStakingExtension(base: QueryClient): StakingExtension { destinationValidatorAddress: string, paginationKey?: Uint8Array, ) => { - const response = await queryService.redelegations({ + const response = await queryService.Redelegations({ delegatorAddr: delegatorAddress, srcValidatorAddr: sourceValidatorAddress, dstValidatorAddr: destinationValidatorAddress, - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }); return toObject(response); }, unbondingDelegation: async (delegatorAddress: string, validatorAddress: string) => { - const response = await queryService.unbondingDelegation({ + const response = await queryService.UnbondingDelegation({ delegatorAddr: delegatorAddress, validatorAddr: validatorAddress, }); return toObject(response); }, validator: async (validatorAddress: string) => { - const response = await queryService.validator({ validatorAddr: validatorAddress }); + const response = await queryService.Validator({ validatorAddr: validatorAddress }); return toObject(response); }, validatorDelegations: async (validatorAddress: string, paginationKey?: Uint8Array) => { - const response = await queryService.validatorDelegations({ + const response = await queryService.ValidatorDelegations({ validatorAddr: validatorAddress, - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }); return toObject(response); }, validators: async (status: BondStatusString, paginationKey?: Uint8Array) => { - const response = await queryService.validators({ + const response = await queryService.Validators({ status: status, - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }); return toObject(response); }, validatorUnbondingDelegations: async (validatorAddress: string, paginationKey?: Uint8Array) => { - const response = await queryService.validatorUnbondingDelegations({ + const response = await queryService.ValidatorUnbondingDelegations({ validatorAddr: validatorAddress, - pagination: paginationKey ? { key: paginationKey } : undefined, + pagination: createPagination(paginationKey), }); return toObject(response); }, diff --git a/packages/stargate/src/queries/utils.ts b/packages/stargate/src/queries/utils.ts index 0466765e..c7ffb923 100644 --- a/packages/stargate/src/queries/utils.ts +++ b/packages/stargate/src/queries/utils.ts @@ -1,4 +1,5 @@ import { Bech32 } from "@cosmjs/encoding"; +import Long from "long"; /** * Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded. @@ -17,3 +18,19 @@ export function toAccAddress(address: string): Uint8Array { export function toObject(thing: I): Omit { return { ...thing }; } + +export function createPagination( + paginationKey?: Uint8Array, +): { + readonly key: Uint8Array; + readonly offset: Long; + readonly limit: Long; + readonly countTotal: boolean; +} { + return { + key: paginationKey ?? new Uint8Array(), + offset: Long.fromNumber(0), + limit: Long.fromNumber(0), + countTotal: false, + }; +} diff --git a/packages/stargate/src/signingstargateclient.spec.ts b/packages/stargate/src/signingstargateclient.spec.ts index 3753be49..abf3714f 100644 --- a/packages/stargate/src/signingstargateclient.spec.ts +++ b/packages/stargate/src/signingstargateclient.spec.ts @@ -6,12 +6,14 @@ import { MsgDelegate as LaunchpadMsgDelegate, Secp256k1HdWallet, } from "@cosmjs/launchpad"; -import { Coin, cosmosField, DirectSecp256k1HdWallet, registered, Registry } from "@cosmjs/proto-signing"; +import { DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing"; import { assert, sleep } from "@cosmjs/utils"; -import { Message } from "protobufjs"; import { AminoTypes } from "./aminotypes"; -import { cosmos } from "./codec"; +import { MsgSend } from "./codec/cosmos/bank/v1beta1/tx"; +import { Coin } from "./codec/cosmos/base/v1beta1/coin"; +import { MsgDelegate } from "./codec/cosmos/staking/v1beta1/tx"; +import { Tx } from "./codec/cosmos/tx/v1beta1/tx"; import { PrivateSigningStargateClient, SigningStargateClient } from "./signingstargateclient"; import { assertIsBroadcastTxSuccess } from "./stargateclient"; import { @@ -24,13 +26,6 @@ import { validator, } from "./testutils.spec"; -type IMsgSend = cosmos.bank.v1beta1.IMsgSend; -type IMsgDelegate = cosmos.staking.v1beta1.IMsgDelegate; - -const { MsgSend } = cosmos.bank.v1beta1; -const { MsgDelegate } = cosmos.staking.v1beta1; -const { Tx } = cosmos.tx.v1beta1; - describe("SigningStargateClient", () => { describe("constructor", () => { it("can be constructed with default fees", async () => { @@ -186,7 +181,7 @@ describe("SigningStargateClient", () => { const msgDelegateTypeUrl = "/cosmos.staking.v1beta1.MsgDelegate"; const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet); - const msg = MsgDelegate.create({ + const msg = MsgDelegate.fromPartial({ delegatorAddress: faucet.address0, validatorAddress: validator.validatorAddress, amount: coin(1234, "ustake"), @@ -210,7 +205,7 @@ describe("SigningStargateClient", () => { const msgDelegateTypeUrl = "/cosmos.staking.v1beta1.MsgDelegate"; const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet); - const msg = MsgDelegate.create({ + const msg = MsgDelegate.fromPartial({ delegatorAddress: faucet.address0, validatorAddress: validator.validatorAddress, amount: coin(1234, "ustake"), @@ -234,8 +229,8 @@ describe("SigningStargateClient", () => { const tx = Tx.decode(searchResult.tx); // From ModifyingDirectSecp256k1HdWallet expect(tx.body!.memo).toEqual("This was modified"); - expect({ ...tx.authInfo!.fee!.amount![0] }).toEqual(coin(3000, "ucosm")); - expect(tx.authInfo!.fee!.gasLimit!.toNumber()).toEqual(333333); + expect({ ...tx.authInfo!.fee!.amount[0] }).toEqual(coin(3000, "ucosm")); + expect(tx.authInfo!.fee!.gasLimit.toNumber()).toEqual(333333); }); }); @@ -246,15 +241,10 @@ describe("SigningStargateClient", () => { const customRegistry = new Registry(); const msgDelegateTypeUrl = "/cosmos.staking.v1beta1.MsgDelegate"; - @registered(customRegistry, msgDelegateTypeUrl) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - class CustomMsgDelegate extends Message { - @cosmosField.string(1) - public readonly custom_delegator_address?: string; - @cosmosField.string(2) - public readonly custom_validator_address?: string; - @cosmosField.message(3, Coin) - public readonly custom_amount?: Coin; + interface CustomMsgDelegate { + readonly customDelegatorAddress?: string; + readonly customValidatorAddress?: string; + readonly customAmount?: Coin; } it("works with bank MsgSend", async () => { @@ -262,7 +252,7 @@ describe("SigningStargateClient", () => { const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet); - const msgSend: IMsgSend = { + const msgSend: MsgSend = { fromAddress: faucet.address0, toAddress: makeRandomAddress(), amount: coins(1234, "ucosm"), @@ -285,7 +275,7 @@ describe("SigningStargateClient", () => { const wallet = await Secp256k1HdWallet.fromMnemonic(faucet.mnemonic); const client = await SigningStargateClient.connectWithSigner(simapp.tendermintUrl, wallet); - const msgDelegate: IMsgDelegate = { + const msgDelegate: MsgDelegate = { delegatorAddress: faucet.address0, validatorAddress: validator.validatorAddress, amount: coin(1234, "ustake"), @@ -311,21 +301,21 @@ describe("SigningStargateClient", () => { "/cosmos.staking.v1beta1.MsgDelegate": { aminoType: "cosmos-sdk/MsgDelegate", toAmino: ({ - custom_delegator_address, - custom_validator_address, - custom_amount, + customDelegatorAddress, + customValidatorAddress, + customAmount, }: CustomMsgDelegate): LaunchpadMsgDelegate["value"] => { - assert(custom_delegator_address, "missing custom_delegator_address"); - assert(custom_validator_address, "missing validator_address"); - assert(custom_amount, "missing amount"); - assert(custom_amount.amount, "missing amount.amount"); - assert(custom_amount.denom, "missing amount.denom"); + assert(customDelegatorAddress, "missing customDelegatorAddress"); + assert(customValidatorAddress, "missing validatorAddress"); + assert(customAmount, "missing amount"); + assert(customAmount.amount, "missing amount.amount"); + assert(customAmount.denom, "missing amount.denom"); return { - delegator_address: custom_delegator_address, - validator_address: custom_validator_address, + delegator_address: customDelegatorAddress, + validator_address: customValidatorAddress, amount: { - amount: custom_amount.amount, - denom: custom_amount.denom, + amount: customAmount.amount, + denom: customAmount.denom, }, }; }, @@ -333,12 +323,11 @@ describe("SigningStargateClient", () => { delegator_address, validator_address, amount, - }: LaunchpadMsgDelegate["value"]): CustomMsgDelegate => - CustomMsgDelegate.create({ - custom_delegator_address: delegator_address, - custom_validator_address: validator_address, - custom_amount: Coin.create(amount), - }), + }: LaunchpadMsgDelegate["value"]): CustomMsgDelegate => ({ + customDelegatorAddress: delegator_address, + customValidatorAddress: validator_address, + customAmount: Coin.fromPartial(amount), + }), }, }, }); @@ -392,8 +381,8 @@ describe("SigningStargateClient", () => { const tx = Tx.decode(searchResult.tx); // From ModifyingSecp256k1HdWallet expect(tx.body!.memo).toEqual("This was modified"); - expect({ ...tx.authInfo!.fee!.amount![0] }).toEqual(coin(3000, "ucosm")); - expect(tx.authInfo!.fee!.gasLimit!.toNumber()).toEqual(333333); + expect({ ...tx.authInfo!.fee!.amount[0] }).toEqual(coin(3000, "ucosm")); + expect(tx.authInfo!.fee!.gasLimit.toNumber()).toEqual(333333); }); }); }); diff --git a/packages/stargate/src/signingstargateclient.ts b/packages/stargate/src/signingstargateclient.ts index 83c098b5..0340b54e 100644 --- a/packages/stargate/src/signingstargateclient.ts +++ b/packages/stargate/src/signingstargateclient.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/naming-convention */ import { fromBase64 } from "@cosmjs/encoding"; import { AccountData, @@ -25,24 +24,23 @@ import { import { adaptor34, Client as TendermintClient } from "@cosmjs/tendermint-rpc"; import { AminoTypes } from "./aminotypes"; -import { cosmos } from "./codec"; -import { BroadcastTxResponse, StargateClient } from "./stargateclient"; - -const { MsgMultiSend } = cosmos.bank.v1beta1; -const { +import { MsgMultiSend } from "./codec/cosmos/bank/v1beta1/tx"; +import { MsgFundCommunityPool, MsgSetWithdrawAddress, MsgWithdrawDelegatorReward, MsgWithdrawValidatorCommission, -} = cosmos.distribution.v1beta1; -const { +} from "./codec/cosmos/distribution/v1beta1/tx"; +import { MsgBeginRedelegate, MsgCreateValidator, MsgDelegate, MsgEditValidator, MsgUndelegate, -} = cosmos.staking.v1beta1; -const { TxRaw } = cosmos.tx.v1beta1; +} from "./codec/cosmos/staking/v1beta1/tx"; +import { SignMode } from "./codec/cosmos/tx/signing/v1beta1/signing"; +import { TxRaw } from "./codec/cosmos/tx/v1beta1/tx"; +import { BroadcastTxResponse, StargateClient } from "./stargateclient"; const defaultGasPrice = GasPrice.fromString("0.025ucosm"); const defaultGasLimits: GasLimits = { send: 80000 }; @@ -165,7 +163,7 @@ export class SigningStargateClient extends StargateClient { const authInfoBytes = makeAuthInfoBytes([pubkeyAny], fee.amount, gasLimit, sequence); const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber); const { signature, signed } = await this.signer.signDirect(signerAddress, signDoc); - const txRaw = TxRaw.create({ + const txRaw = TxRaw.fromPartial({ bodyBytes: signed.bodyBytes, authInfoBytes: signed.authInfoBytes, signatures: [fromBase64(signature.signature)], @@ -175,7 +173,7 @@ export class SigningStargateClient extends StargateClient { } // Amino signer - const signMode = cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_LEGACY_AMINO_JSON; + const signMode = SignMode.SIGN_MODE_LEGACY_AMINO_JSON; const msgs = messages.map((msg) => this.aminoTypes.toAmino(msg)); const signDoc = makeSignDocAmino(msgs, fee, chainId, memo, accountNumber, sequence); const { signature, signed } = await this.signer.signAmino(signerAddress, signDoc); @@ -196,7 +194,7 @@ export class SigningStargateClient extends StargateClient { signedSequence, signMode, ); - const txRaw = TxRaw.create({ + const txRaw = TxRaw.fromPartial({ bodyBytes: signedTxBodyBytes, authInfoBytes: signedAuthInfoBytes, signatures: [fromBase64(signature.signature)], diff --git a/packages/stargate/src/stargateclient.searchtx.spec.ts b/packages/stargate/src/stargateclient.searchtx.spec.ts index 5b85a577..a43dcde2 100644 --- a/packages/stargate/src/stargateclient.searchtx.spec.ts +++ b/packages/stargate/src/stargateclient.searchtx.spec.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/naming-convention */ import { fromBase64, toBase64 } from "@cosmjs/encoding"; import { Coin, coins } from "@cosmjs/launchpad"; import { @@ -10,7 +9,7 @@ import { } from "@cosmjs/proto-signing"; import { assert, sleep } from "@cosmjs/utils"; -import { cosmos } from "./codec"; +import { Tx, TxRaw } from "./codec/cosmos/tx/v1beta1/tx"; import { BroadcastTxResponse, isBroadcastTxFailure, @@ -26,8 +25,6 @@ import { simappEnabled, } from "./testutils.spec"; -const { Tx, TxRaw } = cosmos.tx.v1beta1; - interface TestTxSend { readonly sender: string; readonly recipient: string; @@ -82,7 +79,7 @@ async function sendTokens( const chainId = await client.getChainId(); const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber); const { signature } = await wallet.signDirect(walletAddress, signDoc); - const txRaw = TxRaw.create({ + const txRaw = TxRaw.fromPartial({ bodyBytes: txBodyBytes, authInfoBytes: authInfoBytes, signatures: [fromBase64(signature.signature)], @@ -232,9 +229,9 @@ describe("StargateClient.getTx and .searchTx", () => { // Check basic structure of all results for (const result of results) { const tx = Tx.decode(result.tx); - const filteredMsgs = tx.body!.messages!.filter(({ type_url: typeUrl, value }) => { + const filteredMsgs = tx.body!.messages.filter(({ typeUrl: typeUrl, value }) => { if (typeUrl !== "/cosmos.bank.v1beta1.MsgSend") return false; - const decoded = registry.decode({ typeUrl: typeUrl, value: value! }); + const decoded = registry.decode({ typeUrl: typeUrl, value: value }); return decoded.fromAddress === sendSuccessful?.sender; }); expect(filteredMsgs.length).toBeGreaterThanOrEqual(1); @@ -260,9 +257,9 @@ describe("StargateClient.getTx and .searchTx", () => { // Check basic structure of all results for (const result of results) { const tx = Tx.decode(result.tx); - const filteredMsgs = tx.body!.messages!.filter(({ type_url: typeUrl, value }) => { + const filteredMsgs = tx.body!.messages.filter(({ typeUrl: typeUrl, value }) => { if (typeUrl !== "/cosmos.bank.v1beta1.MsgSend") return false; - const decoded = registry.decode({ typeUrl: typeUrl, value: value! }); + const decoded = registry.decode({ typeUrl: typeUrl, value: value }); return decoded.toAddress === sendSuccessful?.recipient; }); expect(filteredMsgs.length).toBeGreaterThanOrEqual(1); @@ -346,9 +343,9 @@ describe("StargateClient.getTx and .searchTx", () => { // Check basic structure of all results for (const result of results) { const tx = Tx.decode(result.tx); - const { type_url: typeUrl, value } = fromOneElementArray(tx.body!.messages!); + const { typeUrl, value } = fromOneElementArray(tx.body!.messages); expect(typeUrl).toEqual("/cosmos.bank.v1beta1.MsgSend"); - const decoded = registry.decode({ typeUrl: typeUrl!, value: value! }); + const decoded = registry.decode({ typeUrl: typeUrl, value: value }); expect(decoded.toAddress).toEqual(sendSuccessful.recipient); } diff --git a/packages/stargate/src/stargateclient.spec.ts b/packages/stargate/src/stargateclient.spec.ts index 6cc6877b..eef1a218 100644 --- a/packages/stargate/src/stargateclient.spec.ts +++ b/packages/stargate/src/stargateclient.spec.ts @@ -10,7 +10,7 @@ import { import { assert, sleep } from "@cosmjs/utils"; import { ReadonlyDate } from "readonly-date"; -import { cosmos } from "./codec"; +import { TxRaw } from "./codec/cosmos/tx/v1beta1/tx"; import { assertIsBroadcastTxSuccess, PrivateStargateClient, StargateClient } from "./stargateclient"; import { faucet, @@ -23,8 +23,6 @@ import { validator, } from "./testutils.spec"; -const { TxRaw } = cosmos.tx.v1beta1; - describe("StargateClient", () => { describe("connect", () => { it("works", async () => { @@ -311,7 +309,7 @@ describe("StargateClient", () => { const chainId = await client.getChainId(); const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber); const { signature } = await wallet.signDirect(address, signDoc); - const txRaw = TxRaw.create({ + const txRaw = TxRaw.fromPartial({ bodyBytes: txBodyBytes, authInfoBytes: authInfoBytes, signatures: [fromBase64(signature.signature)], diff --git a/packages/stargate/src/stargateclient.ts b/packages/stargate/src/stargateclient.ts index 488ff285..7eebf2c6 100644 --- a/packages/stargate/src/stargateclient.ts +++ b/packages/stargate/src/stargateclient.ts @@ -2,7 +2,6 @@ import { toHex } from "@cosmjs/encoding"; import { Block, - Coin, isSearchByHeightQuery, isSearchBySentFromOrToQuery, isSearchByTagsQuery, @@ -21,15 +20,11 @@ import { import { assert, assertDefinedAndNotNull } from "@cosmjs/utils"; import Long from "long"; -import { cosmos } from "./codec"; +import { BaseAccount } from "./codec/cosmos/auth/v1beta1/auth"; +import { MsgData, TxMsgData } from "./codec/cosmos/base/abci/v1beta1/abci"; +import { Coin } from "./codec/cosmos/base/v1beta1/coin"; import { AuthExtension, BankExtension, QueryClient, setupAuthExtension, setupBankExtension } from "./queries"; -type IBaseAccount = cosmos.auth.v1beta1.IBaseAccount; -type IMsgData = cosmos.base.abci.v1beta1.IMsgData; -type ICoin = cosmos.base.v1beta1.ICoin; - -const { TxMsgData } = cosmos.base.abci.v1beta1; - /** A transaction that is indexed as part of the transaction history */ export interface IndexedTx { readonly height: number; @@ -59,14 +54,14 @@ export interface BroadcastTxFailure { readonly code: number; readonly transactionHash: string; readonly rawLog?: string; - readonly data?: readonly IMsgData[]; + readonly data?: readonly MsgData[]; } export interface BroadcastTxSuccess { readonly height: number; readonly transactionHash: string; readonly rawLog?: string; - readonly data?: readonly IMsgData[]; + readonly data?: readonly MsgData[]; } export type BroadcastTxResponse = BroadcastTxSuccess | BroadcastTxFailure; @@ -97,7 +92,7 @@ function uint64FromProto(input: number | Long | null | undefined): Uint64 { return Uint64.fromString(input.toString()); } -export function accountFromProto(input: IBaseAccount): Account { +export function accountFromProto(input: BaseAccount): Account { const { address, pubKey, accountNumber, sequence } = input; const pubkey = decodePubkey(pubKey); assert(address); @@ -109,7 +104,7 @@ export function accountFromProto(input: IBaseAccount): Account { }; } -export function coinFromProto(input: ICoin): Coin { +export function coinFromProto(input: Coin): Coin { assertDefinedAndNotNull(input.amount); assertDefinedAndNotNull(input.denom); return { diff --git a/packages/stargate/src/testutils.spec.ts b/packages/stargate/src/testutils.spec.ts index 3cc83f6c..1f15a89b 100644 --- a/packages/stargate/src/testutils.spec.ts +++ b/packages/stargate/src/testutils.spec.ts @@ -10,9 +10,8 @@ import { } from "@cosmjs/launchpad"; import { DirectSecp256k1HdWallet, DirectSignResponse, makeAuthInfoBytes } from "@cosmjs/proto-signing"; -import { cosmos } from "./codec"; - -const { AuthInfo, TxBody } = cosmos.tx.v1beta1; +import { SignMode } from "./codec/cosmos/tx/signing/v1beta1/signing"; +import { AuthInfo, SignDoc, TxBody } from "./codec/cosmos/tx/v1beta1/tx"; export function simappEnabled(): boolean { return !!process.env.SIMAPP_ENABLED; @@ -165,15 +164,15 @@ export class ModifyingDirectSecp256k1HdWallet extends DirectSecp256k1HdWallet { ); } - public async signDirect(address: string, signDoc: cosmos.tx.v1beta1.ISignDoc): Promise { - const txBody = TxBody.decode(signDoc.bodyBytes!); - const modifiedTxBody = TxBody.create({ + public async signDirect(address: string, signDoc: SignDoc): Promise { + const txBody = TxBody.decode(signDoc.bodyBytes); + const modifiedTxBody = TxBody.fromPartial({ ...txBody, memo: "This was modified", }); - const authInfo = AuthInfo.decode(signDoc.authInfoBytes!); + const authInfo = AuthInfo.decode(signDoc.authInfoBytes); const pubkeys = authInfo.signerInfos.map((signerInfo) => signerInfo.publicKey!); - const sequence = authInfo.signerInfos[0].sequence!.toNumber(); + const sequence = authInfo.signerInfos[0].sequence.toNumber(); const modifiedFeeAmount = coins(3000, "ucosm"); const modifiedGasLimit = 333333; const modifiedSignDoc = { @@ -184,7 +183,7 @@ export class ModifyingDirectSecp256k1HdWallet extends DirectSecp256k1HdWallet { modifiedFeeAmount, modifiedGasLimit, sequence, - cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT, + SignMode.SIGN_MODE_DIRECT, ), }; return super.signDirect(address, modifiedSignDoc); diff --git a/packages/stargate/types/index.d.ts b/packages/stargate/types/index.d.ts index 9f67b26e..240d94dd 100644 --- a/packages/stargate/types/index.d.ts +++ b/packages/stargate/types/index.d.ts @@ -1,4 +1,3 @@ -export * as codec from "./codec"; export { AminoConverter, AminoTypes } from "./aminotypes"; export { parseRawLog } from "./logs"; export { diff --git a/packages/stargate/types/queries/auth.d.ts b/packages/stargate/types/queries/auth.d.ts index cbdd3756..c81db997 100644 --- a/packages/stargate/types/queries/auth.d.ts +++ b/packages/stargate/types/queries/auth.d.ts @@ -1,10 +1,10 @@ -import { cosmos } from "../codec"; +import { BaseAccount } from "../codec/cosmos/auth/v1beta1/auth"; import { QueryClient } from "./queryclient"; export interface AuthExtension { readonly auth: { - readonly account: (address: string) => Promise; + readonly account: (address: string) => Promise; readonly unverified: { - readonly account: (address: string) => Promise; + readonly account: (address: string) => Promise; }; }; } diff --git a/packages/stargate/types/queries/bank.d.ts b/packages/stargate/types/queries/bank.d.ts index 250a74e5..6aea1a23 100644 --- a/packages/stargate/types/queries/bank.d.ts +++ b/packages/stargate/types/queries/bank.d.ts @@ -1,13 +1,13 @@ -import { cosmos } from "../codec"; +import { Coin } from "../codec/cosmos/base/v1beta1/coin"; import { QueryClient } from "./queryclient"; export interface BankExtension { readonly bank: { - readonly balance: (address: string, denom: string) => Promise; + readonly balance: (address: string, denom: string) => Promise; readonly unverified: { - readonly balance: (address: string, denom: string) => Promise; - readonly allBalances: (address: string) => Promise; - readonly totalSupply: () => Promise; - readonly supplyOf: (denom: string) => Promise; + readonly balance: (address: string, denom: string) => Promise; + readonly allBalances: (address: string) => Promise; + readonly totalSupply: () => Promise; + readonly supplyOf: (denom: string) => Promise; }; }; } diff --git a/packages/stargate/types/queries/distribution.d.ts b/packages/stargate/types/queries/distribution.d.ts index afe453dc..5a214a20 100644 --- a/packages/stargate/types/queries/distribution.d.ts +++ b/packages/stargate/types/queries/distribution.d.ts @@ -1,38 +1,38 @@ -import { cosmos } from "../codec"; +import { + QueryCommunityPoolResponse, + QueryDelegationRewardsResponse, + QueryDelegationTotalRewardsResponse, + QueryDelegatorValidatorsResponse, + QueryDelegatorWithdrawAddressResponse, + QueryParamsResponse, + QueryValidatorCommissionResponse, + QueryValidatorOutstandingRewardsResponse, + QueryValidatorSlashesResponse, +} from "../codec/cosmos/distribution/v1beta1/query"; import { QueryClient } from "./queryclient"; -declare type IQueryCommunityPoolResponse = cosmos.distribution.v1beta1.IQueryCommunityPoolResponse; -declare type IQueryDelegationRewardsResponse = cosmos.distribution.v1beta1.IQueryDelegationRewardsResponse; -declare type IQueryDelegationTotalRewardsResponse = cosmos.distribution.v1beta1.IQueryDelegationTotalRewardsResponse; -declare type IQueryDelegatorValidatorsResponse = cosmos.distribution.v1beta1.IQueryDelegatorValidatorsResponse; -declare type IQueryDelegatorWithdrawAddressResponse = cosmos.distribution.v1beta1.IQueryDelegatorWithdrawAddressResponse; -declare type IQueryParamsResponse = cosmos.distribution.v1beta1.IQueryParamsResponse; -declare type IQueryValidatorCommissionResponse = cosmos.distribution.v1beta1.IQueryValidatorCommissionResponse; -declare type IQueryValidatorOutstandingRewardsResponse = cosmos.distribution.v1beta1.IQueryValidatorOutstandingRewardsResponse; -declare type IQueryValidatorSlashesResponse = cosmos.distribution.v1beta1.IQueryValidatorSlashesResponse; export interface DistributionExtension { readonly distribution: { unverified: { - communityPool: () => Promise; + communityPool: () => Promise; delegationRewards: ( delegatorAddress: string, validatorAddress: string, - ) => Promise; - delegationTotalRewards: (delegatorAddress: string) => Promise; - delegatorValidators: (delegatorAddress: string) => Promise; - delegatorWithdrawAddress: (delegatorAddress: string) => Promise; - params: () => Promise; - validatorCommission: (validatorAddress: string) => Promise; + ) => Promise; + delegationTotalRewards: (delegatorAddress: string) => Promise; + delegatorValidators: (delegatorAddress: string) => Promise; + delegatorWithdrawAddress: (delegatorAddress: string) => Promise; + params: () => Promise; + validatorCommission: (validatorAddress: string) => Promise; validatorOutstandingRewards: ( validatorAddress: string, - ) => Promise; + ) => Promise; validatorSlashes: ( validatorAddress: string, startingHeight: number, endingHeight: number, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; }; }; } export declare function setupDistributionExtension(base: QueryClient): DistributionExtension; -export {}; diff --git a/packages/stargate/types/queries/ibc.d.ts b/packages/stargate/types/queries/ibc.d.ts index 7d826b11..78046243 100644 --- a/packages/stargate/types/queries/ibc.d.ts +++ b/packages/stargate/types/queries/ibc.d.ts @@ -1,8 +1,25 @@ -import { ibc } from "../codec"; +import { Channel } from "../codec/ibc/core/channel/v1/channel"; +import { + QueryChannelResponse, + QueryChannelsResponse, + QueryConnectionChannelsResponse, + QueryNextSequenceReceiveResponse, + QueryPacketAcknowledgementResponse, + QueryPacketAcknowledgementsResponse, + QueryPacketCommitmentResponse, + QueryPacketCommitmentsResponse, + QueryUnreceivedAcksResponse, + QueryUnreceivedPacketsResponse, +} from "../codec/ibc/core/channel/v1/query"; +import { + QueryClientConnectionsResponse, + QueryConnectionResponse, + QueryConnectionsResponse, +} from "../codec/ibc/core/connection/v1/query"; import { QueryClient } from "./queryclient"; export interface IbcExtension { readonly ibc: { - readonly channel: (portId: string, channelId: string) => Promise; + readonly channel: (portId: string, channelId: string) => Promise; readonly packetCommitment: (portId: string, channelId: string, sequence: number) => Promise; readonly packetAcknowledgement: ( portId: string, @@ -11,56 +28,49 @@ export interface IbcExtension { ) => Promise; readonly nextSequenceReceive: (portId: string, channelId: string) => Promise; readonly unverified: { - readonly channel: ( - portId: string, - channelId: string, - ) => Promise; - readonly channels: (paginationKey?: Uint8Array) => Promise; + readonly channel: (portId: string, channelId: string) => Promise; + readonly channels: (paginationKey?: Uint8Array) => Promise; readonly connectionChannels: ( connection: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; readonly packetCommitment: ( portId: string, channelId: string, sequence: number, - ) => Promise; + ) => Promise; readonly packetCommitments: ( portId: string, channelId: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; readonly packetAcknowledgement: ( portId: string, channelId: string, sequence: number, - ) => Promise; + ) => Promise; readonly packetAcknowledgements: ( portId: string, channelId: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; readonly unreceivedPackets: ( portId: string, channelId: string, packetCommitmentSequences: readonly number[], - ) => Promise; + ) => Promise; readonly unreceivedAcks: ( portId: string, channelId: string, packetCommitmentSequences: readonly number[], - ) => Promise; + ) => Promise; readonly nextSequenceReceive: ( portId: string, channelId: string, - ) => Promise; - readonly connection: (connectionId: string) => Promise; - readonly connections: ( - paginationKey?: Uint8Array, - ) => Promise; - readonly clientConnections: ( - clientId: string, - ) => Promise; + ) => Promise; + readonly connection: (connectionId: string) => Promise; + readonly connections: (paginationKey?: Uint8Array) => Promise; + readonly clientConnections: (clientId: string) => Promise; }; }; } diff --git a/packages/stargate/types/queries/staking.d.ts b/packages/stargate/types/queries/staking.d.ts index beabec9d..1706f751 100644 --- a/packages/stargate/types/queries/staking.d.ts +++ b/packages/stargate/types/queries/staking.d.ts @@ -1,66 +1,66 @@ -import { cosmos } from "../codec"; +import { + QueryDelegationResponse, + QueryDelegatorDelegationsResponse, + QueryDelegatorUnbondingDelegationsResponse, + QueryDelegatorValidatorResponse, + QueryDelegatorValidatorsResponse, + QueryHistoricalInfoResponse, + QueryParamsResponse, + QueryPoolResponse, + QueryRedelegationsResponse, + QueryUnbondingDelegationResponse, + QueryValidatorDelegationsResponse, + QueryValidatorResponse, + QueryValidatorsResponse, + QueryValidatorUnbondingDelegationsResponse, +} from "../codec/cosmos/staking/v1beta1/query"; +import { BondStatus } from "../codec/cosmos/staking/v1beta1/staking"; import { QueryClient } from "./queryclient"; -declare type IQueryDelegationResponse = cosmos.staking.v1beta1.IQueryDelegationResponse; -declare type IQueryDelegatorDelegationsResponse = cosmos.staking.v1beta1.IQueryDelegatorDelegationsResponse; -declare type IQueryDelegatorUnbondingDelegationsResponse = cosmos.staking.v1beta1.IQueryDelegatorUnbondingDelegationsResponse; -declare type IQueryDelegatorValidatorResponse = cosmos.staking.v1beta1.IQueryDelegatorValidatorResponse; -declare type IQueryDelegatorValidatorsResponse = cosmos.staking.v1beta1.IQueryDelegatorValidatorsResponse; -declare type IQueryHistoricalInfoResponse = cosmos.staking.v1beta1.IQueryHistoricalInfoResponse; -declare type IQueryParamsResponse = cosmos.staking.v1beta1.IQueryParamsResponse; -declare type IQueryPoolResponse = cosmos.staking.v1beta1.IQueryPoolResponse; -declare type IQueryRedelegationsResponse = cosmos.staking.v1beta1.IQueryRedelegationsResponse; -declare type IQueryUnbondingDelegationResponse = cosmos.staking.v1beta1.IQueryUnbondingDelegationResponse; -declare type IQueryValidatorResponse = cosmos.staking.v1beta1.IQueryValidatorResponse; -declare type IQueryValidatorDelegationsResponse = cosmos.staking.v1beta1.IQueryValidatorDelegationsResponse; -declare type IQueryValidatorsResponse = cosmos.staking.v1beta1.IQueryValidatorsResponse; -declare type IQueryValidatorUnbondingDelegationsResponse = cosmos.staking.v1beta1.IQueryValidatorUnbondingDelegationsResponse; -export declare const BondStatus: typeof cosmos.staking.v1beta1.BondStatus; export declare type BondStatusString = Exclude; export interface StakingExtension { readonly staking: { readonly unverified: { - delegation: (delegatorAddress: string, validatorAddress: string) => Promise; + delegation: (delegatorAddress: string, validatorAddress: string) => Promise; delegatorDelegations: ( delegatorAddress: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; delegatorUnbondingDelegations: ( delegatorAddress: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; delegatorValidator: ( delegatorAddress: string, validatorAddress: string, - ) => Promise; + ) => Promise; delegatorValidators: ( delegatorAddress: string, paginationKey?: Uint8Array, - ) => Promise; - historicalInfo: (height: number) => Promise; - params: () => Promise; - pool: () => Promise; + ) => Promise; + historicalInfo: (height: number) => Promise; + params: () => Promise; + pool: () => Promise; redelegations: ( delegatorAddress: string, sourceValidatorAddress: string, destinationValidatorAddress: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; unbondingDelegation: ( delegatorAddress: string, validatorAddress: string, - ) => Promise; - validator: (validatorAddress: string) => Promise; + ) => Promise; + validator: (validatorAddress: string) => Promise; validatorDelegations: ( validatorAddress: string, paginationKey?: Uint8Array, - ) => Promise; - validators: (status: BondStatusString, paginationKey?: Uint8Array) => Promise; + ) => Promise; + validators: (status: BondStatusString, paginationKey?: Uint8Array) => Promise; validatorUnbondingDelegations: ( validatorAddress: string, paginationKey?: Uint8Array, - ) => Promise; + ) => Promise; }; }; } export declare function setupStakingExtension(base: QueryClient): StakingExtension; -export {}; diff --git a/packages/stargate/types/queries/utils.d.ts b/packages/stargate/types/queries/utils.d.ts index 3d99f5c2..03fad06f 100644 --- a/packages/stargate/types/queries/utils.d.ts +++ b/packages/stargate/types/queries/utils.d.ts @@ -1,3 +1,4 @@ +import Long from "long"; /** * Takes a bech32 encoded address and returns the data part. The prefix is ignored and discarded. * This is called AccAddress in Cosmos SDK, which is basically an alias for raw binary data. @@ -9,3 +10,11 @@ export declare function toAccAddress(address: string): Uint8Array; * in a ways that makes Jasmine's toEqual happy. */ export declare function toObject(thing: I): Omit; +export declare function createPagination( + paginationKey?: Uint8Array, +): { + readonly key: Uint8Array; + readonly offset: Long; + readonly limit: Long; + readonly countTotal: boolean; +}; diff --git a/packages/stargate/types/stargateclient.d.ts b/packages/stargate/types/stargateclient.d.ts index 44af081b..26c4a2c7 100644 --- a/packages/stargate/types/stargateclient.d.ts +++ b/packages/stargate/types/stargateclient.d.ts @@ -1,9 +1,8 @@ -import { Block, Coin, PubKey, SearchTxFilter, SearchTxQuery } from "@cosmjs/launchpad"; +import { Block, PubKey, SearchTxFilter, SearchTxQuery } from "@cosmjs/launchpad"; import { Client as TendermintClient } from "@cosmjs/tendermint-rpc"; -import { cosmos } from "./codec"; -declare type IBaseAccount = cosmos.auth.v1beta1.IBaseAccount; -declare type IMsgData = cosmos.base.abci.v1beta1.IMsgData; -declare type ICoin = cosmos.base.v1beta1.ICoin; +import { BaseAccount } from "./codec/cosmos/auth/v1beta1/auth"; +import { MsgData } from "./codec/cosmos/base/abci/v1beta1/abci"; +import { Coin } from "./codec/cosmos/base/v1beta1/coin"; /** A transaction that is indexed as part of the transaction history */ export interface IndexedTx { readonly height: number; @@ -30,13 +29,13 @@ export interface BroadcastTxFailure { readonly code: number; readonly transactionHash: string; readonly rawLog?: string; - readonly data?: readonly IMsgData[]; + readonly data?: readonly MsgData[]; } export interface BroadcastTxSuccess { readonly height: number; readonly transactionHash: string; readonly rawLog?: string; - readonly data?: readonly IMsgData[]; + readonly data?: readonly MsgData[]; } export declare type BroadcastTxResponse = BroadcastTxSuccess | BroadcastTxFailure; export declare function isBroadcastTxFailure(result: BroadcastTxResponse): result is BroadcastTxFailure; @@ -47,8 +46,8 @@ export declare function isBroadcastTxSuccess(result: BroadcastTxResponse): resul export declare function assertIsBroadcastTxSuccess( result: BroadcastTxResponse, ): asserts result is BroadcastTxSuccess; -export declare function accountFromProto(input: IBaseAccount): Account; -export declare function coinFromProto(input: ICoin): Coin; +export declare function accountFromProto(input: BaseAccount): Account; +export declare function coinFromProto(input: Coin): Coin; /** Use for testing only */ export interface PrivateStargateClient { readonly tmClient: TendermintClient; @@ -78,4 +77,3 @@ export declare class StargateClient { broadcastTx(tx: Uint8Array): Promise; private txsQuery; } -export {};