UNPKG

raiden-ts

Version:

Raiden Light Client Typescript/Javascript SDK

61 lines (60 loc) 3.09 kB
import type { Observable } from 'rxjs'; import type { RaidenAction } from '../../actions'; import type { Channel } from '../../channels/state'; import type { MessageType, WithdrawConfirmation, WithdrawExpired, WithdrawRequest } from '../../messages'; import { messageSend } from '../../messages/actions'; import type { UInt } from '../../utils/types'; import type { withdraw } from '../actions'; /** * Exponential back-off infinite generator * * @param start - First yielded value * @param max - Ceiling of values, won't increase above this number * @param multiplier - Multiply yielded value by this factor on each iteration * @yields Numbers representing delays in exponential backoff strategy of growth */ export declare function exponentialBackoff(start?: number, max?: number, multiplier?: number): Generator<number, void, unknown>; /** * Dispatches an actions and waits until a condition is satisfied. * * @param action$ - Observable of actions that will be monitored * @param request - The request/action that will be dispatched * @param predicate - The condition that will that was to be satisfied for the observable to * complete * @returns Observable of the request type. */ export declare function dispatchAndWait$<A extends RaidenAction>(action$: Observable<RaidenAction>, request: A, predicate: (action: RaidenAction) => boolean): Observable<A>; /** * Retry sending a message until some condition is met * * @param send - messageSend.request to be sent * @param action$ - RaidenActions observable * @param notifier - Stops retrying when this notifier emits * @param delayMs - Delay between retries, or Iterator yielding delays * @returns Observable which retry messageSend.request until notifier emits */ export declare function retrySendUntil$(send: messageSend.request, action$: Observable<RaidenAction>, notifier: Observable<unknown>, delayMs?: number | Iterator<number>): Observable<messageSend.request>; /** * Creates a type-guard function which verifies 'msg' is of given type between withdraw messages * and that total_withdraw and expiration matches given 'data'. * May be used to find matching messages in [[ChannelEnd]]'s 'pendingWithdraws' array * * @param type - Literal type tag to filter * @param data - Optional data to match, either in 'meta' or another 'message' format * @returns Typeguard function to check for matching withdraw protocol messages */ export declare function matchWithdraw<T extends MessageType.WITHDRAW_REQUEST | MessageType.WITHDRAW_CONFIRMATION | MessageType.WITHDRAW_EXPIRED, M extends WithdrawRequest | WithdrawConfirmation | WithdrawExpired>(type: T, data?: { total_withdraw: UInt<32>; expiration: UInt<32>; } | { totalWithdraw: UInt<32>; expiration: number; }): (msg: M) => msg is Extract<M, { type: T; }>; /** * @param req - WithdrawRequest message * @param channel - Channel in which it was received * @returns withdraw async action meta for respective request */ export declare function withdrawMetaFromRequest(req: WithdrawRequest, channel: Channel): withdraw.request['meta'];