UNPKG

xud

Version:
46 lines (45 loc) 1.9 kB
/// <reference types="node" /> import { EventEmitter } from 'events'; import { SwapDealInstance } from '../db/types'; import Logger from '../Logger'; import SwapClientManager from './SwapClientManager'; interface SwapRecovery { on(event: 'recovered', listener: (recoveredSwap: SwapDealInstance) => void): this; emit(event: 'recovered', recoveredSwap: SwapDealInstance): boolean; } /** * A class that's responsible for recovering swap deals that were interrupted due to a system or xud crash, * ensuring that we do not lose funds on a partially completed swap. */ declare class SwapRecovery extends EventEmitter { private swapClientManager; private logger; static readonly PENDING_SWAP_RECHECK_INTERVAL = 300000; /** A map of payment hashes to swaps where we have a pending outgoing payment but don't know the preimage. */ private pendingSwaps; private pendingSwapsTimer?; /** The time in milliseconds between checks on the status of pending swaps. */ constructor(swapClientManager: SwapClientManager, logger: Logger); beginTimer: () => void; stopTimer: () => void; getPendingSwapHashes: () => string[]; private checkPendingSwaps; private failDeal; /** * Claims the incoming payment for a deal where the outgoing payment has * already gone through and where we already know the preimage. */ private claimPayment; /** * Checks the status of the outgoing payment for a swap where we have begun * sending a payment and handles the resolution of the swap once a final * status for the payment is determined. */ private checkPaymentStatus; /** * Attempts to recover a swap deal from whichever state it was left in * including canceling or settling any related invoices & payments. */ recoverDeal: (deal: SwapDealInstance) => Promise<void>; } export default SwapRecovery;