machinomy
Version:
Micropayments powered by Ethereum
99 lines • 4.29 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const decko_1 = require("decko");
const ChannelEthContract_1 = require("./ChannelEthContract");
const ChannelTokenContract_1 = require("./ChannelTokenContract");
const ChannelInflator_1 = require("./ChannelInflator");
const Storage_1 = require("./Storage");
const ChannelContract_1 = require("./ChannelContract");
const ChannelManager_1 = require("./ChannelManager");
const PaymentManager_1 = require("./PaymentManager");
const ChainManager_1 = require("./ChainManager");
const client_1 = require("./client");
const transport_1 = require("./transport");
class Registry {
constructor(account, web3, options) {
this.account = account;
this.web3 = web3;
this.options = options;
}
async inflator() {
const channelEthContract = await this.channelEthContract();
const channelTokenContract = await this.channelTokenContract();
return new ChannelInflator_1.default(channelEthContract, channelTokenContract);
}
async channelEthContract() {
return new ChannelEthContract_1.default(this.web3, this.options.chainCachePeriod || 0);
}
async channelTokenContract() {
return new ChannelTokenContract_1.default(this.web3, this.options.chainCachePeriod || 0);
}
async channelContract() {
const channelEthContract = await this.channelEthContract();
const channelTokenContract = await this.channelTokenContract();
const storage = await this.storage();
const channelsDatabase = storage.channelsDatabase;
return new ChannelContract_1.default(this.web3, channelsDatabase, channelEthContract, channelTokenContract);
}
async storage() {
const inflator = await this.inflator();
return Storage_1.default.build(this.options.databaseUrl, inflator);
}
async chainManager() {
return new ChainManager_1.default(this.web3);
}
async paymentManager() {
let chainManager = await this.chainManager();
let channelContract = await this.channelContract();
return new PaymentManager_1.default(chainManager, channelContract, this.options);
}
async client() {
let transport = this.options.transport ? this.options.transport : new transport_1.Transport();
let channelManager = await this.channelManager();
return new client_1.ClientImpl(transport, channelManager);
}
async channelManager() {
let storage = await this.storage();
let payments = storage.paymentsDatabase;
let channels = storage.channelsDatabase;
let tokens = storage.tokensDatabase;
let channelContract = await this.channelContract();
let paymentManager = await this.paymentManager();
return new ChannelManager_1.default(this.account, this.web3, channels, payments, tokens, channelContract, paymentManager, this.options);
}
}
__decorate([
decko_1.memoize
], Registry.prototype, "inflator", null);
__decorate([
decko_1.memoize
], Registry.prototype, "channelEthContract", null);
__decorate([
decko_1.memoize
], Registry.prototype, "channelTokenContract", null);
__decorate([
decko_1.memoize
], Registry.prototype, "channelContract", null);
__decorate([
decko_1.memoize
], Registry.prototype, "storage", null);
__decorate([
decko_1.memoize
], Registry.prototype, "chainManager", null);
__decorate([
decko_1.memoize
], Registry.prototype, "paymentManager", null);
__decorate([
decko_1.memoize
], Registry.prototype, "client", null);
__decorate([
decko_1.memoize
], Registry.prototype, "channelManager", null);
exports.default = Registry;
//# sourceMappingURL=Registry.js.map