This commit is contained in:
Ben Wilson 2023-07-31 09:12:58 -04:00
parent 432f5c4325
commit 3a1ae6bf09
6 changed files with 49 additions and 8 deletions

View File

@ -1,5 +1,6 @@
{ {
"cSpell.words": [ "cSpell.words": [
"bitcoinjs",
"coinb", "coinb",
"coinbasevalue", "coinbasevalue",
"Fastify", "Fastify",

33
package-lock.json generated
View File

@ -32,6 +32,7 @@
"rpc-bitcoin": "^2.0.0", "rpc-bitcoin": "^2.0.0",
"rxjs": "^7.2.0", "rxjs": "^7.2.0",
"sqlite3": "^5.1.6", "sqlite3": "^5.1.6",
"tiny-secp256k1": "^2.2.3",
"typeorm": "^0.3.17" "typeorm": "^0.3.17"
}, },
"devDependencies": { "devDependencies": {
@ -10359,6 +10360,17 @@
"node": ">=12" "node": ">=12"
} }
}, },
"node_modules/tiny-secp256k1": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/tiny-secp256k1/-/tiny-secp256k1-2.2.3.tgz",
"integrity": "sha512-SGcL07SxcPN2nGKHTCvRMkQLYPSoeFcvArUSCYtjVARiFAWU44cCIqYS0mYAU6nY7XfvwURuTIGo2Omt3ZQr0Q==",
"dependencies": {
"uint8array-tools": "0.0.7"
},
"engines": {
"node": ">=14.0.0"
}
},
"node_modules/tmp": { "node_modules/tmp": {
"version": "0.0.33", "version": "0.0.33",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz",
@ -10859,6 +10871,14 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/uint8array-tools": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/uint8array-tools/-/uint8array-tools-0.0.7.tgz",
"integrity": "sha512-vrrNZJiusLWoFWBqz5Y5KMCgP9W9hnjZHzZiZRT8oNAkq3d5Z5Oe76jAvVVSRh4U8GGR90N2X1dWtrhvx6L8UQ==",
"engines": {
"node": ">=14.0.0"
}
},
"node_modules/unbox-primitive": { "node_modules/unbox-primitive": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz",
@ -19158,6 +19178,14 @@
"resolved": "https://registry.npmjs.org/tiny-lru/-/tiny-lru-11.0.1.tgz", "resolved": "https://registry.npmjs.org/tiny-lru/-/tiny-lru-11.0.1.tgz",
"integrity": "sha512-iNgFugVuQgBKrqeO/mpiTTgmBsTP0WL6yeuLfLs/Ctf0pI/ixGqIRm8sDCwMcXGe9WWvt2sGXI5mNqZbValmJg==" "integrity": "sha512-iNgFugVuQgBKrqeO/mpiTTgmBsTP0WL6yeuLfLs/Ctf0pI/ixGqIRm8sDCwMcXGe9WWvt2sGXI5mNqZbValmJg=="
}, },
"tiny-secp256k1": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/tiny-secp256k1/-/tiny-secp256k1-2.2.3.tgz",
"integrity": "sha512-SGcL07SxcPN2nGKHTCvRMkQLYPSoeFcvArUSCYtjVARiFAWU44cCIqYS0mYAU6nY7XfvwURuTIGo2Omt3ZQr0Q==",
"requires": {
"uint8array-tools": "0.0.7"
}
},
"tmp": { "tmp": {
"version": "0.0.33", "version": "0.0.33",
"resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz",
@ -19440,6 +19468,11 @@
"@lukeed/csprng": "^1.0.0" "@lukeed/csprng": "^1.0.0"
} }
}, },
"uint8array-tools": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/uint8array-tools/-/uint8array-tools-0.0.7.tgz",
"integrity": "sha512-vrrNZJiusLWoFWBqz5Y5KMCgP9W9hnjZHzZiZRT8oNAkq3d5Z5Oe76jAvVVSRh4U8GGR90N2X1dWtrhvx6L8UQ=="
},
"unbox-primitive": { "unbox-primitive": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz",

View File

@ -43,6 +43,7 @@
"rpc-bitcoin": "^2.0.0", "rpc-bitcoin": "^2.0.0",
"rxjs": "^7.2.0", "rxjs": "^7.2.0",
"sqlite3": "^5.1.6", "sqlite3": "^5.1.6",
"tiny-secp256k1": "^2.2.3",
"typeorm": "^0.3.17" "typeorm": "^0.3.17"
}, },
"devDependencies": { "devDependencies": {

View File

@ -1,7 +1,9 @@
import { ValidationPipe } from '@nestjs/common'; import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core'; import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify'; import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import * as bitcoinjs from 'bitcoinjs-lib';
import { useContainer } from 'class-validator'; import { useContainer } from 'class-validator';
import * as ecc from 'tiny-secp256k1';
import { AppModule } from './app.module'; import { AppModule } from './app.module';
@ -25,6 +27,10 @@ async function bootstrap() {
); );
app.enableCors(); app.enableCors();
useContainer(app.select(AppModule), { fallbackOnErrors: true }); useContainer(app.select(AppModule), { fallbackOnErrors: true });
//Taproot
bitcoinjs.initEccLib(ecc);
await app.listen(process.env.PORT, '0.0.0.0', () => { await app.listen(process.env.PORT, '0.0.0.0', () => {
console.log(`http listening on port ${process.env.PORT}`); console.log(`http listening on port ${process.env.PORT}`);
}); });

View File

@ -62,8 +62,6 @@ export class MiningJob {
const testBlock = Object.assign(new bitcoinjs.Block(), jobTemplate.block); const testBlock = Object.assign(new bitcoinjs.Block(), jobTemplate.block);
testBlock.transactions[0] = this.coinbaseTransaction; testBlock.transactions[0] = this.coinbaseTransaction;
testBlock.nonce = nonce; testBlock.nonce = nonce;
@ -84,7 +82,7 @@ export class MiningJob {
testBlock.timestamp = timestamp; testBlock.timestamp = timestamp;
return testBlock as any; return testBlock;
} }

View File

@ -287,11 +287,13 @@ export class StratumV1Client extends EasyUnsubscribe {
this.stratumV1JobsService.newMiningJob$.pipe( this.stratumV1JobsService.newMiningJob$.pipe(
takeUntil(this.easyUnsubscribe) takeUntil(this.easyUnsubscribe)
).subscribe(async (jobTemplate) => { ).subscribe(async (jobTemplate) => {
await this.sendNewMiningJob(jobTemplate); try {
await this.sendNewMiningJob(jobTemplate);
await this.checkDifficulty(); await this.checkDifficulty();
await this.watchdog();
await this.watchdog(); } catch (e) {
this.promiseSocket.socket.emit('end', true);
}
}); });
} }