UNPKG

@emeraldpay/api

Version:
130 lines (129 loc) 4.62 kB
import * as blockchain_pb from './generated/blockchain_pb'; import * as common_pb from './generated/common_pb'; import { DataMapper } from './Publisher'; import { AnyAddress, AnyAsset, Blockchain, ConvertCommon, SingleAddress } from './typesCommon'; import { MessageFactory } from './typesConvert'; export type ChainHead = { chain: number; height: number; blockId: string; timestamp: Date; }; export type NativeCallItem = { id: number; method: string; payload: Array<any>; }; export type NativeCallResponse = { id: number; payload: any; success: boolean; }; export type NativeCallError = { id: number; success: boolean; message: string | undefined; }; export declare function isNativeCallResponse(obj: NativeCallResponse | NativeCallError): obj is NativeCallResponse; export declare function isNativeCallError(obj: NativeCallResponse | NativeCallError): obj is NativeCallError; export type BalanceRequest = { asset: AnyAsset; address: AnyAddress; includeUtxo?: boolean; }; export interface AddressBalance { asset: AnyAsset; address: SingleAddress; balance: string; utxo?: Utxo[] | undefined; } export interface Utxo { txid: string; vout: number; value: string; spent: boolean; } export interface TxStatusRequest { blockchain: number; txid: string; limit: number; } export interface TxStatusResponse { txid: string; broadcast: boolean; mined: boolean; block?: { height: number; hash: string; timestamp: Date; }; confirmations: number; } /** * Request for a Fee Estimation */ export interface EstimateFeeRequest { blockchain: number; mode: EstimationMode; blocks: number; } /** * Mode of estimation: * avgLast - Average over last transaction in each block * avgTail5 - Average over transaction 5th from the end in each block * avgTail20 - Average over transaction 20th from the end in each block * avgTail50 - Average over transaction 50th from the end in each block * minAlways - Minimal fee that would be accepted by every last block * avgMiddle - Average over transaction in the middle of each block * avgTop - Average over transaction in head of each block. Note that for Bitcoin it doesn't count COINBASE tx as top tx. */ export type EstimationMode = 'avgLast' | 'avgTail5' | 'avgTail20' | 'avgTail50' | 'minAlways' | 'avgMiddle' | 'avgTop'; export interface EthereumStdFees { type: 'ethereumStd'; /** * Fee value in Wei */ fee: string; } export interface EthereumExtFees { type: 'ethereumExt'; /** * Estimated fee that would be actually paid. I.e. it's the Base Fee + Priority Fee */ expect: string; /** * Priority Fee in Wei */ priority: string; /** * Max Fee value in Wei. Note that it only indicated current preference and actual Max may be significantly lower, depending on the usage scenario. */ max: string; } export interface BitcoinStdFees { type: 'bitcoinStd'; /** * Fee in Satoshi per Kilobyte. Note that the actual fee calculation MUST divide it by 1024 at the last step to get a fair fee. */ satPerKb: number; } export type EstimateFeeResponse = EthereumExtFees | EthereumStdFees | BitcoinStdFees; export declare function isEthereumStdFees(obj: EstimateFeeResponse): obj is EthereumStdFees; export declare function isEthereumExtFees(obj: EstimateFeeResponse): obj is EthereumExtFees; export declare function isBitcoinStdFees(obj: EstimateFeeResponse): obj is BitcoinStdFees; export declare class ConvertBlockchain { private readonly factory; private readonly common; constructor(factory: MessageFactory, common?: ConvertCommon); chain(blockchain: Blockchain): common_pb.Chain; headResponse(): DataMapper<blockchain_pb.ChainHead, ChainHead>; nativeCallRequest(chain: Blockchain, calls: NativeCallItem[]): blockchain_pb.NativeCallRequest; nativeCallResponse(): DataMapper<blockchain_pb.NativeCallReplyItem, NativeCallResponse | NativeCallError>; balanceRequest(req: BalanceRequest): blockchain_pb.BalanceRequest; balanceResponse(): DataMapper<blockchain_pb.AddressBalance, AddressBalance>; txRequest(req: TxStatusRequest): blockchain_pb.TxStatusRequest; txResponse(): DataMapper<blockchain_pb.TxStatus, TxStatusResponse>; estimationMode(mode: EstimationMode): blockchain_pb.FeeEstimationMode; estimateFeeRequest(req: EstimateFeeRequest): blockchain_pb.EstimateFeeRequest; estimateFeeResponse(): DataMapper<blockchain_pb.EstimateFeeResponse, EstimateFeeResponse>; }