mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 17:15:03 -07:00
+13
-2
@@ -40,8 +40,19 @@ export class MiningJob {
|
||||
|
||||
// 39th byte onwards: Optional data with no consensus meaning
|
||||
const extra = Buffer.from('\\public-pool\\');
|
||||
|
||||
// Encode the block height
|
||||
// https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki
|
||||
this.coinbaseTransaction.ins[0].script = Buffer.concat([Buffer.from([jobTemplate.blockData.littleEndianBlockHeight.byteLength]), jobTemplate.blockData.littleEndianBlockHeight, extra, Buffer.alloc(8, 0)]);
|
||||
const blockHeightEncoded = bitcoinjs.script.number.encode(jobTemplate.blockData.height);
|
||||
|
||||
// Get the length of the block height encoding
|
||||
const blockHeightLengthByte = Buffer.from([blockHeightEncoded.length]);
|
||||
|
||||
// generate padding and take length of encode blockHeight into account
|
||||
const padding = Buffer.alloc(8 + (3 - blockHeightEncoded.length), 0)
|
||||
|
||||
// build the script
|
||||
this.coinbaseTransaction.ins[0].script = Buffer.concat([blockHeightLengthByte, blockHeightEncoded, extra, padding])
|
||||
|
||||
this.coinbaseTransaction.addOutput(bitcoinjs.script.compile([bitcoinjs.opcodes.OP_RETURN, Buffer.concat([segwitMagicBits, jobTemplate.block.witnessCommit])]), 0);
|
||||
|
||||
@@ -196,4 +207,4 @@ export class MiningJob {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,9 +392,21 @@ export class StratumV1Client {
|
||||
];
|
||||
}
|
||||
|
||||
const networkConfig = this.configService.get('NETWORK');
|
||||
let network;
|
||||
|
||||
if (networkConfig === 'mainnet') {
|
||||
network = bitcoinjs.networks.bitcoin;
|
||||
} else if (networkConfig === 'testnet') {
|
||||
network = bitcoinjs.networks.testnet;
|
||||
} else if (networkConfig === 'regtest') {
|
||||
network = bitcoinjs.networks.regtest;
|
||||
} else {
|
||||
throw new Error('Invalid network configuration');
|
||||
}
|
||||
|
||||
const job = new MiningJob(
|
||||
this.configService.get('NETWORK') === 'mainnet' ? bitcoinjs.networks.bitcoin : bitcoinjs.networks.testnet,
|
||||
network,
|
||||
this.stratumV1JobsService.getNextId(),
|
||||
payoutInformation,
|
||||
jobTemplate
|
||||
|
||||
@@ -13,7 +13,6 @@ export interface IJobTemplate {
|
||||
merkle_branch: string[];
|
||||
blockData: {
|
||||
id: string,
|
||||
littleEndianBlockHeight: Buffer;
|
||||
coinbasevalue: number;
|
||||
networkDifficulty: number;
|
||||
height: number;
|
||||
@@ -72,7 +71,6 @@ export class StratumV1JobsService {
|
||||
bits: parseInt(blockTemplate.bits, 16),
|
||||
prevHash: this.convertToLittleEndian(blockTemplate.previousblockhash),
|
||||
transactions: blockTemplate.transactions.map(t => bitcoinjs.Transaction.fromHex(t.data)),
|
||||
littleEndianBlockHeight: this.convertToLittleEndian(blockTemplate.height.toString(16).padStart(6, '0')),
|
||||
coinbasevalue: blockTemplate.coinbasevalue,
|
||||
timestamp: Math.floor(new Date().getTime() / 1000),
|
||||
networkDifficulty: this.calculateNetworkDifficulty(parseInt(blockTemplate.bits, 16)),
|
||||
@@ -81,7 +79,7 @@ export class StratumV1JobsService {
|
||||
};
|
||||
}),
|
||||
filter(next => next != null),
|
||||
map(({ version, bits, prevHash, transactions, timestamp, littleEndianBlockHeight, coinbasevalue, networkDifficulty, clearJobs, height }) => {
|
||||
map(({ version, bits, prevHash, transactions, timestamp, coinbasevalue, networkDifficulty, clearJobs, height }) => {
|
||||
const block = new bitcoinjs.Block();
|
||||
|
||||
//create an empty coinbase tx
|
||||
@@ -115,7 +113,6 @@ export class StratumV1JobsService {
|
||||
merkle_branch,
|
||||
blockData: {
|
||||
id,
|
||||
littleEndianBlockHeight,
|
||||
coinbasevalue,
|
||||
networkDifficulty,
|
||||
height,
|
||||
@@ -176,4 +173,4 @@ export class StratumV1JobsService {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user