mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 17:15:03 -07:00
cleanup and support for all address types
This commit is contained in:
+26
-2
@@ -1,3 +1,4 @@
|
||||
import { AddressType, getAddressInfo } from 'bitcoin-address-validation';
|
||||
import * as bitcoinjs from 'bitcoinjs-lib';
|
||||
import * as crypto from 'crypto';
|
||||
import { MerkleTree } from 'merkletreejs';
|
||||
@@ -134,10 +135,9 @@ export class MiningJob {
|
||||
let rewardBalance = reward;
|
||||
|
||||
addresses.forEach(recipientAddress => {
|
||||
const scriptPubKey = bitcoinjs.payments.p2wpkh({ address: recipientAddress.address, network: bitcoinjs.networks.testnet });
|
||||
const amount = Math.floor((recipientAddress.percent / 100) * reward);
|
||||
rewardBalance -= amount;
|
||||
coinbaseTransaction.addOutput(scriptPubKey.output, amount);
|
||||
coinbaseTransaction.addOutput(this.getPaymentScript(recipientAddress.address), amount);
|
||||
})
|
||||
|
||||
//Add any remaining sats from the Math.floor
|
||||
@@ -151,6 +151,30 @@ export class MiningJob {
|
||||
return coinbaseTransaction;
|
||||
}
|
||||
|
||||
private getPaymentScript(address: string): Buffer {
|
||||
const addressInfo = getAddressInfo(address);
|
||||
switch (addressInfo.type) {
|
||||
case AddressType.p2wpkh: {
|
||||
return bitcoinjs.payments.p2wpkh({ address, network: bitcoinjs.networks.testnet }).output;
|
||||
}
|
||||
case AddressType.p2pkh: {
|
||||
return bitcoinjs.payments.p2pkh({ address }).output;;
|
||||
}
|
||||
case AddressType.p2sh: {
|
||||
return bitcoinjs.payments.p2sh({ address }).output;;
|
||||
}
|
||||
case AddressType.p2tr: {
|
||||
return bitcoinjs.payments.p2tr({ address }).output;;
|
||||
}
|
||||
case AddressType.p2wsh: {
|
||||
return bitcoinjs.payments.p2wsh({ address }).output;
|
||||
}
|
||||
default: {
|
||||
return Buffer.alloc(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sha256(data) {
|
||||
return crypto.createHash('sha256').update(data).digest()
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ import * as crypto from 'crypto';
|
||||
import { Socket } from 'net';
|
||||
import { combineLatest, interval, startWith } from 'rxjs';
|
||||
|
||||
import { BitcoinRpcService } from '../bitcoin-rpc.service';
|
||||
import { BlockTemplateService } from '../BlockTemplateService';
|
||||
import { ClientStatisticsService } from '../ORM/client-statistics/client-statistics.service';
|
||||
import { ClientEntity } from '../ORM/client/client.entity';
|
||||
import { ClientService } from '../ORM/client/client.service';
|
||||
import { StratumV1JobsService } from '../stratum-v1-jobs.service';
|
||||
import { BitcoinRpcService } from '../services/bitcoin-rpc.service';
|
||||
import { BlockTemplateService } from '../services/block-template.service';
|
||||
import { StratumV1JobsService } from '../services/stratum-v1-jobs.service';
|
||||
import { EasyUnsubscribe } from '../utils/AutoUnsubscribe';
|
||||
import { eRequestMethod } from './enums/eRequestMethod';
|
||||
import { MiningJob } from './MiningJob';
|
||||
@@ -22,6 +22,7 @@ import { SuggestDifficulty } from './stratum-messages/SuggestDifficultyMessage';
|
||||
import { StratumV1ClientStatistics } from './StratumV1ClientStatistics';
|
||||
|
||||
|
||||
|
||||
export class StratumV1Client extends EasyUnsubscribe {
|
||||
|
||||
private clientSubscription: SubscriptionMessage;
|
||||
|
||||
Reference in New Issue
Block a user