Commit updated types

This commit is contained in:
Ethan Frey 2020-01-22 23:33:17 +01:00
parent f1ad81a05a
commit 310dad2a0f
8 changed files with 55 additions and 80 deletions

21
types/address.d.ts vendored
View File

@ -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;

View File

@ -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;
}

View File

@ -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<CosmosConnection>;
static establish(url: string, prefix: CosmosBech32Prefix, tokenInfo: TokenInfos): Promise<CosmosConnection>;
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<Account | undefined>;
watchAccount(_account: AccountQuery): Stream<Account | undefined>;
getNonce(query: AddressQuery | PubkeyQuery): Promise<Nonce>;
getNonces(
query: AddressQuery | PubkeyQuery,
count: number
): Promise<readonly Nonce[]>;
getNonces(query: AddressQuery | PubkeyQuery, count: number): Promise<readonly Nonce[]>;
getBlockHeader(height: number): Promise<BlockHeader>;
watchBlockHeaders(): Stream<BlockHeader>;
getTx(
id: TransactionId
): Promise<
ConfirmedAndSignedTransaction<UnsignedTransaction> | FailedTransaction
>;
getTx(id: TransactionId): Promise<ConfirmedAndSignedTransaction<UnsignedTransaction> | FailedTransaction>;
postTx(tx: PostableBytes): Promise<PostTxResponse>;
searchTx(
query: TransactionQuery
): Promise<
readonly (ConfirmedTransaction<UnsignedTransaction> | FailedTransaction)[]
>;
listenTx(
_query: TransactionQuery
): Stream<ConfirmedTransaction<UnsignedTransaction> | FailedTransaction>;
liveTx(
_query: TransactionQuery
): Stream<ConfirmedTransaction<UnsignedTransaction> | FailedTransaction>;
query: TransactionQuery,
): Promise<readonly (ConfirmedTransaction<UnsignedTransaction> | FailedTransaction)[]>;
listenTx(_query: TransactionQuery): Stream<ConfirmedTransaction<UnsignedTransaction> | FailedTransaction>;
liveTx(_query: TransactionQuery): Stream<ConfirmedTransaction<UnsignedTransaction> | FailedTransaction>;
getFeeQuote(tx: UnsignedTransaction): Promise<Fee>;
withDefaultFee<T extends UnsignedTransaction>(tx: T): Promise<T>;
private parseAndPopulateTxResponse;

View File

@ -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<CosmosConnection>;

23
types/decode.d.ts vendored
View File

@ -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<UnsignedTransaction>;

23
types/encode.d.ts vendored
View File

@ -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;

View File

@ -69,10 +69,7 @@ export declare class RestClient {
nodeInfo(): Promise<NodeInfoResponse>;
blocksLatest(): Promise<BlocksResponse>;
blocks(height: number): Promise<BlocksResponse>;
authAccounts(
address: Address,
height?: string
): Promise<AuthAccountsResponse>;
authAccounts(address: Address, height?: string): Promise<AuthAccountsResponse>;
txs(query: string): Promise<SearchTxsResponse>;
txsById(id: TransactionId): Promise<TxsResponse>;
postTx(tx: PostableBytes): Promise<PostTxsResponse>;

11
types/types.d.ts vendored
View File

@ -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<TokenInfo>;
export declare function amountToCoin(lookup: ReadonlyArray<TokenInfo>, amount: Amount): amino.Coin;
export declare function coinToAmount(tokens: TokenInfos, coin: amino.Coin): Amount;