diff --git a/packages/sdk38/src/lcdapi/base.ts b/packages/sdk38/src/lcdapi/base.ts new file mode 100644 index 00000000..bcf457cf --- /dev/null +++ b/packages/sdk38/src/lcdapi/base.ts @@ -0,0 +1,164 @@ +import { Coin } from "../coins"; +import { CosmosSdkTx } from "../types"; + +/** + * The mode used to send transaction + * + * @see https://cosmos.network/rpc/#/Transactions/post_txs + */ +export enum BroadcastMode { + /** Return after tx commit */ + Block = "block", + /** Return afer CheckTx */ + Sync = "sync", + /** Return right away */ + Async = "async", +} + +/** A reponse from the /txs/encode endpoint */ +export interface EncodeTxResponse { + /** base64-encoded amino-binary encoded representation */ + readonly tx: string; +} + +interface NodeInfo { + readonly protocol_version: { + readonly p2p: string; + readonly block: string; + readonly app: string; + }; + readonly id: string; + readonly listen_addr: string; + readonly network: string; + readonly version: string; + readonly channels: string; + readonly moniker: string; + readonly other: { + readonly tx_index: string; + readonly rpc_address: string; + }; +} + +interface ApplicationVersion { + readonly name: string; + readonly server_name: string; + readonly client_name: string; + readonly version: string; + readonly commit: string; + readonly build_tags: string; + readonly go: string; +} + +export interface NodeInfoResponse { + readonly node_info: NodeInfo; + readonly application_version: ApplicationVersion; +} + +interface BlockId { + readonly hash: string; + // TODO: here we also have this + // parts: { + // total: '1', + // hash: '7AF200C78FBF9236944E1AB270F4045CD60972B7C265E3A9DA42973397572931' + // } +} + +interface BlockHeader { + readonly version: { + readonly block: string; + readonly app: string; + }; + readonly height: string; + readonly chain_id: string; + /** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */ + readonly time: string; + readonly last_commit_hash: string; + readonly last_block_id: BlockId; + /** Can be empty */ + readonly data_hash: string; + readonly validators_hash: string; + readonly next_validators_hash: string; + readonly consensus_hash: string; + readonly app_hash: string; + /** Can be empty */ + readonly last_results_hash: string; + /** Can be empty */ + readonly evidence_hash: string; + readonly proposer_address: string; +} + +interface Block { + readonly header: BlockHeader; + readonly data: { + /** Array of base64 encoded transactions */ + readonly txs: readonly string[] | null; + }; +} + +export interface BlockResponse { + readonly block_id: BlockId; + readonly block: Block; +} + +export interface CosmosSdkAccount { + /** Bech32 account address */ + readonly address: string; + readonly coins: readonly Coin[]; + /** Bech32 encoded pubkey */ + readonly public_key: string; + readonly account_number: number; + readonly sequence: number; +} + +export interface AuthAccountsResponse { + readonly height: string; + readonly result: { + readonly type: "cosmos-sdk/Account"; + readonly value: CosmosSdkAccount; + }; +} + +export interface TxsResponse { + readonly height: string; + readonly txhash: string; + /** 🤷‍♂️ */ + readonly codespace?: string; + /** Falsy when transaction execution succeeded. Contains error code on error. */ + readonly code?: number; + readonly raw_log: string; + readonly logs?: object; + readonly tx: CosmosSdkTx; + /** The gas limit as set by the user */ + readonly gas_wanted?: string; + /** The gas used by the execution */ + readonly gas_used?: string; + readonly timestamp: string; +} + +export interface SearchTxsResponse { + readonly total_count: string; + readonly count: string; + readonly page_number: string; + readonly page_total: string; + readonly limit: string; + readonly txs: readonly TxsResponse[]; +} + +export interface PostTxsResponse { + readonly height: string; + readonly txhash: string; + readonly code?: number; + /** + * The result data of the execution (hex encoded). + * + * @see https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/types/result.go#L101 + */ + readonly data?: string; + readonly raw_log?: string; + /** The same as `raw_log` but deserialized? */ + readonly logs?: object; + /** The gas limit as set by the user */ + readonly gas_wanted?: string; + /** The gas used by the execution */ + readonly gas_used?: string; +} diff --git a/packages/sdk38/src/lcdapi/index.ts b/packages/sdk38/src/lcdapi/index.ts index 567e1517..59479bf3 100644 --- a/packages/sdk38/src/lcdapi/index.ts +++ b/packages/sdk38/src/lcdapi/index.ts @@ -1,6 +1,3 @@ -import { Coin } from "../coins"; -import { CosmosSdkTx } from "../types"; - // // Standard modules (see tracking issue https://github.com/CosmWasm/cosmjs/issues/276) // @@ -11,164 +8,13 @@ export { SupplyModule, TotalSupplyAllReponse, TotalSupplyReponse } from "./suppl // Base types // -/** - * The mode used to send transaction - * - * @see https://cosmos.network/rpc/#/Transactions/post_txs - */ -export enum BroadcastMode { - /** Return after tx commit */ - Block = "block", - /** Return afer CheckTx */ - Sync = "sync", - /** Return right away */ - Async = "async", -} - -/** A reponse from the /txs/encode endpoint */ -export interface EncodeTxResponse { - /** base64-encoded amino-binary encoded representation */ - readonly tx: string; -} - -interface NodeInfo { - readonly protocol_version: { - readonly p2p: string; - readonly block: string; - readonly app: string; - }; - readonly id: string; - readonly listen_addr: string; - readonly network: string; - readonly version: string; - readonly channels: string; - readonly moniker: string; - readonly other: { - readonly tx_index: string; - readonly rpc_address: string; - }; -} - -interface ApplicationVersion { - readonly name: string; - readonly server_name: string; - readonly client_name: string; - readonly version: string; - readonly commit: string; - readonly build_tags: string; - readonly go: string; -} - -export interface NodeInfoResponse { - readonly node_info: NodeInfo; - readonly application_version: ApplicationVersion; -} - -interface BlockId { - readonly hash: string; - // TODO: here we also have this - // parts: { - // total: '1', - // hash: '7AF200C78FBF9236944E1AB270F4045CD60972B7C265E3A9DA42973397572931' - // } -} - -interface BlockHeader { - readonly version: { - readonly block: string; - readonly app: string; - }; - readonly height: string; - readonly chain_id: string; - /** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */ - readonly time: string; - readonly last_commit_hash: string; - readonly last_block_id: BlockId; - /** Can be empty */ - readonly data_hash: string; - readonly validators_hash: string; - readonly next_validators_hash: string; - readonly consensus_hash: string; - readonly app_hash: string; - /** Can be empty */ - readonly last_results_hash: string; - /** Can be empty */ - readonly evidence_hash: string; - readonly proposer_address: string; -} - -interface Block { - readonly header: BlockHeader; - readonly data: { - /** Array of base64 encoded transactions */ - readonly txs: readonly string[] | null; - }; -} - -export interface BlockResponse { - readonly block_id: BlockId; - readonly block: Block; -} - -export interface CosmosSdkAccount { - /** Bech32 account address */ - readonly address: string; - readonly coins: readonly Coin[]; - /** Bech32 encoded pubkey */ - readonly public_key: string; - readonly account_number: number; - readonly sequence: number; -} - -export interface AuthAccountsResponse { - readonly height: string; - readonly result: { - readonly type: "cosmos-sdk/Account"; - readonly value: CosmosSdkAccount; - }; -} - -export interface TxsResponse { - readonly height: string; - readonly txhash: string; - /** 🤷‍♂️ */ - readonly codespace?: string; - /** Falsy when transaction execution succeeded. Contains error code on error. */ - readonly code?: number; - readonly raw_log: string; - readonly logs?: object; - readonly tx: CosmosSdkTx; - /** The gas limit as set by the user */ - readonly gas_wanted?: string; - /** The gas used by the execution */ - readonly gas_used?: string; - readonly timestamp: string; -} - -export interface SearchTxsResponse { - readonly total_count: string; - readonly count: string; - readonly page_number: string; - readonly page_total: string; - readonly limit: string; - readonly txs: readonly TxsResponse[]; -} - -export interface PostTxsResponse { - readonly height: string; - readonly txhash: string; - readonly code?: number; - /** - * The result data of the execution (hex encoded). - * - * @see https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/types/result.go#L101 - */ - readonly data?: string; - readonly raw_log?: string; - /** The same as `raw_log` but deserialized? */ - readonly logs?: object; - /** The gas limit as set by the user */ - readonly gas_wanted?: string; - /** The gas used by the execution */ - readonly gas_used?: string; -} +export { + AuthAccountsResponse, + BlockResponse, + BroadcastMode, + EncodeTxResponse, + PostTxsResponse, + NodeInfoResponse, + SearchTxsResponse, + TxsResponse, +} from "./base"; diff --git a/packages/sdk38/src/lcdclient.spec.ts b/packages/sdk38/src/lcdapi/lcdclient.spec.ts similarity index 98% rename from packages/sdk38/src/lcdclient.spec.ts rename to packages/sdk38/src/lcdapi/lcdclient.spec.ts index e6b43eb8..e80ee2c0 100644 --- a/packages/sdk38/src/lcdclient.spec.ts +++ b/packages/sdk38/src/lcdapi/lcdclient.spec.ts @@ -1,17 +1,15 @@ /* eslint-disable @typescript-eslint/camelcase */ import { assert, sleep } from "@cosmjs/utils"; -import { rawSecp256k1PubkeyToAddress } from "./address"; -import { Coin } from "./coins"; -import { isPostTxFailure } from "./cosmosclient"; -import { makeSignBytes } from "./encoding"; -import { TxsResponse } from "./lcdapi"; -import { LcdApiArray, LcdClient, normalizeArray } from "./lcdclient"; -import { parseLogs } from "./logs"; -import { MsgSend } from "./msgs"; -import { makeCosmoshubPath, Secp256k1Pen } from "./pen"; -import { SigningCosmosClient } from "./signingcosmosclient"; -import cosmoshub from "./testdata/cosmoshub.json"; +import { rawSecp256k1PubkeyToAddress } from "../address"; +import { Coin } from "../coins"; +import { isPostTxFailure } from "../cosmosclient"; +import { makeSignBytes } from "../encoding"; +import { parseLogs } from "../logs"; +import { MsgSend } from "../msgs"; +import { makeCosmoshubPath, Secp256k1Pen } from "../pen"; +import { SigningCosmosClient } from "../signingcosmosclient"; +import cosmoshub from "../testdata/cosmoshub.json"; import { faucet, makeRandomAddress, @@ -21,8 +19,10 @@ import { tendermintIdMatcher, wasmd, wasmdEnabled, -} from "./testutils.spec"; -import { StdFee } from "./types"; +} from "../testutils.spec"; +import { StdFee } from "../types"; +import { TxsResponse } from "./base"; +import { LcdApiArray, LcdClient, normalizeArray } from "./lcdclient"; /** Deployed as part of scripts/wasmd/init.sh */ export const deployedErc20 = { diff --git a/packages/sdk38/src/lcdclient.ts b/packages/sdk38/src/lcdapi/lcdclient.ts similarity index 99% rename from packages/sdk38/src/lcdclient.ts rename to packages/sdk38/src/lcdapi/lcdclient.ts index c15d2d8f..a2bb655e 100644 --- a/packages/sdk38/src/lcdclient.ts +++ b/packages/sdk38/src/lcdapi/lcdclient.ts @@ -2,6 +2,7 @@ import { assert, isNonNullObject } from "@cosmjs/utils"; import axios, { AxiosError, AxiosInstance } from "axios"; +import { CosmosSdkTx, StdTx } from "../types"; import { AuthAccountsResponse, BlockResponse, @@ -11,8 +12,7 @@ import { PostTxsResponse, SearchTxsResponse, TxsResponse, -} from "./lcdapi"; -import { CosmosSdkTx, StdTx } from "./types"; +} from "./base"; /** Unfortunately, Cosmos SDK encodes empty arrays as null */ export type LcdApiArray = readonly T[] | null; diff --git a/packages/sdk38/src/lcdapi/supply.spec.ts b/packages/sdk38/src/lcdapi/supply.spec.ts index 6ae295e7..3d905fc9 100644 --- a/packages/sdk38/src/lcdapi/supply.spec.ts +++ b/packages/sdk38/src/lcdapi/supply.spec.ts @@ -1,5 +1,5 @@ -import { LcdClient } from "../lcdclient"; import { pendingWithoutWasmd, wasmd } from "../testutils.spec"; +import { LcdClient } from "./lcdclient"; import { setupSupplyModule } from "./supply"; describe("supply", () => { diff --git a/packages/sdk38/src/lcdapi/supply.ts b/packages/sdk38/src/lcdapi/supply.ts index 2063954f..081310ad 100644 --- a/packages/sdk38/src/lcdapi/supply.ts +++ b/packages/sdk38/src/lcdapi/supply.ts @@ -1,5 +1,5 @@ import { Coin } from "../coins"; -import { LcdApiArray, LcdClient, LcdModule } from "../lcdclient"; +import { LcdApiArray, LcdClient, LcdModule } from "./lcdclient"; export interface TotalSupplyAllReponse { readonly height: string; diff --git a/packages/sdk38/types/lcdapi/base.d.ts b/packages/sdk38/types/lcdapi/base.d.ts new file mode 100644 index 00000000..3f520738 --- /dev/null +++ b/packages/sdk38/types/lcdapi/base.d.ts @@ -0,0 +1,146 @@ +import { Coin } from "../coins"; +import { CosmosSdkTx } from "../types"; +/** + * The mode used to send transaction + * + * @see https://cosmos.network/rpc/#/Transactions/post_txs + */ +export declare enum BroadcastMode { + /** Return after tx commit */ + Block = "block", + /** Return afer CheckTx */ + Sync = "sync", + /** Return right away */ + Async = "async", +} +/** A reponse from the /txs/encode endpoint */ +export interface EncodeTxResponse { + /** base64-encoded amino-binary encoded representation */ + readonly tx: string; +} +interface NodeInfo { + readonly protocol_version: { + readonly p2p: string; + readonly block: string; + readonly app: string; + }; + readonly id: string; + readonly listen_addr: string; + readonly network: string; + readonly version: string; + readonly channels: string; + readonly moniker: string; + readonly other: { + readonly tx_index: string; + readonly rpc_address: string; + }; +} +interface ApplicationVersion { + readonly name: string; + readonly server_name: string; + readonly client_name: string; + readonly version: string; + readonly commit: string; + readonly build_tags: string; + readonly go: string; +} +export interface NodeInfoResponse { + readonly node_info: NodeInfo; + readonly application_version: ApplicationVersion; +} +interface BlockId { + readonly hash: string; +} +interface BlockHeader { + readonly version: { + readonly block: string; + readonly app: string; + }; + readonly height: string; + readonly chain_id: string; + /** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */ + readonly time: string; + readonly last_commit_hash: string; + readonly last_block_id: BlockId; + /** Can be empty */ + readonly data_hash: string; + readonly validators_hash: string; + readonly next_validators_hash: string; + readonly consensus_hash: string; + readonly app_hash: string; + /** Can be empty */ + readonly last_results_hash: string; + /** Can be empty */ + readonly evidence_hash: string; + readonly proposer_address: string; +} +interface Block { + readonly header: BlockHeader; + readonly data: { + /** Array of base64 encoded transactions */ + readonly txs: readonly string[] | null; + }; +} +export interface BlockResponse { + readonly block_id: BlockId; + readonly block: Block; +} +export interface CosmosSdkAccount { + /** Bech32 account address */ + readonly address: string; + readonly coins: readonly Coin[]; + /** Bech32 encoded pubkey */ + readonly public_key: string; + readonly account_number: number; + readonly sequence: number; +} +export interface AuthAccountsResponse { + readonly height: string; + readonly result: { + readonly type: "cosmos-sdk/Account"; + readonly value: CosmosSdkAccount; + }; +} +export interface TxsResponse { + readonly height: string; + readonly txhash: string; + /** 🤷‍♂️ */ + readonly codespace?: string; + /** Falsy when transaction execution succeeded. Contains error code on error. */ + readonly code?: number; + readonly raw_log: string; + readonly logs?: object; + readonly tx: CosmosSdkTx; + /** The gas limit as set by the user */ + readonly gas_wanted?: string; + /** The gas used by the execution */ + readonly gas_used?: string; + readonly timestamp: string; +} +export interface SearchTxsResponse { + readonly total_count: string; + readonly count: string; + readonly page_number: string; + readonly page_total: string; + readonly limit: string; + readonly txs: readonly TxsResponse[]; +} +export interface PostTxsResponse { + readonly height: string; + readonly txhash: string; + readonly code?: number; + /** + * The result data of the execution (hex encoded). + * + * @see https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/types/result.go#L101 + */ + readonly data?: string; + readonly raw_log?: string; + /** The same as `raw_log` but deserialized? */ + readonly logs?: object; + /** The gas limit as set by the user */ + readonly gas_wanted?: string; + /** The gas used by the execution */ + readonly gas_used?: string; +} +export {}; diff --git a/packages/sdk38/types/lcdapi/index.d.ts b/packages/sdk38/types/lcdapi/index.d.ts index 7341b9bf..5c36adce 100644 --- a/packages/sdk38/types/lcdapi/index.d.ts +++ b/packages/sdk38/types/lcdapi/index.d.ts @@ -1,146 +1,11 @@ -import { Coin } from "../coins"; -import { CosmosSdkTx } from "../types"; export { SupplyModule, TotalSupplyAllReponse, TotalSupplyReponse } from "./supply"; -/** - * The mode used to send transaction - * - * @see https://cosmos.network/rpc/#/Transactions/post_txs - */ -export declare enum BroadcastMode { - /** Return after tx commit */ - Block = "block", - /** Return afer CheckTx */ - Sync = "sync", - /** Return right away */ - Async = "async", -} -/** A reponse from the /txs/encode endpoint */ -export interface EncodeTxResponse { - /** base64-encoded amino-binary encoded representation */ - readonly tx: string; -} -interface NodeInfo { - readonly protocol_version: { - readonly p2p: string; - readonly block: string; - readonly app: string; - }; - readonly id: string; - readonly listen_addr: string; - readonly network: string; - readonly version: string; - readonly channels: string; - readonly moniker: string; - readonly other: { - readonly tx_index: string; - readonly rpc_address: string; - }; -} -interface ApplicationVersion { - readonly name: string; - readonly server_name: string; - readonly client_name: string; - readonly version: string; - readonly commit: string; - readonly build_tags: string; - readonly go: string; -} -export interface NodeInfoResponse { - readonly node_info: NodeInfo; - readonly application_version: ApplicationVersion; -} -interface BlockId { - readonly hash: string; -} -interface BlockHeader { - readonly version: { - readonly block: string; - readonly app: string; - }; - readonly height: string; - readonly chain_id: string; - /** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */ - readonly time: string; - readonly last_commit_hash: string; - readonly last_block_id: BlockId; - /** Can be empty */ - readonly data_hash: string; - readonly validators_hash: string; - readonly next_validators_hash: string; - readonly consensus_hash: string; - readonly app_hash: string; - /** Can be empty */ - readonly last_results_hash: string; - /** Can be empty */ - readonly evidence_hash: string; - readonly proposer_address: string; -} -interface Block { - readonly header: BlockHeader; - readonly data: { - /** Array of base64 encoded transactions */ - readonly txs: ReadonlyArray | null; - }; -} -export interface BlockResponse { - readonly block_id: BlockId; - readonly block: Block; -} -export interface CosmosSdkAccount { - /** Bech32 account address */ - readonly address: string; - readonly coins: ReadonlyArray; - /** Bech32 encoded pubkey */ - readonly public_key: string; - readonly account_number: number; - readonly sequence: number; -} -export interface AuthAccountsResponse { - readonly height: string; - readonly result: { - readonly type: "cosmos-sdk/Account"; - readonly value: CosmosSdkAccount; - }; -} -export interface TxsResponse { - readonly height: string; - readonly txhash: string; - /** 🤷‍♂️ */ - readonly codespace?: string; - /** Falsy when transaction execution succeeded. Contains error code on error. */ - readonly code?: number; - readonly raw_log: string; - readonly logs?: object; - readonly tx: CosmosSdkTx; - /** The gas limit as set by the user */ - readonly gas_wanted?: string; - /** The gas used by the execution */ - readonly gas_used?: string; - readonly timestamp: string; -} -export interface SearchTxsResponse { - readonly total_count: string; - readonly count: string; - readonly page_number: string; - readonly page_total: string; - readonly limit: string; - readonly txs: readonly TxsResponse[]; -} -export interface PostTxsResponse { - readonly height: string; - readonly txhash: string; - readonly code?: number; - /** - * The result data of the execution (hex encoded). - * - * @see https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/types/result.go#L101 - */ - readonly data?: string; - readonly raw_log?: string; - /** The same as `raw_log` but deserialized? */ - readonly logs?: object; - /** The gas limit as set by the user */ - readonly gas_wanted?: string; - /** The gas used by the execution */ - readonly gas_used?: string; -} +export { + AuthAccountsResponse, + BlockResponse, + BroadcastMode, + EncodeTxResponse, + PostTxsResponse, + NodeInfoResponse, + SearchTxsResponse, + TxsResponse, +} from "./base"; diff --git a/packages/sdk38/types/lcdclient.d.ts b/packages/sdk38/types/lcdapi/lcdclient.d.ts similarity index 97% rename from packages/sdk38/types/lcdclient.d.ts rename to packages/sdk38/types/lcdapi/lcdclient.d.ts index 349373ea..b0e6fe67 100644 --- a/packages/sdk38/types/lcdclient.d.ts +++ b/packages/sdk38/types/lcdapi/lcdclient.d.ts @@ -1,3 +1,4 @@ +import { CosmosSdkTx, StdTx } from "../types"; import { AuthAccountsResponse, BlockResponse, @@ -7,11 +8,10 @@ import { PostTxsResponse, SearchTxsResponse, TxsResponse, -} from "./lcdapi"; -import { CosmosSdkTx, StdTx } from "./types"; +} from "./base"; /** Unfortunately, Cosmos SDK encodes empty arrays as null */ -export declare type LcdApiArray = ReadonlyArray | null; -export declare function normalizeArray(backend: LcdApiArray): ReadonlyArray; +export declare type LcdApiArray = readonly T[] | null; +export declare function normalizeArray(backend: LcdApiArray): readonly T[]; export declare type LcdModule = Record any>; declare type LcdModuleSetup = (base: LcdClient) => M; export interface LcdClientBaseOptions { diff --git a/packages/sdk38/types/lcdapi/lcdclient.spec.d.ts b/packages/sdk38/types/lcdapi/lcdclient.spec.d.ts new file mode 100644 index 00000000..42096dd0 --- /dev/null +++ b/packages/sdk38/types/lcdapi/lcdclient.spec.d.ts @@ -0,0 +1,8 @@ +/** Deployed as part of scripts/wasmd/init.sh */ +export declare const deployedErc20: { + codeId: number; + source: string; + builder: string; + checksum: string; + instances: string[]; +}; diff --git a/packages/sdk38/types/lcdapi/supply.d.ts b/packages/sdk38/types/lcdapi/supply.d.ts index 321869a9..90186538 100644 --- a/packages/sdk38/types/lcdapi/supply.d.ts +++ b/packages/sdk38/types/lcdapi/supply.d.ts @@ -1,5 +1,5 @@ import { Coin } from "../coins"; -import { LcdApiArray, LcdClient, LcdModule } from "../lcdclient"; +import { LcdApiArray, LcdClient, LcdModule } from "./lcdclient"; export interface TotalSupplyAllReponse { readonly height: string; readonly result: LcdApiArray;