UNPKG

raiden-ts

Version:

Raiden Light Client Typescript/Javascript SDK

93 lines 4.04 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.Channel = exports.ChannelEnd = exports.ChannelState = void 0; const t = __importStar(require("io-ts")); const messages_1 = require("../messages"); const types_1 = require("../utils/types"); const types_2 = require("./types"); var ChannelState; (function (ChannelState) { ChannelState["open"] = "open"; ChannelState["closing"] = "closing"; ChannelState["closed"] = "closed"; ChannelState["settleable"] = "settleable"; ChannelState["settling"] = "settling"; ChannelState["settled"] = "settled"; })(ChannelState = exports.ChannelState || (exports.ChannelState = {})); /** * Contains info of each side of a channel */ const _ChannelEnd = t.readonly(t.type({ address: types_1.Address, deposit: (0, types_1.UInt)(32), withdraw: (0, types_1.UInt)(32), locks: t.readonlyArray(types_2.Lock), balanceProof: (0, types_1.Signed)(types_2.BalanceProof), pendingWithdraws: t.readonlyArray(t.union([(0, types_1.Signed)(messages_1.WithdrawRequest), (0, types_1.Signed)(messages_1.WithdrawConfirmation), (0, types_1.Signed)(messages_1.WithdrawExpired)])), nextNonce: (0, types_1.UInt)(8), // usually balanceProof.nonce+1, but withdraw messages also increment it }), 'ChannelEnd'); exports.ChannelEnd = _ChannelEnd; exports.Channel = t.intersection([ // readonly needs to be applied to the individual types to allow tagged union narrowing t.readonly(t.type({ _id: types_2.ChannelUniqueKey, id: t.number, token: types_1.Address, tokenNetwork: types_1.Address, isFirstParticipant: t.boolean, openBlock: t.number, own: exports.ChannelEnd, partner: exports.ChannelEnd, }), 'Channel'), t.union([ /* union of types with literals intersection allows narrowing other props presence. e.g.: * if (channel.state === ChannelState.open) { * id = channel.id; // <- id can't be undefined * closeBlock = channel.closeBlock; // error: closeBlock only exist on states closed|settling * } */ t.readonly(t.type({ state: t.union([t.literal(ChannelState.open), t.literal(ChannelState.closing)]), }), 'state[open|closing]'), t.intersection([ t.readonly(t.type({ closeBlock: t.number, closeParticipant: types_1.Address, }), 'ChannelClosed'), t.union([ t.readonly(t.type({ state: t.union([ t.literal(ChannelState.closed), t.literal(ChannelState.settleable), t.literal(ChannelState.settling), ]), }), 'state[closed|settleable|settling]'), t.readonly(t.type({ state: t.literal(ChannelState.settled), settleBlock: t.number }), 'state[settled]'), ]), ]), ]), ]); //# sourceMappingURL=state.js.map