mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
Use zeromq if configured
This commit is contained in:
@@ -4,6 +4,10 @@ BITCOIN_RPC_PASSWORD=
|
|||||||
BITCOIN_RPC_PORT=8332
|
BITCOIN_RPC_PORT=8332
|
||||||
BITCOIN_RPC_TIMEOUT=10000
|
BITCOIN_RPC_TIMEOUT=10000
|
||||||
|
|
||||||
|
# Enable in bitcoin.conf with
|
||||||
|
# zmqpubrawblock=tcp://*:3000
|
||||||
|
# BITCOIN_ZMQ_HOST="tcp://192.168.1.100:3000"
|
||||||
|
|
||||||
API_PORT=3334
|
API_PORT=3334
|
||||||
STRATUM_PORT=3333
|
STRATUM_PORT=3333
|
||||||
|
|
||||||
|
|||||||
Generated
+39
-1
@@ -34,7 +34,8 @@
|
|||||||
"rxjs": "^7.2.0",
|
"rxjs": "^7.2.0",
|
||||||
"sqlite3": "^5.1.6",
|
"sqlite3": "^5.1.6",
|
||||||
"tiny-secp256k1": "^2.2.3",
|
"tiny-secp256k1": "^2.2.3",
|
||||||
"typeorm": "^0.3.17"
|
"typeorm": "^0.3.17",
|
||||||
|
"zeromq": "^5.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nestjs/cli": "^9.0.0",
|
"@nestjs/cli": "^9.0.0",
|
||||||
@@ -8187,6 +8188,16 @@
|
|||||||
"node": ">= 10.12.0"
|
"node": ">= 10.12.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/node-gyp-build": {
|
||||||
|
"version": "4.6.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.1.tgz",
|
||||||
|
"integrity": "sha512-24vnklJmyRS8ViBNI8KbtK/r/DmXQMRiOMXTNz2nrTnAYUwjmEEbnnpB/+kt+yWRv73bPsSPRFddrcIbAxSiMQ==",
|
||||||
|
"bin": {
|
||||||
|
"node-gyp-build": "bin.js",
|
||||||
|
"node-gyp-build-optional": "optional.js",
|
||||||
|
"node-gyp-build-test": "build-test.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/node-gyp/node_modules/are-we-there-yet": {
|
"node_modules/node-gyp/node_modules/are-we-there-yet": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-3.0.1.tgz",
|
||||||
@@ -11355,6 +11366,19 @@
|
|||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"node_modules/zeromq": {
|
||||||
|
"version": "5.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/zeromq/-/zeromq-5.3.1.tgz",
|
||||||
|
"integrity": "sha512-4WDF9bNWWXe8OAI319bVw5dmG4BklEk8wzFGwRQxEzKb+0mgDU5J/jtyZPo0BEusVIU1+3mRQIEdT5LtQn+aAw==",
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"dependencies": {
|
||||||
|
"nan": "2.17.0",
|
||||||
|
"node-gyp-build": "^4.5.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -17662,6 +17686,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node-gyp-build": {
|
||||||
|
"version": "4.6.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.6.1.tgz",
|
||||||
|
"integrity": "sha512-24vnklJmyRS8ViBNI8KbtK/r/DmXQMRiOMXTNz2nrTnAYUwjmEEbnnpB/+kt+yWRv73bPsSPRFddrcIbAxSiMQ=="
|
||||||
|
},
|
||||||
"node-int64": {
|
"node-int64": {
|
||||||
"version": "0.4.0",
|
"version": "0.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
|
||||||
@@ -19818,6 +19847,15 @@
|
|||||||
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",
|
||||||
"integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==",
|
"integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==",
|
||||||
"dev": true
|
"dev": true
|
||||||
|
},
|
||||||
|
"zeromq": {
|
||||||
|
"version": "5.3.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/zeromq/-/zeromq-5.3.1.tgz",
|
||||||
|
"integrity": "sha512-4WDF9bNWWXe8OAI319bVw5dmG4BklEk8wzFGwRQxEzKb+0mgDU5J/jtyZPo0BEusVIU1+3mRQIEdT5LtQn+aAw==",
|
||||||
|
"requires": {
|
||||||
|
"nan": "2.17.0",
|
||||||
|
"node-gyp-build": "^4.5.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -45,7 +45,8 @@
|
|||||||
"rxjs": "^7.2.0",
|
"rxjs": "^7.2.0",
|
||||||
"sqlite3": "^5.1.6",
|
"sqlite3": "^5.1.6",
|
||||||
"tiny-secp256k1": "^2.2.3",
|
"tiny-secp256k1": "^2.2.3",
|
||||||
"typeorm": "^0.3.17"
|
"typeorm": "^0.3.17",
|
||||||
|
"zeromq": "^5.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nestjs/cli": "^9.0.0",
|
"@nestjs/cli": "^9.0.0",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { BehaviorSubject, filter, shareReplay } from 'rxjs';
|
|||||||
|
|
||||||
import { IBlockTemplate } from '../models/bitcoin-rpc/IBlockTemplate';
|
import { IBlockTemplate } from '../models/bitcoin-rpc/IBlockTemplate';
|
||||||
import { IMiningInfo } from '../models/bitcoin-rpc/IMiningInfo';
|
import { IMiningInfo } from '../models/bitcoin-rpc/IMiningInfo';
|
||||||
|
import * as zmq from 'zeromq';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class BitcoinRpcService {
|
export class BitcoinRpcService {
|
||||||
@@ -25,17 +26,28 @@ export class BitcoinRpcService {
|
|||||||
|
|
||||||
console.log('Bitcoin RPC connected');
|
console.log('Bitcoin RPC connected');
|
||||||
|
|
||||||
// Maybe use ZeroMQ ?
|
if (this.configService.get('BITCOIN_ZMQ_HOST')) {
|
||||||
setInterval(async () => {
|
const sock = zmq.socket("sub");
|
||||||
const miningInfo = await this.getMiningInfo();
|
sock.connect(this.configService.get('BITCOIN_ZMQ_HOST'));
|
||||||
if (miningInfo != null && miningInfo.blocks > this.blockHeight) {
|
sock.subscribe("rawblock");
|
||||||
this._newBlock$.next(miningInfo);
|
sock.on("message", async (topic: Buffer, message: Buffer) => {
|
||||||
this.blockHeight = miningInfo.blocks;
|
console.log("new block zmq");
|
||||||
}
|
this.pollMiningInfo();
|
||||||
|
});
|
||||||
}, 500);
|
this.pollMiningInfo();
|
||||||
|
} else {
|
||||||
|
setInterval(this.pollMiningInfo.bind(this), 500);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async pollMiningInfo() {
|
||||||
|
const miningInfo = await this.getMiningInfo();
|
||||||
|
if (miningInfo != null && miningInfo.blocks > this.blockHeight) {
|
||||||
|
console.log("block height change");
|
||||||
|
this._newBlock$.next(miningInfo);
|
||||||
|
this.blockHeight = miningInfo.blocks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async getBlockTemplate(): Promise<IBlockTemplate> {
|
public async getBlockTemplate(): Promise<IBlockTemplate> {
|
||||||
let result: IBlockTemplate;
|
let result: IBlockTemplate;
|
||||||
|
|||||||
Reference in New Issue
Block a user