raiden-ts
Version:
Raiden Light Client Typescript/Javascript SDK
111 lines • 5.31 kB
JavaScript
"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.channelSettle = exports.channelSettleable = exports.channelClose = exports.channelWithdrawn = exports.channelDeposit = exports.channelMonitored = exports.channelOpen = exports.tokenMonitored = exports.contractSettleTimeout = exports.blockStale = exports.blockTime = exports.newBlock = void 0;
/* eslint-disable @typescript-eslint/no-namespace */
const t = __importStar(require("io-ts"));
const messages_1 = require("../messages");
const actions_1 = require("../utils/actions");
const types_1 = require("../utils/types");
const types_2 = require("./types");
// interfaces need to be exported, and we need/want to support `import * as RaidenActions`
const ChannelId = t.type({
tokenNetwork: types_1.Address,
partner: types_1.Address,
});
/* A new head in the blockchain is detected by provider */
exports.newBlock = (0, actions_1.createAction)('block/new', t.type({ blockNumber: t.number }));
/* A new blockTime (average time between latest X blocks) was detected */
exports.blockTime = (0, actions_1.createAction)('block/time', t.type({ blockTime: t.number }));
exports.blockStale = (0, actions_1.createAction)('block/stale', t.type({ stale: t.boolean }));
exports.contractSettleTimeout = (0, actions_1.createAction)('contract/settleTimeout', t.number);
/**
* A new token network is detected in the TokenNetworkRegistry instance
* fromBlock is only set on the first time, to fetch and handle past events
*/
exports.tokenMonitored = (0, actions_1.createAction)('token/monitored', t.intersection([
t.type({
token: types_1.Address,
tokenNetwork: types_1.Address,
}),
t.partial({
fromBlock: t.number,
toBlock: t.number,
}),
]));
/**
* Channel actions receive ChannelId as 'meta' action property
* This way, 'meta' can be used equally for request, success and error actions
*/
exports.channelOpen = (0, actions_1.createAsyncAction)(ChannelId, 'channel/open', t.partial({ deposit: (0, types_1.UInt)(32) }), t.type({
id: t.number,
token: types_1.Address,
isFirstParticipant: t.boolean,
txHash: types_1.Hash,
txBlock: t.number,
confirmed: t.union([t.undefined, t.boolean]),
}));
/* Channel with meta:ChannelId + payload.id should be monitored */
exports.channelMonitored = (0, actions_1.createAction)('channel/monitored', t.type({ id: t.number }), ChannelId);
exports.channelDeposit = (0, actions_1.createAsyncAction)(ChannelId, 'channel/deposit', t.intersection([
t.union([t.type({ deposit: (0, types_1.UInt)(32) }), t.type({ totalDeposit: (0, types_1.UInt)(32) })]),
t.partial({ waitOpen: t.literal(true) }),
]), t.type({
id: t.number,
participant: types_1.Address,
totalDeposit: (0, types_1.UInt)(32),
txHash: types_1.Hash,
txBlock: t.number,
confirmed: t.union([t.undefined, t.boolean]),
}));
/* A withdraw is detected on-chain */
exports.channelWithdrawn = (0, actions_1.createAction)('channel/withdraw/success', t.type({
id: t.number,
participant: types_1.Address,
totalWithdraw: (0, types_1.UInt)(32),
txHash: types_1.Hash,
txBlock: t.number,
confirmed: t.union([t.undefined, t.boolean]),
}), ChannelId);
exports.channelClose = (0, actions_1.createAsyncAction)(ChannelId, 'channel/close', t.undefined, t.type({
id: t.number,
participant: types_1.Address,
txHash: types_1.Hash,
txBlock: t.number,
confirmed: t.union([t.undefined, t.boolean]),
}));
/* A channel meta:ChannelId becomes settleable, starting from payload.settleableBlock */
exports.channelSettleable = (0, actions_1.createAction)('channel/settleable', t.type({ settleableBlock: t.number }), ChannelId);
const WithdrawPair = t.tuple([(0, types_1.Signed)(messages_1.WithdrawRequest), (0, types_1.Signed)(messages_1.WithdrawConfirmation)]);
exports.channelSettle = (0, actions_1.createAsyncAction)(ChannelId, 'channel/settle', t.union([t.type({ coopSettle: t.tuple([WithdrawPair, WithdrawPair]) }), t.undefined]), t.intersection([
t.type({
id: t.number,
txHash: types_1.Hash,
txBlock: t.number,
confirmed: t.union([t.undefined, t.boolean]),
}),
t.partial({ locks: t.readonlyArray(types_2.Lock) }),
]));
//# sourceMappingURL=actions.js.map