raiden-ts
Version:
Raiden Light Client Typescript/Javascript SDK
125 lines • 5.96 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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RevealedSecret = exports.RaidenTransferStatus = exports.TransferState = exports.DirectionC = exports.Direction = void 0;
const t = __importStar(require("io-ts"));
const invert_1 = __importDefault(require("lodash/invert"));
const types_1 = require("../messages/types");
const types_2 = require("../services/types");
const types_3 = require("../utils/types");
// it's like an enum, but with literals
exports.Direction = {
SENT: 'sent',
RECEIVED: 'received',
};
exports.DirectionC = t.keyof((0, invert_1.default)(exports.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: exports.DirectionC,
secrethash: types_3.Hash,
expiration: t.number,
/** -> outgoing locked transfer */
transfer: (0, types_3.Timed)((0, types_3.Signed)(types_1.LockedTransfer)),
fee: types_2.Fee,
partner: types_3.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: types_3.Secret,
/** Set iff secret got registered on-chain on a block before transfer expiration */
secretRegistered: (0, types_3.Timed)(t.type({ txHash: types_3.Hash, txBlock: t.number })),
/** <- incoming processed for locked transfer */
transferProcessed: (0, types_3.Timed)((0, types_3.Signed)(types_1.Processed)),
/** !! channel was closed !! */
channelClosed: (0, types_3.Timed)(t.type({ txHash: types_3.Hash, txBlock: t.number })),
/** channel was settled */
channelSettled: (0, types_3.Timed)(t.type({ txHash: types_3.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: (0, types_3.Timed)((0, types_3.Signed)(types_1.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: (0, types_3.Timed)((0, types_3.Signed)(types_1.SecretReveal)),
/**
* -> outgoing unlock to recipient
* If this is set, it means the Unlock was sent (even if partner didn't acknowledge it yet)
*/
unlock: (0, types_3.Timed)((0, types_3.Signed)(types_1.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: (0, types_3.Timed)((0, types_3.Signed)(types_1.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: (0, types_3.Timed)((0, types_3.Signed)(types_1.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: (0, types_3.Timed)((0, types_3.Signed)(types_1.Processed)),
}, 'TransferStateOpts'),
]));
exports.TransferState = _TransferState;
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 = exports.RaidenTransferStatus || (exports.RaidenTransferStatus = {}));
exports.RevealedSecret = t.intersection([
t.type({ secret: types_3.Secret, amount: (0, types_3.UInt)(32) }),
t.partial({ payment_identifier: (0, types_3.UInt)(8) }),
]);
//# sourceMappingURL=state.js.map