UNPKG

raiden-ts

Version:

Raiden Light Client Typescript/Javascript SDK

96 lines 4.21 kB
import * as t from 'io-ts'; import invert from 'lodash/invert'; import { LockedTransfer, LockExpired, Processed, SecretRequest, SecretReveal, Unlock, } from '../messages/types'; import { Fee } from '../services/types'; import { Address, Hash, Secret, Signed, Timed, UInt } from '../utils/types'; // it's like an enum, but with literals export const Direction = { SENT: 'sent', RECEIVED: 'received', }; export const DirectionC = t.keyof(invert(Direction)); /** * This struct holds the relevant messages exchanged in a transfer * The transfer state is defined by the exchanged messages */ const _TransferState = t.readonly(t.intersection([ t.type({ _id: t.string, channel: t.string, direction: DirectionC, secrethash: Hash, expiration: t.number, /** -> outgoing locked transfer */ transfer: Timed(Signed(LockedTransfer)), fee: Fee, partner: Address, /* timestamp of when transfer completed and may be cleared from state (non-cleared=0) */ cleared: t.number, }, 'TransferStateBase'), t.partial({ /** Transfer secret, if known */ secret: Secret, /** Set iff secret got registered on-chain on a block before transfer expiration */ secretRegistered: Timed(t.type({ txHash: Hash, txBlock: t.number })), /** <- incoming processed for locked transfer */ transferProcessed: Timed(Signed(Processed)), /** !! channel was closed !! */ channelClosed: Timed(t.type({ txHash: Hash, txBlock: t.number })), /** channel was settled */ channelSettled: Timed(t.type({ txHash: Hash, txBlock: t.number })), /** * <- incoming secret request from target * If this is set, it means the target requested the secret, not necessarily with a valid * amount (an invalid amount < value == lock - fee, means transfer failed) */ secretRequest: Timed(Signed(SecretRequest)), /** * -> outgoing secret reveal to target * If this is set, it means the secret was revealed (so transfer succeeded, even if it didn't * complete yet) */ secretReveal: Timed(Signed(SecretReveal)), /** * -> outgoing unlock to recipient * If this is set, it means the Unlock was sent (even if partner didn't acknowledge it yet) */ unlock: Timed(Signed(Unlock)), /** * -> outgoing lock expired (if so) * If this is set, transfer failed, and we expired the lock (retrieving the locked amount). * Transfer failed may not have completed yet, e.g. waiting for LockExpired's Processed reply */ expired: Timed(Signed(LockExpired)), /** * <- incoming processed for Unlock message * If this is set, the protocol completed by the transfer succeeding and partner * acknowledging validity of our off-chain unlock */ unlockProcessed: Timed(Signed(Processed)), /** * <- incoming processed for LockExpired message * If this is set, the protocol completed by the transfer failing and partner acknowledging * this transfer can't be claimed anymore */ expiredProcessed: Timed(Signed(Processed)), }, 'TransferStateOpts'), ])); export const TransferState = _TransferState; export var RaidenTransferStatus; (function (RaidenTransferStatus) { RaidenTransferStatus["pending"] = "PENDING"; RaidenTransferStatus["received"] = "RECEIVED"; RaidenTransferStatus["closed"] = "CLOSED"; RaidenTransferStatus["requested"] = "REQUESTED"; RaidenTransferStatus["revealed"] = "REVEALED"; RaidenTransferStatus["registered"] = "REGISTERED"; RaidenTransferStatus["unlocking"] = "UNLOCKING"; RaidenTransferStatus["expiring"] = "EXPIRING"; RaidenTransferStatus["unlocked"] = "UNLOCKED"; RaidenTransferStatus["expired"] = "EXPIRED"; })(RaidenTransferStatus || (RaidenTransferStatus = {})); export const RevealedSecret = t.intersection([ t.type({ secret: Secret, amount: UInt(32) }), t.partial({ payment_identifier: UInt(8) }), ]); //# sourceMappingURL=state.js.map