@liskhq/lisk-framework-faucet-plugin
Version:
A plugin for distributing testnet tokens from a newly developed blockchain application.
56 lines • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FaucetPlugin = void 0;
const lisk_sdk_1 = require("lisk-sdk");
const express = require("express");
const path_1 = require("path");
const schemas_1 = require("./schemas");
const endpoint_1 = require("./endpoint");
class FaucetPlugin extends lisk_sdk_1.BasePlugin {
constructor() {
super(...arguments);
this.configSchema = schemas_1.configSchema;
this.endpoint = new endpoint_1.Endpoint();
this._state = {
publicKey: undefined,
privateKey: undefined,
address: undefined,
};
}
get nodeModulePath() {
return __filename;
}
async init(context) {
await super.init(context);
this.endpoint.init(this._state, this.apiClient, this.config);
}
async load() {
const app = express();
app.get('/api/config', (_req, res) => {
const config = {
applicationUrl: this.config.applicationUrl,
amount: this.config.amount,
tokenPrefix: this.config.tokenPrefix,
captchaSitekey: this.config.captchaSitekey,
logoURL: this.config.logoURL,
faucetAddress: this._state.address,
};
res.json(config);
});
app.use(express.static((0, path_1.join)(__dirname, '../../build')));
this._server = app.listen(this.config.port, this.config.host);
}
async unload() {
return new Promise((resolve, reject) => {
this._server.close(err => {
if (err) {
reject(err);
return;
}
resolve();
});
});
}
}
exports.FaucetPlugin = FaucetPlugin;
//# sourceMappingURL=faucet_plugin.js.map