From 3a1ae6bf09f4a72921f48436f987b60d5c9fc291 Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Mon, 31 Jul 2023 09:12:58 -0400 Subject: [PATCH] taproot --- .vscode/settings.json | 1 + package-lock.json | 33 +++++++++++++++++++++++++++++++++ package.json | 1 + src/main.ts | 6 ++++++ src/models/MiningJob.ts | 4 +--- src/models/StratumV1Client.ts | 12 +++++++----- 6 files changed, 49 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index efe6615..96065aa 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "cSpell.words": [ + "bitcoinjs", "coinb", "coinbasevalue", "Fastify", diff --git a/package-lock.json b/package-lock.json index e84297b..228cd36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "rpc-bitcoin": "^2.0.0", "rxjs": "^7.2.0", "sqlite3": "^5.1.6", + "tiny-secp256k1": "^2.2.3", "typeorm": "^0.3.17" }, "devDependencies": { @@ -10359,6 +10360,17 @@ "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": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -10859,6 +10871,14 @@ "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": { "version": "1.0.2", "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", "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": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", @@ -19440,6 +19468,11 @@ "@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": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", diff --git a/package.json b/package.json index 94e96ac..3343400 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "rpc-bitcoin": "^2.0.0", "rxjs": "^7.2.0", "sqlite3": "^5.1.6", + "tiny-secp256k1": "^2.2.3", "typeorm": "^0.3.17" }, "devDependencies": { diff --git a/src/main.ts b/src/main.ts index 159c1d6..14eab4c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,9 @@ import { ValidationPipe } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify'; +import * as bitcoinjs from 'bitcoinjs-lib'; import { useContainer } from 'class-validator'; +import * as ecc from 'tiny-secp256k1'; import { AppModule } from './app.module'; @@ -25,6 +27,10 @@ async function bootstrap() { ); app.enableCors(); useContainer(app.select(AppModule), { fallbackOnErrors: true }); + + //Taproot + bitcoinjs.initEccLib(ecc); + await app.listen(process.env.PORT, '0.0.0.0', () => { console.log(`http listening on port ${process.env.PORT}`); }); diff --git a/src/models/MiningJob.ts b/src/models/MiningJob.ts index f6ac6b0..28a796b 100644 --- a/src/models/MiningJob.ts +++ b/src/models/MiningJob.ts @@ -62,8 +62,6 @@ export class MiningJob { const testBlock = Object.assign(new bitcoinjs.Block(), jobTemplate.block); - - testBlock.transactions[0] = this.coinbaseTransaction; testBlock.nonce = nonce; @@ -84,7 +82,7 @@ export class MiningJob { testBlock.timestamp = timestamp; - return testBlock as any; + return testBlock; } diff --git a/src/models/StratumV1Client.ts b/src/models/StratumV1Client.ts index 5dad297..abcb7fe 100644 --- a/src/models/StratumV1Client.ts +++ b/src/models/StratumV1Client.ts @@ -287,11 +287,13 @@ export class StratumV1Client extends EasyUnsubscribe { this.stratumV1JobsService.newMiningJob$.pipe( takeUntil(this.easyUnsubscribe) ).subscribe(async (jobTemplate) => { - await this.sendNewMiningJob(jobTemplate); - - await this.checkDifficulty(); - - await this.watchdog(); + try { + await this.sendNewMiningJob(jobTemplate); + await this.checkDifficulty(); + await this.watchdog(); + } catch (e) { + this.promiseSocket.socket.emit('end', true); + } }); }