UNPKG

raiden-ts

Version:

Raiden Light Client Typescript/Javascript SDK

100 lines 4.44 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.initialState = exports.makeInitialState = exports.RaidenState = void 0; const constants_1 = require("@ethersproject/constants"); const networks_1 = require("@ethersproject/networks"); const t = __importStar(require("io-ts")); const actions_1 = require("./actions"); const state_1 = require("./channels/state"); const config_1 = require("./config"); const types_1 = require("./services/types"); const state_2 = require("./transfers/state"); const state_3 = require("./transport/state"); const types_2 = require("./types"); const types_3 = require("./utils/types"); // types const _RaidenState = t.readonly(t.type({ address: types_3.Address, chainId: t.number, contracts: types_2.ContractsInfo, blockNumber: t.number, config: config_1.PartialRaidenConfig, channels: t.readonly(t.record(t.string /* ChannelKey */, state_1.Channel)), oldChannels: t.readonly(t.record(t.string /* ChannelUniqueKey */, state_1.Channel)), tokens: t.readonly(t.record(t.string /* token: Address */, types_3.Address)), transport: t.readonly(t.partial({ server: t.string, setup: state_3.RaidenMatrixSetup })), transfers: t.readonly(t.record(t.string /*: key: TransferKey */, state_2.TransferState)), iou: t.readonly(t.record(t.string /* tokenNetwork: Address */, t.record(t.string /* service: Address */, (0, types_3.Signed)(types_1.IOU)))), pendingTxs: t.readonlyArray(actions_1.ConfirmableAction), services: types_1.ServicesValidityMap, }), 'RaidenState'); exports.RaidenState = _RaidenState; /** * Create an initial RaidenState from common parameters (including default config) * * @param obj - Object containing common parameters for state * @param obj.network - ether's Network object for the current blockchain * @param obj.address - current account's address * @param obj.contractsInfo - ContractsInfo mapping * @param overrides - A partial object to overwrite top-level properties of the returned config * @returns A full config object */ function makeInitialState({ network, address, contractsInfo, }, overrides = {}) { return { address, chainId: network.chainId, contracts: contractsInfo, blockNumber: contractsInfo.TokenNetworkRegistry.block_number, channels: {}, oldChannels: {}, tokens: {}, transport: {}, transfers: {}, iou: {}, pendingTxs: [], services: {}, config: {}, ...overrides, }; } exports.makeInitialState = makeInitialState; /** * state constant used as default state reducer parameter only. * To build an actual initial state at runtime, use [[makeInitialState]] instead. */ exports.initialState = makeInitialState({ network: (0, networks_1.getNetwork)('unspecified'), address: constants_1.AddressZero, contractsInfo: { TokenNetworkRegistry: { address: constants_1.AddressZero, block_number: 0 }, ServiceRegistry: { address: constants_1.AddressZero, block_number: 0 }, UserDeposit: { address: constants_1.AddressZero, block_number: 0 }, SecretRegistry: { address: constants_1.AddressZero, block_number: 0 }, MonitoringService: { address: constants_1.AddressZero, block_number: 0 }, OneToN: { address: constants_1.AddressZero, block_number: 0 }, }, }); //# sourceMappingURL=state.js.map