import { TransactionReceipt } from "web3";
import { Hash } from "./commonTypes";
import { PubSubEventService } from "./pubSubEventService";
/**
 * Enables you to track the completion of transactions triggered by Arc.js functions.
 * You can subscribe to events that tell you how many transactions are anticipated when
 * the transactions have completed.  For more information, see [Tracking Transactions](/Transactions).
 */
export declare class TransactionService extends PubSubEventService {
    /**
     * Generate a new invocation key.
     */
    static generateInvocationKey(): number;
    /**
     * Publish the `kickoff` event and return the payload that should be passed
     * to the ensuing calls to `publishTxLifecycleEvents`.
     *
     * @hidden - for internal use only
     * @param functionName Looks like [classname].[functionname], the function that is generating the transaction.
     * @param options Arbitrary object to pass in the callback for each event
     * @param txCount The expected number of transactions, will be included in the payload.
     */
    static publishKickoffEvent(functionName: string, options: any, txCount: number): TransactionReceiptsEventInfo;
    /**
     * Send the given payload to subscribers of the given topic on `sent`, `mined` and `confirmed`.
     *
     * @hidden - for internal use only
     * @param eventContext array of TxEventSpec
     * @param tx the transaction id.
     * @param contract Truffle contract wrapper for the contract that is generating the transaction.
     */
    static publishTxLifecycleEvents(eventContext: TxEventContext, tx: Hash, contract: any): void;
    static publishTxFailed(eventContext: TxEventContext, atStage: TransactionStage, error?: Error, tx?: Hash, txReceipt?: TransactionReceiptTruffle): void;
    /**
     * Return a new event stack with the given one pushed onto it.
     * Will take obj.txEventContext, else create a new one.
     *
     * @hidden - for internal use only
     * @param obj
     * @param eventSpec
     * @param addToObject True to clone obj and add the new txEventContext to it
     */
    static newTxEventContext(functionName: string, payload: TransactionReceiptsEventInfo, obj: Partial<TxGeneratingFunctionOptions> & any): TxEventContext;
    /**
     * Returns a promise of a TransactionReceipt once the given transaction has been mined.
     *
     * See also [getMinedTransaction](/api/classes/TransactionService#getMinedTransaction) and
     * [getTransactionDepth](/api/classes/TransactionService#getTransactionDepth).
     *
     * @param txHash the transaction hash
     * @param contract Optional contract instance or contract name of the contract that generated the transaction.
     * Supply this if you want decoded events (or else call `TransactionService.toTxTruffle` manually yourself)
     * @param requiredDepth Optional minimum block depth required to resolve the promise.  Default is 0.
     * @returns Promise of `TransactionReceiptTruffle` if contract is given, else `TransactionReceipt`
     */
    static watchForMinedTransaction(txHash: Hash, contract?: string | object, requiredDepth?: number): Promise<TransactionReceipt | TransactionReceiptTruffle>;
    /**
     * Returns a promise of a TransactionReceipt once the given transaction has been confirmed
     * according to the optional `requiredDepth`.
     *
     * See also [getConfirmedTransaction](/api/classes/TransactionService#getConfirmedTransaction) and
     * [getTransactionDepth](/api/classes/TransactionService#getTransactionDepth).
     *
     * @param txHash The transaction hash to watch
     * @param contract Optional contract instance or contract name of the contract that generated the transaction.
     * Supply this if you want decoded events (or else call `TransactionService.toTxTruffle` manually yourself)
     * @param requiredDepth Optional minimum block depth required to resolve the promise.
     * Default comes from the `ConfigurationService`.
     */
    static watchForConfirmedTransaction(txHash: Hash, contract?: string | object, requiredDepth?: number): Promise<TransactionReceipt | TransactionReceiptTruffle>;
    /**
     * Returns a promise of the number of blocks that have been added to the chain since
     * the given transaction appeared. Use this to decide whether a transaction is
     * sufficiently secure (confirmed).
     *
     * See also [getConfirmedTransaction](/api/classes/TransactionService#getConfirmedTransaction)
     * and [watchForConfirmedTransaction](/api/classes/TransactionService#watchForConfirmedTransaction).
     * @param tx txHash or TransactionReceipt
     * @returns Promise of the depth or -1 if the transaction cannot be found
     */
    static getTransactionDepth(tx: Hash | TransactionReceipt): Promise<number>;
    /**
     * Returns a promise of a TransactionReceipt for a mined transaction, or null if it hasn't yet been mined.
     * @param txHash
     * @param requiredDepth Optional minimum block depth required to resolve the promise.  Default is 0.
     * @param contract Optional contract instance or contract name of the contract that generated the transaction.
     * Supply this if you want decoded events (or else call `TransactionService.toTxTruffle` manually yourself)
     * @returns Promise of `TransactionReceiptTruffle` if contract is given, else `TransactionReceipt`,
     * or null if not found.
     */
    static getMinedTransaction(txHash: Hash, contract?: string | object, requiredDepth?: number): Promise<TransactionReceipt | TransactionReceiptTruffle | null>;
    /**
     * Returns a promise of a TransactionReceipt for a confirmed transaction, or null if it hasn't yet been confirmed
     * according to the requiredDepth.
     * @param txHash
     * @param requiredDepth Optional minimum block depth required to resolve the promise.
     * Default comes from the `ConfigurationService`.
     * @param contract Optional contract instance or contract name of the contract that generated the transaction.
     * Supply this if you want decoded events (or else call `TransactionService.toTxTruffle` manually yourself)
     */
    static getConfirmedTransaction(txHash: Hash, contract?: string | object, requiredDepth?: number): Promise<TransactionReceipt | TransactionReceiptTruffle | null>;
    /**
     * Convert a mined TransactionReceipt to a TransactionReceiptTruffle with more readable logs
     * such as are produced by truffle (see `DecodedLogEntry`).
     *
     * @hidden - for internal use only
     *
     * @param txReceipt The mined tx
     * @param contract The truffle contract that generated the tx
     */
    static toTxTruffle(txReceipt: TransactionReceipt, contract: string | object): Promise<TransactionReceiptTruffle>;
    /**
     * Returns a value from the given transaction log.
     * Undefined if not found for any reason.
     *
     * @param tx The transaction
     * @param arg The name of the property whose value we wish to return from the args object:
     *  tx.logs[index].args[argName]
     * @param eventName Overrides index, identifies which log,
     *  where tx.logs[n].event === eventName
     * @param index Identifies which log when eventName is not given
     */
    static getValueFromLogs(tx: TransactionReceiptTruffle | TransactionReceipt, arg: string, eventName?: string, index?: number): any | undefined;
    /**
     * Returns the default value for required block depth defined for the current network
     * in the Arc.js global configuration ("txDepthRequiredForConfirmation").
     * @param requiredDepth Overrides the default if given
     */
    static getDefaultDepth(requiredDepth?: number): Promise<number>;
    private static createPayload(functionName, options, txCount);
    private static _publishTxEvent(eventStack, tx, txReceipt, txStage, failed?, error?);
    private static topicBaseFromFunctionName(functionName);
}
export declare enum TransactionStage {
    kickoff = 0,
    sent = 1,
    mined = 2,
    confirmed = 3,
}
/**
 * Information supplied to the event callback when the event is published. Otherwise
 * known as the "payload".
 */
export interface TransactionReceiptsEventInfo {
    /**
     * A value that is unique to the invocation of the function that is generating
     * the transaction. It is useful for grouping events by a single function invocation.
     */
    invocationKey: number;
    /**
     * The options that were passed to the function that is generating the transaction, if any.
     * In most cases this will have default values filled in.
     */
    options?: any;
    /**
     * The name of the function that is generating the transactions and these events.
     */
    functionName: string;
    /**
     * The transaction hash id.  Note that the transaction may not necessarily have completed successfully
     * in the case of errors or rejection.
     * Will be null in `kickoff` events.
     */
    tx: Hash | null;
    /**
     * The `TransactionReceiptTruffle` once the transaction has been mined.
     * Will be null in `kickoff` and `sent` events.
     */
    txReceipt: TransactionReceiptTruffle | null;
    /**
     * The total expected number of transactions.
     */
    txCount: number;
    /**
     * Stage of the transaction.  Can be `kickoff`, `sent`, `mined` or `confirmed`.
     */
    txStage: TransactionStage;
    /**
     * Error when a failure has occured.  Supplied by the ".failed" events.
     */
    error?: Error;
}
/**
 * @hidden - for internal use only
 */
export declare class TxEventContext {
    invocationKey: number;
    stack: Array<TxEventSpec>;
    constructor(invocationKey: number, stack: Array<TxEventSpec>);
}
/**
 * @hidden - for internal use only
 */
export declare class TxEventSpec {
    functionName: string;
    payload: TransactionReceiptsEventInfo;
    constructor(functionName: string, payload: TransactionReceiptsEventInfo);
}
/**
 * @hidden - for internal use only
 */
export interface TxGeneratingFunctionOptions {
    txEventContext?: TxEventContext;
}
/**
 * The bundle of logs, TransactionReceipt and other information as returned by Truffle after invoking
 * a contract function that causes a transaction.
 */
export interface TransactionReceiptTruffle {
    logs: Array<any>;
    receipt: TransactionReceipt;
    transactionHash: Hash;
}
