Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion combined.sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@
// Default: 0.01
//poolFee: 0.01,

// The following object is used by the endpoints to describe your pool.
// Default: description and both links are blank, payoutType is "Manual", payoutFrequency is blank, supportsNano is false
//poolInfo: {
// description : "",
// websiteLink : "",
// communityLink : "",
// payoutType : "Automatic",
// payoutFrequency : "every 3 hours",
// supportsNano : false
//},

// Network fee used by the pool for payouts (in satoshi per byte).
// Default: 1
//networkFee: 1,
Expand Down Expand Up @@ -119,4 +130,3 @@
//level: "verbose"
}
}

5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const Nimiq = require('@nimiq/core');
const argv = require('minimist')(process.argv.slice(2));
const config = require('./src/Config.js')(argv.config);

const PoolServer = require('./src/PoolServer.js');
//const PoolServer = require('./src/PoolServer.js');
const PoolServer = require('./src/PoolUIServer.js');
const PoolService = require('./src/PoolService.js');
const PoolPayout = require('./src/PoolPayout.js');
const MetricsServer = require('./src/MetricsServer.js');
Expand Down Expand Up @@ -113,7 +114,7 @@ for (const key in config.constantOverrides) {
}

if (config.poolServer.enabled) {
const poolServer = new PoolServer($.consensus, config.pool, config.poolServer.port, config.poolServer.mySqlPsw, config.poolServer.mySqlHost, config.poolServer.sslKeyPath, config.poolServer.sslCertPath, config.reverseProxy);
const poolServer = new PoolServer($.consensus, config.pool, config.poolServer.port, config.poolServer.mySqlPsw, config.poolServer.mySqlHost, config.poolServer.sslKeyPath, config.poolServer.sslCertPath, config.reverseProxy, config.host);

if (config.poolMetricsServer.enabled) {
$.metricsServer = new MetricsServer(config.poolServer.sslKeyPath, config.poolServer.sslCertPath, config.poolMetricsServer.port, config.poolMetricsServer.password);
Expand Down
11 changes: 11 additions & 0 deletions payout.sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
// Default: 0.01
//poolFee: 0.01,

// The following object is used by the endpoints to describe your pool.
// Default: description and both links are blank, payoutType is "Manual", payoutFrequency is blank, supportsNano is false
//poolInfo: {
// description : "",
// websiteLink : "",
// communityLink : "",
// payoutType : "Automatic",
// payoutFrequency : "every 3 hours",
// supportsNano : false
//},

// Network fee used by the pool for payouts (in satoshi per byte).
// Default: 1
//networkFee: 1,
Expand Down
8 changes: 8 additions & 0 deletions src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ const DEFAULT_CONFIG = /** @type {Config} */ {
payoutConfirmations: 10,
autoPayOutLimit: 5000000, // 50 NIM
poolFee: 0.01, // 1%
poolInfo: {
description : "",
websiteLink : "",
communityLink : "",
payoutType : "Manual",
payoutFrequency : "",
supportsNano : false
},
networkFee: 1, // satoshi per byte
startDifficulty: 1,
minDifficulty: 1,
Expand Down
5 changes: 5 additions & 0 deletions src/Helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class Helper {
return (1 - config.poolFee) * (Nimiq.Policy.blockRewardAt(block.height) + block.transactions.reduce((sum, tx) => sum + tx.fee, 0));
}

static async queryDB(connectionPool, query, ...args) {
let result = await connectionPool.execute(query, args);
return JSON.parse(JSON.stringify(result[0]));
}

/**
* @param {PoolConfig} config
* @param {mysql2.Pool} connectionPool
Expand Down
15 changes: 10 additions & 5 deletions src/PoolServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ class PoolServer extends Nimiq.Observable {
database: 'pool'
});

this._wss = PoolServer.createServer(this.port, this._sslKeyPath, this._sslCertPath);
let httpsServer = await this.startServer(this.port, this._sslKeyPath, this._sslCertPath);
// We have to access socket.remoteAddress here because otherwise req.connection.remoteAddress won't be set in the WebSocket's 'connection' event (yay)
httpsServer.on('secureConnection', socket => socket.remoteAddress);

this._wss = new WebSocket.Server({server: httpsServer});
this._wss.on('connection', (ws, req) => this._onConnection(ws, req));

this.consensus.blockchain.on('head-changed', (head) => {
Expand All @@ -145,6 +149,10 @@ class PoolServer extends Nimiq.Observable {
});
}

async startServer(...args) {
return await PoolServer.createServer(this.port, this._sslKeyPath, this._sslCertPath);
}

static createServer(port, sslKeyPath, sslCertPath) {
const sslOptions = {
key: fs.readFileSync(sslKeyPath),
Expand All @@ -155,11 +163,8 @@ class PoolServer extends Nimiq.Observable {
res.end('Nimiq Pool Server\n');
}).listen(port);

// We have to access socket.remoteAddress here because otherwise req.connection.remoteAddress won't be set in the WebSocket's 'connection' event (yay)
httpsServer.on('secureConnection', socket => socket.remoteAddress);

Nimiq.Log.i(PoolServer, "Started server on port " + port);
return new WebSocket.Server({server: httpsServer});
return httpsServer;
}

stop() {
Expand Down
Loading