raiden-ts
Version:
Raiden Light Client Typescript/Javascript SDK
123 lines • 6.09 kB
JavaScript
;
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfirmableAction = exports.RaidenEvents = exports.raidenSynced = exports.raidenStarted = exports.raidenConfigCaps = exports.raidenConfigUpdate = exports.raidenShutdown = void 0;
/**
* Aggregate types and exported properties from actions from all modules
*/
const Either_1 = require("fp-ts/lib/Either");
const function_1 = require("fp-ts/lib/function");
const t = __importStar(require("io-ts"));
const mapKeys_1 = __importDefault(require("lodash/mapKeys"));
const property_1 = __importDefault(require("lodash/property"));
const reduce_1 = __importDefault(require("lodash/reduce"));
const ChannelsActions = __importStar(require("./channels/actions"));
const config_1 = require("./config");
const constants_1 = require("./constants");
const MessagesActions = __importStar(require("./messages/actions"));
const ServicesActions = __importStar(require("./services/actions"));
const TransfersActions = __importStar(require("./transfers/actions"));
const TransportActions = __importStar(require("./transport/actions"));
const types_1 = require("./transport/types");
const actions_1 = require("./utils/actions");
const error_1 = require("./utils/error");
const types_2 = require("./utils/types");
exports.raidenShutdown = (0, actions_1.createAction)('raiden/shutdown', t.type({
reason: t.union([
t.literal(constants_1.ShutdownReason.STOP),
t.literal(constants_1.ShutdownReason.ACCOUNT_CHANGED),
t.literal(constants_1.ShutdownReason.NETWORK_CHANGED),
error_1.ErrorCodec,
]),
}));
exports.raidenConfigUpdate = (0, actions_1.createAction)('raiden/config/update', config_1.PartialRaidenConfig);
exports.raidenConfigCaps = (0, actions_1.createAction)('raiden/config/caps', t.type({ caps: t.union([types_1.Caps, t.null]) }));
exports.raidenStarted = (0, actions_1.createAction)('raiden/started');
exports.raidenSynced = (0, actions_1.createAction)('raiden/synced', t.type({ tookMs: t.number, initialBlock: t.number, currentBlock: t.number }));
const RaidenActions = {
raidenShutdown: exports.raidenShutdown,
raidenConfigUpdate: exports.raidenConfigUpdate,
raidenConfigCaps: exports.raidenConfigCaps,
raidenStarted: exports.raidenStarted,
raidenSynced: exports.raidenSynced,
...ChannelsActions,
...TransportActions,
...MessagesActions,
...TransfersActions,
...ServicesActions,
};
/* Mapping { [type: string]: Action } of a subset of RaidenActions exposed as events */
exports.RaidenEvents = [
RaidenActions.raidenShutdown,
RaidenActions.newBlock,
RaidenActions.matrixPresence.success,
RaidenActions.tokenMonitored,
RaidenActions.udcWithdrawPlan.success,
RaidenActions.udcWithdrawPlan.failure,
RaidenActions.udcWithdraw.success,
RaidenActions.udcWithdraw.failure,
RaidenActions.msBalanceProofSent,
RaidenActions.channelSettle.success,
RaidenActions.channelSettle.failure,
RaidenActions.channelOpen.success,
RaidenActions.channelOpen.failure,
];
const RaidenActionsMap = (0, reduce_1.default)(RaidenActions, (acc, v) => ({ ...acc, ...('type' in v ? { [v.type]: v } : (0, mapKeys_1.default)(v, (0, property_1.default)('type'))) }), {});
/**
* Pure codec which decodes/validates actions which can be confirmed on-chain
*
* Note that this isn't a complete ActionCreator, but it helps identify and narrow actions which
* matches this schema. Also important is that this codec isn't `t.exact`, and therefore it will
* validate objects with additional properties (like meta and payload properties), as long as it
* matches the required schema below.
* Use [[ConfirmableAction]] to ensure it both complies with and decodes/validates also to the
* actual corresponding action registered in [[RaidenActionsMap]]
*/
const _ConfirmableAction = t.readonly(t.type({
type: t.string,
payload: t.type({
txHash: types_2.Hash,
txBlock: t.number,
confirmed: t.union([t.undefined, t.boolean]),
}),
}));
/**
* Special custom codec with validates a type equivalent to:
* ConfirmableAction & ValueOf<RaidenActionsMap>
* i.e. a ConfirmableAction intersected with an union of any possible registered RaidenAction.
* This is needed in order to properly handle members of actions which require special encoding/
* decoding logic, like BigNumbers, otherwise when decoding actions (e.g. from
* RaidenState['pendingTxs']), the members would be kept but not decoded properly.
*/
exports.ConfirmableAction = new t.Type('ConfirmableAction', _ConfirmableAction.is, (u, c) => (0, function_1.pipe)(_ConfirmableAction.validate(u, c), (0, Either_1.chain)((v) => {
const type = v.type;
if (!(type in RaidenActionsMap))
return t.failure(v, c);
return RaidenActionsMap[type].codec.validate(v, c);
})), (a) => RaidenActionsMap[a.type].codec.encode(a));
//# sourceMappingURL=actions.js.map