mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2025-03-18 22:01:43 +01:00
bitcoin rpc
This commit is contained in:
parent
ff6adb8a65
commit
01b65b893a
5
.env.example
Normal file
5
.env.example
Normal file
@ -0,0 +1,5 @@
|
||||
BITCOIN_RPC_URL=http://192.168.1.100
|
||||
BITCOIN_RPC_USER=
|
||||
BITCOIN_RPC_PASSWORD=
|
||||
BITCOIN_RPC_PORT=8332
|
||||
BITCOIN_RPC_TIMEOUT=10000
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -26,6 +26,8 @@ lerna-debug.log*
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
.env
|
||||
settings.json
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
|
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@ -2,6 +2,7 @@
|
||||
"cSpell.words": [
|
||||
"coinb",
|
||||
"Fastify",
|
||||
"getblocktemplate",
|
||||
"merkle",
|
||||
"nbits",
|
||||
"ntime",
|
||||
|
69
package-lock.json
generated
69
package-lock.json
generated
@ -10,6 +10,7 @@
|
||||
"license": "UNLICENSED",
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^9.0.0",
|
||||
"@nestjs/config": "^2.3.2",
|
||||
"@nestjs/core": "^9.0.0",
|
||||
"@nestjs/platform-fastify": "^9.4.2",
|
||||
"class-transformer": "^0.5.1",
|
||||
@ -1553,6 +1554,30 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/config": {
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/config/-/config-2.3.2.tgz",
|
||||
"integrity": "sha512-VtGV8PBpxzMzz68kdxTWqPm9v7SYCSZXQ0tC72AMNnjdmU+CVjUSLpEpdnm0XcWHxE1nV6wSI3HZxsATIV4ZxA==",
|
||||
"dependencies": {
|
||||
"dotenv": "16.0.3",
|
||||
"dotenv-expand": "10.0.0",
|
||||
"lodash": "4.17.21",
|
||||
"uuid": "9.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@nestjs/common": "^7.0.0 || ^8.0.0 || ^9.0.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rxjs": "^6.0.0 || ^7.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/config/node_modules/uuid": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz",
|
||||
"integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==",
|
||||
"bin": {
|
||||
"uuid": "dist/bin/uuid"
|
||||
}
|
||||
},
|
||||
"node_modules/@nestjs/core": {
|
||||
"version": "9.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/core/-/core-9.4.2.tgz",
|
||||
@ -3449,6 +3474,22 @@
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv-expand": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz",
|
||||
"integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/ecc-jsbn": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
|
||||
@ -9531,6 +9572,24 @@
|
||||
"uid": "2.0.2"
|
||||
}
|
||||
},
|
||||
"@nestjs/config": {
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/config/-/config-2.3.2.tgz",
|
||||
"integrity": "sha512-VtGV8PBpxzMzz68kdxTWqPm9v7SYCSZXQ0tC72AMNnjdmU+CVjUSLpEpdnm0XcWHxE1nV6wSI3HZxsATIV4ZxA==",
|
||||
"requires": {
|
||||
"dotenv": "16.0.3",
|
||||
"dotenv-expand": "10.0.0",
|
||||
"lodash": "4.17.21",
|
||||
"uuid": "9.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"uuid": {
|
||||
"version": "9.0.0",
|
||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz",
|
||||
"integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@nestjs/core": {
|
||||
"version": "9.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@nestjs/core/-/core-9.4.2.tgz",
|
||||
@ -10968,6 +11027,16 @@
|
||||
"esutils": "^2.0.2"
|
||||
}
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "16.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ=="
|
||||
},
|
||||
"dotenv-expand": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/dotenv-expand/-/dotenv-expand-10.0.0.tgz",
|
||||
"integrity": "sha512-GopVGCpVS1UKH75VKHGuQFqS1Gusej0z4FyQkPdwjil2gNIv+LNsqBlboOzpJFZKVT95GkCyWJbBSdFEFUWI2A=="
|
||||
},
|
||||
"ecc-jsbn": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
|
||||
|
@ -21,6 +21,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^9.0.0",
|
||||
"@nestjs/config": "^2.3.2",
|
||||
"@nestjs/core": "^9.0.0",
|
||||
"@nestjs/platform-fastify": "^9.4.2",
|
||||
"class-transformer": "^0.5.1",
|
||||
|
@ -1,17 +1,23 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { BitcoinRpcService } from './bitcoin-rpc.service';
|
||||
import { BitcoinStratumProvider } from './bitcoin-stratum.provider';
|
||||
|
||||
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
||||
ConfigModule
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService, BitcoinStratumProvider],
|
||||
providers: [
|
||||
AppService,
|
||||
BitcoinStratumProvider,
|
||||
BitcoinRpcService
|
||||
],
|
||||
})
|
||||
export class AppModule {
|
||||
constructor(private readonly bitcoinStratumProvider: BitcoinStratumProvider) {
|
||||
|
33
src/bitcoin-rpc.service.ts
Normal file
33
src/bitcoin-rpc.service.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { RPCClient } from 'rpc-bitcoin';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class BitcoinRpcService {
|
||||
|
||||
private client: RPCClient;
|
||||
|
||||
constructor(configService: ConfigService) {
|
||||
const url = configService.get('BITCOIN_RPC_URL');
|
||||
const user = configService.get('BITCOIN_RPC_USER');
|
||||
const pass = configService.get('BITCOIN_RPC_PASSWORD');
|
||||
const port = parseInt(configService.get('BITCOIN_RPC_PORT'));
|
||||
const timeout = parseInt(configService.get('BITCOIN_RPC_TIMEOUT'));
|
||||
this.client = new RPCClient({ url, port, timeout, user, pass });
|
||||
console.log('Bitcoin RPC connected');
|
||||
}
|
||||
|
||||
|
||||
public async getBlockTemplate() {
|
||||
|
||||
const result = await this.client.getblocktemplate({
|
||||
template_request: {
|
||||
rules: ['segwit'],
|
||||
mode: 'template',
|
||||
capabilities: ['serverlist', 'proposal']
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user