UNPKG

@kippurocks/libticketto-papi

Version:

A Kippu implementation of The Ticketto Protocol with Polkadot-API

82 lines (81 loc) 4.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KippuPAPIConsumer = exports.isKreivoTx = void 0; const subscriptions_ts_1 = require("./subscriptions.js"); const types_ts_1 = require("./types.js"); const directory_ts_1 = require("./directory.js"); const events_ts_1 = require("./events.js"); const tickets_ts_1 = require("./tickets.js"); const descriptors_1 = require("@polkadot-api/descriptors"); const inversify_1 = require("inversify"); const tickettoModel_ts_1 = require("./tickettoModel.js"); const submitter_ts_1 = require("./submitter.js"); const sdk_ink_1 = require("@polkadot-api/sdk-ink"); var types_ts_2 = require("./types.js"); Object.defineProperty(exports, "isKreivoTx", { enumerable: true, get: function () { return types_ts_2.isKreivoTx; } }); class KippuPAPIConsumer { container = new inversify_1.Container(); constructor() { this.container.bind(types_ts_1.TOKEN.QUEUE).toConstantValue(new subscriptions_ts_1.EventQueue()); this.container.bind(types_ts_1.TOKEN.SUBMITTER).to(submitter_ts_1.TransactionSubmitter); this.container.bind(directory_ts_1.KippuDirectoryCalls).toSelf(); this.container.bind(directory_ts_1.KippuDirectoryStorage).toSelf(); this.container.bind(events_ts_1.KippuEventsCalls).toSelf(); this.container.bind(events_ts_1.KippuEventsStorage).toSelf(); this.container.bind(tickets_ts_1.KippuTicketsCalls).toSelf(); this.container.bind(tickets_ts_1.KippuTicketsStorage).toSelf(); this.container.bind(subscriptions_ts_1.WebStubEventSubscribtion).toSelf(); } async build(config) { if (config === undefined) { throw new TypeError("A valid `KippuConfig` is required to initialize the `KippuPAPIConsumer`"); } this.container .bind(types_ts_1.TOKEN.ACCUNT_PROVIDER) .toConstantValue(config.accountProvider); this.container .bind(types_ts_1.TOKEN.SETTINGS) .toConstantValue(config.consumerSettings); const consumerSettings = config.consumerSettings; this.container .bind(types_ts_1.TOKEN.MERCHANT_ID) .toConstantValue(consumerSettings.merchantId ?? 3); this.container .bind(types_ts_1.TOKEN.POLKADOT_CLIENT) .toConstantValue(consumerSettings.client); // Initialize Kreivo API const kreivoApi = consumerSettings.client.getTypedApi(descriptors_1.kreivo); this.container.bind(types_ts_1.TOKEN.KREIVO_API).toConstantValue(kreivoApi); this.container.bind(tickettoModel_ts_1.TickettoModelConverter).toSelf(); // Initialize Events contract const eventsSdk = (0, sdk_ink_1.createInkSdk)(kreivoApi, descriptors_1.contracts.tickettoEvents); this.container .bind(types_ts_1.TOKEN.EVENTS_CONTRACT) .toConstantValue(eventsSdk.getContract(consumerSettings.eventsContractAddress)); this.container .bind(types_ts_1.TOKEN.EVENTS_CONTRACT_ADDRESS) .toConstantValue(consumerSettings.eventsContractAddress); // Initialize Tickets contract const ticketsSdk = (0, sdk_ink_1.createInkSdk)(kreivoApi, descriptors_1.contracts.tickettoTickets); this.container .bind(types_ts_1.TOKEN.TICKETS_CONTRACT) .toConstantValue(ticketsSdk.getContract(consumerSettings.ticketsContractAddress)); return { accountProvider: this.container.get(types_ts_1.TOKEN.ACCUNT_PROVIDER), directory: { calls: this.container.get(directory_ts_1.KippuDirectoryCalls), query: this.container.get(directory_ts_1.KippuDirectoryStorage), }, events: { calls: this.container.get(events_ts_1.KippuEventsCalls), query: this.container.get(events_ts_1.KippuEventsStorage), }, tickets: { calls: this.container.get(tickets_ts_1.KippuTicketsCalls), query: this.container.get(tickets_ts_1.KippuTicketsStorage), }, systemEvents: this.container.get(subscriptions_ts_1.WebStubEventSubscribtion), }; } } exports.KippuPAPIConsumer = KippuPAPIConsumer;