diff --git a/types/address.d.ts b/types/address.d.ts index c5cba906..776cb61d 100644 --- a/types/address.d.ts +++ b/types/address.d.ts @@ -1,23 +1,12 @@ import { Address, PubkeyBundle } from "@iov/bcp"; -export declare type CosmosAddressBech32Prefix = - | "cosmos" - | "cosmosvalcons" - | "cosmosvaloper"; -export declare type CosmosPubkeyBech32Prefix = - | "cosmospub" - | "cosmosvalconspub" - | "cosmosvaloperpub"; -export declare type CosmosBech32Prefix = - | CosmosAddressBech32Prefix - | CosmosPubkeyBech32Prefix; +export declare type CosmosAddressBech32Prefix = "cosmos" | "cosmosvalcons" | "cosmosvaloper"; +export declare type CosmosPubkeyBech32Prefix = "cosmospub" | "cosmosvalconspub" | "cosmosvaloperpub"; +export declare type CosmosBech32Prefix = CosmosAddressBech32Prefix | CosmosPubkeyBech32Prefix; export declare function decodeCosmosAddress( - address: Address + address: Address, ): { readonly prefix: CosmosAddressBech32Prefix; readonly data: Uint8Array; }; export declare function isValidAddress(address: string): boolean; -export declare function pubkeyToAddress( - pubkey: PubkeyBundle, - prefix: CosmosBech32Prefix -): Address; +export declare function pubkeyToAddress(pubkey: PubkeyBundle, prefix: CosmosBech32Prefix): Address; diff --git a/types/cosmoscodec.d.ts b/types/cosmoscodec.d.ts index 59482edc..64de7f38 100644 --- a/types/cosmoscodec.d.ts +++ b/types/cosmoscodec.d.ts @@ -8,17 +8,18 @@ import { SigningJob, TransactionId, TxCodec, - UnsignedTransaction + UnsignedTransaction, } from "@iov/bcp"; +import { CosmosBech32Prefix } from "./address"; +import { TokenInfos } from "./types"; export declare class CosmosCodec implements TxCodec { + private readonly prefix; + private readonly tokens; + constructor(prefix: CosmosBech32Prefix, tokens: TokenInfos); bytesToSign(unsigned: UnsignedTransaction, nonce: Nonce): SigningJob; bytesToPost(signed: SignedTransaction): PostableBytes; identifier(signed: SignedTransaction): TransactionId; - parseBytes( - bytes: PostableBytes, - chainId: ChainId, - nonce?: Nonce - ): SignedTransaction; + parseBytes(bytes: PostableBytes, chainId: ChainId, nonce?: Nonce): SignedTransaction; identityToAddress(identity: Identity): Address; isValidAddress(address: string): boolean; } diff --git a/types/cosmosconnection.d.ts b/types/cosmosconnection.d.ts index 94efb242..4c8e8f66 100644 --- a/types/cosmosconnection.d.ts +++ b/types/cosmosconnection.d.ts @@ -17,16 +17,20 @@ import { TokenTicker, TransactionId, TransactionQuery, - UnsignedTransaction + UnsignedTransaction, } from "@iov/bcp"; import { Stream } from "xstream"; +import { CosmosBech32Prefix } from "./address"; +import { TokenInfos } from "./types"; export declare class CosmosConnection implements BlockchainConnection { - static establish(url: string): Promise; + static establish(url: string, prefix: CosmosBech32Prefix, tokenInfo: TokenInfos): Promise; private static initialize; private readonly restClient; private readonly chainData; private readonly primaryToken; private readonly supportedTokens; + private readonly _prefix; + private readonly tokenInfo; private get prefix(); private constructor(); disconnect(): void; @@ -37,29 +41,16 @@ export declare class CosmosConnection implements BlockchainConnection { getAccount(query: AccountQuery): Promise; watchAccount(_account: AccountQuery): Stream; getNonce(query: AddressQuery | PubkeyQuery): Promise; - getNonces( - query: AddressQuery | PubkeyQuery, - count: number - ): Promise; + getNonces(query: AddressQuery | PubkeyQuery, count: number): Promise; getBlockHeader(height: number): Promise; watchBlockHeaders(): Stream; - getTx( - id: TransactionId - ): Promise< - ConfirmedAndSignedTransaction | FailedTransaction - >; + getTx(id: TransactionId): Promise | FailedTransaction>; postTx(tx: PostableBytes): Promise; searchTx( - query: TransactionQuery - ): Promise< - readonly (ConfirmedTransaction | FailedTransaction)[] - >; - listenTx( - _query: TransactionQuery - ): Stream | FailedTransaction>; - liveTx( - _query: TransactionQuery - ): Stream | FailedTransaction>; + query: TransactionQuery, + ): Promise | FailedTransaction)[]>; + listenTx(_query: TransactionQuery): Stream | FailedTransaction>; + liveTx(_query: TransactionQuery): Stream | FailedTransaction>; getFeeQuote(tx: UnsignedTransaction): Promise; withDefaultFee(tx: T): Promise; private parseAndPopulateTxResponse; diff --git a/types/cosmosconnector.d.ts b/types/cosmosconnector.d.ts index 6a18915d..509a8068 100644 --- a/types/cosmosconnector.d.ts +++ b/types/cosmosconnector.d.ts @@ -1,9 +1,13 @@ import { ChainConnector, ChainId } from "@iov/bcp"; import { CosmosConnection } from "./cosmosconnection"; +import { CosmosBech32Prefix } from "./address"; +import { TokenInfos } from "./types"; /** * A helper to connect to a cosmos-based chain at a given url */ export declare function createCosmosConnector( url: string, - expectedChainId?: ChainId + prefix: CosmosBech32Prefix, + tokenInfo: TokenInfos, + expectedChainId?: ChainId, ): ChainConnector; diff --git a/types/decode.d.ts b/types/decode.d.ts index ac66c871..8b7332c7 100644 --- a/types/decode.d.ts +++ b/types/decode.d.ts @@ -9,30 +9,27 @@ import { SendTransaction, SignatureBytes, SignedTransaction, - UnsignedTransaction + UnsignedTransaction, } from "@iov/bcp"; import amino from "@tendermint/amino-js"; import { TxsResponse } from "./restclient"; +import { TokenInfos } from "./types"; export declare function decodePubkey(pubkey: amino.PubKey): PubkeyBundle; export declare function decodeSignature(signature: string): SignatureBytes; -export declare function decodeFullSignature( - signature: amino.StdSignature, - nonce: number -): FullSignature; -export declare function decodeAmount(amount: amino.Coin): Amount; -export declare function parseMsg( - msg: amino.Msg, - chainId: ChainId -): SendTransaction; -export declare function parseFee(fee: amino.StdFee): Fee; +export declare function decodeFullSignature(signature: amino.StdSignature, nonce: number): FullSignature; +export declare const decodeAmount: (tokens: TokenInfos) => (coin: amino.Coin) => Amount; +export declare function parseMsg(msg: amino.Msg, chainId: ChainId, tokens: TokenInfos): SendTransaction; +export declare function parseFee(fee: amino.StdFee, tokens: TokenInfos): Fee; export declare function parseTx( tx: amino.Tx, chainId: ChainId, - nonce: Nonce + nonce: Nonce, + tokens: TokenInfos, ): SignedTransaction; export declare function parseTxsResponse( chainId: ChainId, currentHeight: number, nonce: Nonce, - response: TxsResponse + response: TxsResponse, + tokens: TokenInfos, ): ConfirmedAndSignedTransaction; diff --git a/types/encode.d.ts b/types/encode.d.ts index e5931aef..2a0788df 100644 --- a/types/encode.d.ts +++ b/types/encode.d.ts @@ -1,18 +1,9 @@ -import { - Amount, - Fee, - FullSignature, - PubkeyBundle, - SignedTransaction, - UnsignedTransaction -} from "@iov/bcp"; +import { Amount, Fee, FullSignature, PubkeyBundle, SignedTransaction, UnsignedTransaction } from "@iov/bcp"; import amino from "@tendermint/amino-js"; -import { AminoTx } from "./types"; +import { AminoTx, TokenInfos } from "./types"; export declare function encodePubkey(pubkey: PubkeyBundle): amino.PubKey; -export declare function encodeAmount(amount: Amount): amino.Coin; -export declare function encodeFee(fee: Fee): amino.StdFee; -export declare function encodeFullSignature( - fullSignature: FullSignature -): amino.StdSignature; -export declare function buildUnsignedTx(tx: UnsignedTransaction): AminoTx; -export declare function buildSignedTx(tx: SignedTransaction): AminoTx; +export declare function encodeAmount(amount: Amount, tokens: TokenInfos): amino.Coin; +export declare function encodeFee(fee: Fee, tokens: TokenInfos): amino.StdFee; +export declare function encodeFullSignature(fullSignature: FullSignature): amino.StdSignature; +export declare function buildUnsignedTx(tx: UnsignedTransaction, tokens: TokenInfos): AminoTx; +export declare function buildSignedTx(tx: SignedTransaction, tokens: TokenInfos): AminoTx; diff --git a/types/restclient.d.ts b/types/restclient.d.ts index 9097d2cb..df1d9251 100644 --- a/types/restclient.d.ts +++ b/types/restclient.d.ts @@ -69,10 +69,7 @@ export declare class RestClient { nodeInfo(): Promise; blocksLatest(): Promise; blocks(height: number): Promise; - authAccounts( - address: Address, - height?: string - ): Promise; + authAccounts(address: Address, height?: string): Promise; txs(query: string): Promise; txsById(id: TransactionId): Promise; postTx(tx: PostableBytes): Promise; diff --git a/types/types.d.ts b/types/types.d.ts index adcda576..62d5ab9b 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -1,7 +1,12 @@ +import { Amount, Token } from "@iov/bcp"; import amino from "@tendermint/amino-js"; export declare type AminoTx = amino.Tx & { readonly value: amino.StdTx; }; -export declare function isAminoStdTx( - txValue: amino.TxValue -): txValue is amino.StdTx; +export declare function isAminoStdTx(txValue: amino.TxValue): txValue is amino.StdTx; +export interface TokenInfo extends Token { + readonly denom: string; +} +export declare type TokenInfos = ReadonlyArray; +export declare function amountToCoin(lookup: ReadonlyArray, amount: Amount): amino.Coin; +export declare function coinToAmount(tokens: TokenInfos, coin: amino.Coin): Amount;