launchpad: Refactor FeeTable type

This commit is contained in:
willclarktech 2020-08-18 16:40:34 +01:00
parent f30004db73
commit 914f8d94bb
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
6 changed files with 18 additions and 15 deletions

View File

@ -3,6 +3,8 @@ import { Decimal } from "@cosmjs/math";
import { coins } from "./coins";
import { StdFee } from "./types";
export type FeeTable = Record<string, StdFee>;
export class GasPrice {
public readonly amount: Decimal;
public readonly denom: string;

View File

@ -29,7 +29,7 @@ export {
isSearchByTagsQuery,
} from "./cosmosclient";
export { makeSignBytes } from "./encoding";
export { buildFeeTable, GasPrice } from "./gas";
export { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./gas";
export {
AuthAccountsResponse,
AuthExtension,
@ -98,7 +98,7 @@ export {
} from "./pubkey";
export { findSequenceForSignedTx } from "./sequence";
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
export { FeeTable, SigningCosmosClient } from "./signingcosmosclient";
export { CosmosFeeTable, SigningCosmosClient } from "./signingcosmosclient";
export { isStdTx, pubkeyType, CosmosSdkTx, PubKey, StdFee, StdSignature, StdTx } from "./types";
export {
AccountData,

View File

@ -2,7 +2,7 @@
import { Coin } from "./coins";
import { Account, BroadcastTxResult, CosmosClient, GetSequenceResult } from "./cosmosclient";
import { makeSignBytes } from "./encoding";
import { buildFeeTable, GasLimits, GasPrice } from "./gas";
import { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./gas";
import { BroadcastMode } from "./lcdapi";
import { Msg, MsgSend } from "./msgs";
import { StdFee, StdTx } from "./types";
@ -11,23 +11,23 @@ import { OfflineSigner } from "./wallet";
/**
* These fees are used by the higher level methods of SigningCosmosClient
*/
export interface FeeTable extends Record<string, StdFee> {
export interface CosmosFeeTable extends FeeTable {
readonly send: StdFee;
}
const defaultGasPrice = GasPrice.fromString("0.025ucosm");
const defaultGasLimits: GasLimits<FeeTable> = { send: 80000 };
const defaultGasLimits: GasLimits<CosmosFeeTable> = { send: 80000 };
/** Use for testing only */
export interface PrivateSigningCosmosClient {
readonly fees: FeeTable;
readonly fees: CosmosFeeTable;
}
export class SigningCosmosClient extends CosmosClient {
public readonly senderAddress: string;
private readonly signer: OfflineSigner;
private readonly fees: FeeTable;
private readonly fees: CosmosFeeTable;
/**
* Creates a new client with signing capability to interact with a Cosmos SDK blockchain. This is the bigger brother of CosmosClient.
@ -47,14 +47,14 @@ export class SigningCosmosClient extends CosmosClient {
senderAddress: string,
signer: OfflineSigner,
gasPrice: GasPrice = defaultGasPrice,
gasLimits: Partial<GasLimits<FeeTable>> = {},
gasLimits: Partial<GasLimits<CosmosFeeTable>> = {},
broadcastMode = BroadcastMode.Block,
) {
super(apiUrl, broadcastMode);
this.anyValidAddress = senderAddress;
this.senderAddress = senderAddress;
this.signer = signer;
this.fees = buildFeeTable<FeeTable>(gasPrice, defaultGasLimits, gasLimits);
this.fees = buildFeeTable<CosmosFeeTable>(gasPrice, defaultGasLimits, gasLimits);
}
public async getSequence(address?: string): Promise<GetSequenceResult> {

View File

@ -1,5 +1,6 @@
import { Decimal } from "@cosmjs/math";
import { StdFee } from "./types";
export declare type FeeTable = Record<string, StdFee>;
export declare class GasPrice {
readonly amount: Decimal;
readonly denom: string;

View File

@ -27,7 +27,7 @@ export {
isSearchByTagsQuery,
} from "./cosmosclient";
export { makeSignBytes } from "./encoding";
export { buildFeeTable, GasPrice } from "./gas";
export { buildFeeTable, FeeTable, GasLimits, GasPrice } from "./gas";
export {
AuthAccountsResponse,
AuthExtension,
@ -96,7 +96,7 @@ export {
} from "./pubkey";
export { findSequenceForSignedTx } from "./sequence";
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
export { FeeTable, SigningCosmosClient } from "./signingcosmosclient";
export { CosmosFeeTable, SigningCosmosClient } from "./signingcosmosclient";
export { isStdTx, pubkeyType, CosmosSdkTx, PubKey, StdFee, StdSignature, StdTx } from "./types";
export {
AccountData,

View File

@ -1,6 +1,6 @@
import { Coin } from "./coins";
import { Account, BroadcastTxResult, CosmosClient, GetSequenceResult } from "./cosmosclient";
import { GasLimits, GasPrice } from "./gas";
import { FeeTable, GasLimits, GasPrice } from "./gas";
import { BroadcastMode } from "./lcdapi";
import { Msg } from "./msgs";
import { StdFee } from "./types";
@ -8,12 +8,12 @@ import { OfflineSigner } from "./wallet";
/**
* These fees are used by the higher level methods of SigningCosmosClient
*/
export interface FeeTable extends Record<string, StdFee> {
export interface CosmosFeeTable extends FeeTable {
readonly send: StdFee;
}
/** Use for testing only */
export interface PrivateSigningCosmosClient {
readonly fees: FeeTable;
readonly fees: CosmosFeeTable;
}
export declare class SigningCosmosClient extends CosmosClient {
readonly senderAddress: string;
@ -37,7 +37,7 @@ export declare class SigningCosmosClient extends CosmosClient {
senderAddress: string,
signer: OfflineSigner,
gasPrice?: GasPrice,
gasLimits?: Partial<GasLimits<FeeTable>>,
gasLimits?: Partial<GasLimits<CosmosFeeTable>>,
broadcastMode?: BroadcastMode,
);
getSequence(address?: string): Promise<GetSequenceResult>;