UNPKG

raiden-ts

Version:

Raiden Light Client Typescript/Javascript SDK

154 lines 9.23 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.withdrawCompleted = exports.withdrawExpire = exports.withdrawBusy = exports.withdrawMessage = exports.withdraw = exports.withdrawResolve = exports.transferLoad = exports.transferClear = exports.transferExpireProcessed = exports.transferExpire = exports.transferUnlockProcessed = exports.transferUnlock = exports.transferSecretReveal = exports.transferSecretRequest = exports.transferSecretRegister = exports.transferSecret = exports.transferProcessed = exports.transferSigned = exports.transfer = void 0; /* eslint-disable @typescript-eslint/no-namespace */ const t = __importStar(require("io-ts")); const types_1 = require("../channels/types"); const types_2 = require("../messages/types"); const types_3 = require("../services/types"); const types_4 = require("../transport/types"); const actions_1 = require("../utils/actions"); const types_5 = require("../utils/types"); const state_1 = require("./state"); const TransferId = t.type({ secrethash: types_5.Hash, direction: state_1.DirectionC, }); /** * A transfer async action set * * A transfer is considered as having succeeded from the time the secret is revealed to the target, * as from there, target and mediators can claim the payment down to us. But the full off-chain * happy case completes only after partner/neighbor acknowledges receiving the Unlock. * So, we usually only emits this action in the end of the happy case, and it'll then contain the * unlock's balanceProof, which indicates the full off-chain path succeeded. * It'll be emitted without a balanceProof if something forces the transfer to complete * (e.g. channel closed), the secret was revealed (so target was paid) but for any reason the * unlock didn't happen yet. * * transfer.failure is emitted as soon as we know the transfer failed definitely, like when a * RefundTransfer is received or the lock expires before revealing the secret. It notifies the user * (e.g. pending Promises) that the transfer failed and won't be paid (eventually, locked amount * will be recovered by expiring the lock). */ exports.transfer = (0, actions_1.createAsyncAction)(TransferId, 'transfer', t.intersection([ t.type({ tokenNetwork: types_5.Address, target: types_5.Address, value: (0, types_5.UInt)(32), paymentId: (0, types_5.UInt)(8), }), t.union([ t.intersection([ t.type({ resolved: t.literal(false) }), t.partial({ paths: types_3.InputPaths, pfs: t.union([types_3.PFS, t.null]), encryptSecret: t.boolean }), ]), t.intersection([ t.type({ resolved: t.literal(true), metadata: t.unknown, fee: types_3.Fee, partner: types_5.Address, }), types_4.Via, ]), ]), t.partial({ secret: types_5.Secret, initiator: types_5.Address }), t.union([t.partial({ expiration: t.number }), t.partial({ lockTimeout: t.number })]), ]), t.partial({ balanceProof: (0, types_5.Signed)(types_1.BalanceProof) })); /** A LockedTransfer was signed and should be sent to partner */ exports.transferSigned = (0, actions_1.createAction)('transfer/signed', t.intersection([t.type({ message: (0, types_5.Signed)(types_2.LockedTransfer), fee: types_3.Fee, partner: types_5.Address }), types_4.Via]), TransferId); /** Partner acknowledge they received and processed our LockedTransfer */ exports.transferProcessed = (0, actions_1.createAction)('transfer/processed', t.intersection([t.type({ message: (0, types_5.Signed)(types_2.Processed) }), types_4.Via]), TransferId); /** Register a secret */ exports.transferSecret = (0, actions_1.createAction)('transfer/secret', t.type({ secret: types_5.Secret }), TransferId); exports.transferSecretRegister = (0, actions_1.createAsyncAction)(TransferId, 'transfer/secret/register', t.type({ secret: types_5.Secret }), t.type({ secret: types_5.Secret, txTimestamp: t.number, txHash: types_5.Hash, txBlock: t.number, // ConfirmableAction confirmed: t.union([t.undefined, t.boolean]), })); /** A valid SecretRequest received from target */ exports.transferSecretRequest = (0, actions_1.createAction)('transfer/secret/request', t.intersection([t.type({ message: (0, types_5.Signed)(types_2.SecretRequest) }), types_4.Via]), TransferId); /** A SecretReveal sent to target */ exports.transferSecretReveal = (0, actions_1.createAction)('transfer/secret/reveal', t.intersection([t.type({ message: (0, types_5.Signed)(types_2.SecretReveal) }), types_4.Via]), TransferId); exports.transferUnlock = (0, actions_1.createAsyncAction)(TransferId, 'transfer/unlock', t.union([t.undefined, types_4.Via]), t.intersection([t.type({ message: (0, types_5.Signed)(types_2.Unlock), partner: types_5.Address }), types_4.Via])); /** Partner acknowledge they received and processed our Unlock */ exports.transferUnlockProcessed = (0, actions_1.createAction)('transfer/unlock/processed', t.intersection([t.type({ message: (0, types_5.Signed)(types_2.Processed) }), types_4.Via]), TransferId); /** * A request to expire a given transfer * * A transfer expiration request may fail for any reason * e.g. user rejected sign prompt. It should eventually get prompted again, on a future newBlock * action which sees this transfer should be expired but sent.expired didn't get set yet. */ exports.transferExpire = (0, actions_1.createAsyncAction)(TransferId, 'transfer/expire', undefined, t.type({ message: (0, types_5.Signed)(types_2.LockExpired), partner: types_5.Address })); /** Partner acknowledge they received and processed our LockExpired */ exports.transferExpireProcessed = (0, actions_1.createAction)('transfer/expire/processed', t.intersection([t.type({ message: (0, types_5.Signed)(types_2.Processed) }), types_4.Via]), TransferId); exports.transferClear = (0, actions_1.createAction)('transfer/clear', t.undefined, TransferId); exports.transferLoad = (0, actions_1.createAction)('transfer/load', state_1.TransferState, TransferId); // Withdraw actions const WithdrawId = t.type({ direction: state_1.DirectionC, tokenNetwork: types_5.Address, partner: types_5.Address, totalWithdraw: (0, types_5.UInt)(32), expiration: t.number, }); /** * Request withdrawResolveEpic to resolve and emit a withdraw.request */ exports.withdrawResolve = (0, actions_1.createAction)('withdraw/resolve', t.union([t.undefined, t.type({ coopSettle: t.literal(true) })]), WithdrawId); /** * Start a withdraw * - request: request to start a withdraw * - success: withdraw finished on-chain * - failure: something went wrong generating or processing a request */ exports.withdraw = (0, actions_1.createAsyncAction)(WithdrawId, 'withdraw', t.union([t.undefined, t.type({ coopSettle: t.boolean })]), t.type({ txHash: types_5.Hash, txBlock: t.number, confirmed: t.union([t.undefined, t.boolean]) })); /** * Withdraw messages going through: * - request: WithdrawRequest sent or received * - success: WithdrawConfirmation sent or received * - failure: something went wrong processing WithdrawRequest or WithdrawConfirmation messages */ exports.withdrawMessage = (0, actions_1.createAsyncAction)(WithdrawId, 'withdraw/message', t.type({ message: (0, types_5.Signed)(types_2.WithdrawRequest) }), t.type({ message: (0, types_5.Signed)(types_2.WithdrawConfirmation) })); /** * Signals this withdraw is "busy" performing contract's transaction (either setTotalWithdraw * or cooperativeSettle). Is "unlocked" by the respective withdraw.success|failure */ exports.withdrawBusy = (0, actions_1.createAction)('withdraw/busy', t.undefined, WithdrawId); /** * Expires a withdraw * - request: request to expire a past request * - success: WithdrawExpired sent or received * - failure: something went wrong generating or processing a request */ exports.withdrawExpire = (0, actions_1.createAsyncAction)(WithdrawId, 'withdraw/expire', t.undefined, t.type({ message: (0, types_5.Signed)(types_2.WithdrawExpired) })); exports.withdrawCompleted = (0, actions_1.createAction)('withdraw/completed', t.undefined, WithdrawId); //# sourceMappingURL=actions.js.map