UNPKG

machinomy

Version:

Micropayments powered by Ethereum

45 lines 2.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const BigNumber = require("bignumber.js"); const Exceptions_1 = require("./Exceptions"); const RemoteChannelInfo_1 = require("./RemoteChannelInfo"); exports.TRANSPORT_VERSION = '0.0.4'; class PaymentRequiredResponse { constructor(price, receiver, gateway, tokenContract, meta, remoteChannelInfo) { this.price = price; this.receiver = receiver; this.gateway = gateway; this.tokenContract = tokenContract; this.meta = meta; this.remoteChannelInfo = remoteChannelInfo; } } exports.PaymentRequiredResponse = PaymentRequiredResponse; class PaymentRequiredResponseSerializer { serialize(obj, headers) { headers['paywall-address'] = obj.receiver; headers['paywall-price'] = obj.price.toString(); headers['paywall-gateway'] = obj.gateway; headers['paywall-token-contract'] = obj.tokenContract; headers['paywall-meta'] = obj.meta; headers['paywall-version'] = exports.TRANSPORT_VERSION; headers['paywall-channels'] = JSON.stringify(RemoteChannelInfo_1.RemoteChannelInfosSerde.instance.serialize(obj.remoteChannelInfo)); return headers; } deserialize(headers) { if (!headers['paywall-version'] || headers['paywall-version'] !== exports.TRANSPORT_VERSION) { throw new Exceptions_1.TransportVersionNotSupportError(); } return { price: new BigNumber.BigNumber(headers['paywall-price']), receiver: headers['paywall-address'], gateway: headers['paywall-gateway'], tokenContract: headers['paywall-token-contract'], meta: headers['paywall-meta'], remoteChannelInfo: RemoteChannelInfo_1.RemoteChannelInfosSerde.instance.deserialize(JSON.parse(headers['paywall-channels'])) }; } } PaymentRequiredResponseSerializer.instance = new PaymentRequiredResponseSerializer(); exports.PaymentRequiredResponseSerializer = PaymentRequiredResponseSerializer; //# sourceMappingURL=PaymentRequiredResponse.js.map