import BigNumber from 'bignumber.js'; import { Address } from './address'; import { Block } from './block'; import { Transaction } from './transaction'; export interface SendOptions { to: Address | string; value: BigNumber; data?: string; fee?: number; } export interface ChainProvider { /** * Generate a block * @param {!number} numberOfBlocks - Number of blocks to be generated * @return {} */ generateBlock(numberOfBlocks: number): Promise; /** * Get a block given its hash. * @param {!string} blockHash - A hexadecimal string that represents the * *hash* of the desired block. * @param {boolean} [includeTx=false] - If true, fetches transactions in the block. * @return {Promise} * Resolves with a Block with the same hash as the given input. * If `includeTx` is true, the transaction property is an array of Transactions; * otherwise, it is a list of transaction hashes. * Rejects with TypeError if input is invalid. * Rejects with InvalidProviderResponseError if provider's response is invalid. */ getBlockByHash(blockHash: string, includeTx?: boolean): Promise; /** * Get a block given its number. * @param {!number} blockNumber - The number of the desired block. * @param {boolean} [includeTx=false] - If true, fetches transaction in the block. * @return {Promise} * Resolves with a Block with the same number as the given input. * If `includeTx` is true, the transaction property is an array of Transactions; * otherwise, it is a list of transaction hashes. * Rejects with TypeError if input is invalid. * Rejects with InvalidProviderResponseError if provider's response is invalid. */ getBlockByNumber(blockNumber: number, includeTx?: boolean): Promise; /** * Get current block height of the chain. * @return {Promise} Resolves with * chain height. * Rejects with InvalidProviderResponseError if provider's response is invalid. */ getBlockHeight(): Promise; /** * Get a transaction given its hash. * @param {!string} txHash - A hexadecimal string that represents the *hash* of the * desired transaction. * @return {Promise} * Resolves with a Transaction with the same hash as the given input. * Rejects with TypeError if input is invalid. * Rejects with InvalidProviderResponseError if provider's response is invalid. */ getTransactionByHash(txHash: string): Promise; /** * Get the balance of an account given its addresses. * @param {(string | Address)[]} addresses - A list of addresses. * @return {Promise} If addresses is given, * returns the cumulative balance of the given addresses. Otherwise returns the balance * of the addresses that the signing provider controls. * Rejects with InvalidProviderResponseError if provider's response is invalid. */ getBalance(addresses: (Address | string)[]): Promise; /** * Create, sign & broadcast a transaction. * @param {!string} to - Recepient address. * @param {!number} value - Value of transaction. * @param {!string} data - Data to be passed to the transaction. * @param {!Fee} [fee] - Fee price in native unit (e.g. sat/b, wei) * @return {Promise} Resolves with a signed transaction. */ sendTransaction(options: SendOptions): Promise; /** * Create, sign & broadcast a sweep transaction. * @param {!string} address - External address. * @param {Fee} [fee] - Fee price in native unit (e.g. sat/b, wei) * @return {Promise} Resolves with a signed transaction. */ sendSweepTransaction( address: Address | string, fee?: number, ): Promise; /** * Update the fee of a transaction. * @param {(string|Transaction)} tx - Transaction object or hash of the transaction to update * @param {!Fee} newFee - New fee price in native unit (e.g. sat/b, wei) * @return {Promise} Resolves with the new transaction */ updateTransactionFee( tx: string | Transaction, newFee: number, ): Promise; /** * Create, sign & broad a transaction with multiple outputs. * @param {string[]} transactions - to, value, data * @return {Promise} Resolves with a signed transaction. */ sendBatchTransaction(transactions: SendOptions[]): Promise; /** * Broadcast a signed transaction to the network. * @param {!string} rawTransaction - A raw transaction usually in the form of a * hexadecimal string that represents the serialized transaction. * @return {Promise} Resolves with an * identifier for the broadcasted transaction. * Rejects with InvalidProviderResponseError if provider's response is invalid. */ sendRawTransaction(rawTransaction: string): Promise; }