machinomy
Version:
Micropayments powered by Ethereum
62 lines • 2.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const BigNumber = require("bignumber.js");
const Exceptions_1 = require("./Exceptions");
const Signature_1 = require("./Signature");
class RemoteChannelInfo {
constructor(channelId, spent, sign) {
this.channelId = channelId;
this.spent = spent;
this.sign = sign;
}
}
exports.RemoteChannelInfo = RemoteChannelInfo;
class RemoteChannelInfoSerde {
serialize(obj) {
return {
channelId: obj.channelId,
spent: obj.spent.toString(),
sign: obj.sign.toString()
};
}
deserialize(data) {
if (!data.channelId) {
throw new Exceptions_1.IvalidTypeError(RemoteChannelInfo.name, 'channelId');
}
if (!data.spent) {
throw new Exceptions_1.IvalidTypeError(RemoteChannelInfo.name, 'spent');
}
if (!data.sign) {
throw new Exceptions_1.IvalidTypeError(RemoteChannelInfo.name, 'sign');
}
return {
channelId: data.channelId,
spent: new BigNumber.BigNumber(data.spent),
sign: Signature_1.default.fromRpcSig(data.sign)
};
}
}
RemoteChannelInfoSerde.instance = new RemoteChannelInfoSerde();
exports.RemoteChannelInfoSerde = RemoteChannelInfoSerde;
class RemoteChannelInfos {
constructor(channels) {
this.channels = channels;
}
}
exports.RemoteChannelInfos = RemoteChannelInfos;
class RemoteChannelInfosSerde {
serialize(obj) {
return obj.channels.map(channel => RemoteChannelInfoSerde.instance.serialize(channel));
}
deserialize(data) {
if (!data.map) {
throw new Exceptions_1.IvalidTypeError(RemoteChannelInfosSerde.name, 'map');
}
return {
channels: data.map((channel) => RemoteChannelInfoSerde.instance.deserialize(channel))
};
}
}
RemoteChannelInfosSerde.instance = new RemoteChannelInfosSerde();
exports.RemoteChannelInfosSerde = RemoteChannelInfosSerde;
//# sourceMappingURL=RemoteChannelInfo.js.map