mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2025-03-27 02:02:10 +01:00
block template
This commit is contained in:
parent
01b65b893a
commit
deb3aa30d4
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -6,6 +6,7 @@
|
||||
"merkle",
|
||||
"nbits",
|
||||
"ntime",
|
||||
"prevhash"
|
||||
"prevhash",
|
||||
"Tempalte"
|
||||
]
|
||||
}
|
@ -5,18 +5,20 @@ import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { BitcoinRpcService } from './bitcoin-rpc.service';
|
||||
import { BitcoinStratumProvider } from './bitcoin-stratum.provider';
|
||||
import { CoinbaseConstructorService } from './coinbase-constructor.service';
|
||||
|
||||
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule
|
||||
ConfigModule.forRoot()
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [
|
||||
AppService,
|
||||
BitcoinStratumProvider,
|
||||
BitcoinRpcService
|
||||
BitcoinRpcService,
|
||||
CoinbaseConstructorService
|
||||
],
|
||||
})
|
||||
export class AppModule {
|
||||
|
@ -1,10 +1,12 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { RPCClient } from 'rpc-bitcoin';
|
||||
|
||||
import { IBlockTempalte } from './models/IBlockTempalte';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class BitcoinRpcService {
|
||||
export class BitcoinRpcService implements OnModuleInit {
|
||||
|
||||
private client: RPCClient;
|
||||
|
||||
@ -14,20 +16,31 @@ export class BitcoinRpcService {
|
||||
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');
|
||||
}
|
||||
|
||||
async onModuleInit(): Promise<void> {
|
||||
console.log('onModuleInit');
|
||||
// Asynchronous initialization logic
|
||||
//await this.getBlockTemplate();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public async getBlockTemplate() {
|
||||
|
||||
const result = await this.client.getblocktemplate({
|
||||
const result: IBlockTempalte = await this.client.getblocktemplate({
|
||||
template_request: {
|
||||
rules: ['segwit'],
|
||||
mode: 'template',
|
||||
capabilities: ['serverlist', 'proposal']
|
||||
}
|
||||
});
|
||||
|
||||
console.log('Block Template: ', JSON.stringify(result));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Server, Socket } from 'net';
|
||||
|
||||
import { CoinbaseConstructorService } from './coinbase-constructor.service';
|
||||
import { StratumV1Client } from './models/StratumV1Client';
|
||||
|
||||
@Injectable()
|
||||
@ -10,7 +11,8 @@ export class BitcoinStratumProvider {
|
||||
|
||||
private server: Server;
|
||||
|
||||
constructor() {
|
||||
constructor(private coinbaseConstructorService: CoinbaseConstructorService) {
|
||||
|
||||
this.server = new Server((socket: Socket) => {
|
||||
console.log('New client connected:', socket.remoteAddress);
|
||||
|
||||
|
14
src/coinbase-constructor.service.ts
Normal file
14
src/coinbase-constructor.service.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { BitcoinRpcService } from './bitcoin-rpc.service';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class CoinbaseConstructorService {
|
||||
|
||||
constructor(private bitcoinRPCService: BitcoinRpcService) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
41
src/models/IBlockTempalte.ts
Normal file
41
src/models/IBlockTempalte.ts
Normal file
@ -0,0 +1,41 @@
|
||||
export interface IBlockTempalte {
|
||||
// (json object)
|
||||
version: number; // (numeric) The preferred block version
|
||||
rules: string[]; // (json array) specific block rules that are to be enforced // (string) name of a rule the client must understand to some extent; see BIP 9 for format
|
||||
|
||||
vbavailable: { // (json object) set of pending, supported versionbit (BIP 9) softfork deployments
|
||||
rulename: number, // (numeric) identifies the bit number as indicating acceptance and readiness for the named softfork rule
|
||||
},
|
||||
vbrequired: number, // (numeric) bit mask of versionbits the server requires set in submissions
|
||||
previousblockhash: string, // (string) The hash of current highest block
|
||||
transactions: [ // (json array) contents of non-coinbase transactions that should be included in the next block
|
||||
{ // (json object)
|
||||
data: string; //'hex', // (string) transaction data encoded in hexadecimal (byte-for-byte)
|
||||
txid: string; //'hex', // (string) transaction id encoded in little-endian hexadecimal
|
||||
hash: string; //'hex', // (string) hash encoded in little-endian hexadecimal (including witness data)
|
||||
depends: number[]; // (json array) array of numbers // (numeric) transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is
|
||||
fee: number, // (numeric) difference in value between transaction inputs and outputs (in satoshis); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one
|
||||
sigops: number, // (numeric) total SigOps cost, as counted for purposes of block limits; if key is not present, sigop cost is unknown and clients MUST NOT assume it is zero
|
||||
weight: number // (numeric) total transaction weight, as counted for purposes of block limits
|
||||
}
|
||||
],
|
||||
coinbaseaux: { // (json object) data that should be included in the coinbase's scriptSig content
|
||||
key: string; //'hex', // (string) values must be in the coinbase (keys may be ignored)
|
||||
},
|
||||
coinbasevalue: number, // (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in satoshis)
|
||||
longpollid: string, // (string) an id to include with a request to longpoll on an update to this template
|
||||
target: string, // (string) The hash target
|
||||
mintime: number, // (numeric) The minimum timestamp appropriate for the next block time, expressed in UNIX epoch time
|
||||
mutable: string[]; // (json array) list of ways the block template may be changed // (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'
|
||||
|
||||
noncerange: string; // 'hex', // (string) A range of valid nonces
|
||||
sigoplimit: number, // (numeric) limit of sigops in blocks
|
||||
sizelimit: number, // (numeric) limit of block size
|
||||
weightlimit: number, // (numeric) limit of block weight
|
||||
curtime: number, // (numeric) current timestamp in UNIX epoch time
|
||||
bits: string, // (string) compressed target of next block
|
||||
height: number, // (numeric) The height of the next block
|
||||
default_witness_commitment: string // (string, optional) a valid witness commitment for the unmodified block template
|
||||
|
||||
|
||||
}
|
@ -9,12 +9,12 @@ export class MiningJob {
|
||||
|
||||
|
||||
public job_id: string; // ID of the job. Use this ID while submitting share generated from this job.
|
||||
public prevhash: string; // Hash of previous block.
|
||||
public coinb1: string; // Initial part of coinbase transaction.
|
||||
public coinb2: string; // Final part of coinbase transaction.
|
||||
public prevhash: string; // The hex-encoded previous block hash.
|
||||
public coinb1: string; // The hex-encoded prefix of the coinbase transaction (to precede extra nonce 2).
|
||||
public coinb2: string; //The hex-encoded suffix of the coinbase transaction (to follow extra nonce 2).
|
||||
public merkle_branch: string[]; // List of hashes, will be used for calculation of merkle root. This is not a list of all transactions, it only contains prepared hashes of steps of merkle tree algorithm.
|
||||
public version: string; // Bitcoin block version.
|
||||
public nbits: string; // Encoded current network difficulty
|
||||
public version: string; // The hex-encoded block version.
|
||||
public nbits: string; // The hex-encoded network difficulty required for the block.
|
||||
public ntime: string; // Current ntime/
|
||||
public clean_jobs: boolean; // When true, server indicates that submitting shares from previous jobs don't have a sense and such shares will be rejected. When this flag is set, miner should also drop all previous jobs too.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user