import type { Transaction as ITransaction } from './transaction-manager.js'; import type { Address } from '@hoprnet/hopr-utils'; /** * @property highestLocallyConfirmed - A hex string of the highest nonce on a confirmed transaction. * @property nextNetworkNonce - The next nonce suggested by the eth_getTransactionCount method. * @property highestSuggested - The maximum between the other two, the number returned. * @property local - Nonce details derived from pending transactions and highestSuggested * @property network - Nonce details from the eth_getTransactionCount method */ export type NonceDetails = { params: { highestLocallyConfirmed: number; nextNetworkNonce: number; highestSuggested: number; }; local: HighestContinuousFrom; network: NetworkNextNonce; }; /** * @property nextNonce - The highest of the nonce values derived based on confirmed and pending transactions and eth_getTransactionCount method * @property nonceDetails - details of nonce value derivation. * @property releaseLock */ export interface NonceLock { nextNonce: number; nonceDetails: NonceDetails; releaseLock: () => void; } /** * @property name - The name for how the nonce was calculated based on the data used * @property nonce - The next nonce value suggested by the eth_getTransactionCount method. * @property blockNumber - The latest block from the network * @property baseCount - Transaction count from the network suggested by eth_getTransactionCount method */ export type NetworkNextNonce = { name: string; nonce: number; details: { blockNumber: number; baseCount: number; }; }; /** * @property name - The name for how the nonce was calculated based on the data used * @property nonce - The next suggested nonce * @property details{startPoint, highest} - the provided starting nonce that was used and highest derived from it (for debugging) */ export type HighestContinuousFrom = { name: string; nonce: number; details: { startPoint: number; highest: number; }; }; export type Transaction = ITransaction & { status?: string; from?: string; hash?: string; }; /** * A simple nonce-tracker that takes into account nonces which have failed, * this could happen because of network issues, low funds, node unavailability, etc. */ export default class NonceTracker { private api; private minPending?; private lockMap; constructor(api: { getLatestBlockNumber: () => Promise; getTransactionCount: (address: Address, blockNumber?: number) => Promise; getPendingTransactions: (address: Address) => Transaction[]; getConfirmedTransactions: (address: Address) => Transaction[]; }, minPending?: number); /** * @returns Promise<{ releaseLock: () => void }> with the key releaseLock (the global mutex) */ getGlobalLock(): Promise<{ releaseLock: () => void; }>; /** * this will return an object with the `nextNonce` `nonceDetails`, and the releaseLock * Note: releaseLock must be called after adding a signed tx to pending transactions (or discarding). * * @param address the hex string for the address whose nonce we are calculating * @returns {Promise} */ getNonceLock(address: Address): Promise; /** * It's possible we encounter transactions that are pending for a very long time, * this can happen if a transaction is under-funded. * This function will return `true` if it finds a pending transaction that has * been pending for more than {minPending} ms. * @param txs * @return true if it contains a stuck transaction */ private _containsStuckTx; private _globalMutexFree; private _takeMutex; /** * Function returns the nonce details from the network based on the latest block * and eth_getTransactionCount method * * @param address the hex string for the address whose nonce we are calculating * @returns {Promise} */ private _getNetworkNextNonce; private _lookupMutex; /** * Function returns the highest of the confirmed transaction from the address. * @param address the hex string for the address whose nonce we are calculating */ private _getHighestLocallyConfirmed; /** * Function returns highest nonce value from the transcation list provided * @param txList list of transactions */ private _getHighestNonce; /** * Function return the nonce value higher than the highest nonce value from the transaction list * starting from startPoint * @param txList {array} - list of txMeta's * @param startPoint {number} - the highest known locally confirmed nonce */ private _getHighestContinuousFrom; } //# sourceMappingURL=nonce-tracker.d.ts.map