Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

coin-hive-stratum

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coin-hive-stratum - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

src/queue.js

2

package.json
{
"name": "coin-hive-stratum",
"version": "1.0.0",
"version": "1.0.1",
"description": "proxy to use CoinHive miner on any stratum pool",

@@ -5,0 +5,0 @@ "main": "src/proxy.js",

const WebSocket = require('ws');
const Queue = require('./queue');
const net = require('net');

@@ -12,17 +13,95 @@ const defaults = require('../config/defaults');

log('listening on port', port);
let socket = new net.Socket();
log('tcp socket created');
socket.connect(+constructorOptions.port, constructorOptions.host, function () {
log('connected to pool');
log('host', constructorOptions.host);
log('port', constructorOptions.port);
wss.on('connection', (ws) => {
let online = true;
let workerId = null;
let rpcId = 1;
let hashes = 1;
let getRpcId = () => rpcId++;
let getHashes = () => (hashes++);
let sendToPool = (payload) => {
const stratumMessage = JSON.stringify(payload);
wss.on('connection', (ws) => {
let getRpcId = null;
let getHashes = null;
let sendToPool = null;
let online = null;
let workerId = null;
let rpcId = null;
let hashes = null;
let socket = null;
log('new websocket connection');
let queue = new Queue();
log('queue created');
ws.on('message', function (message) {
queue.push({
type: 'message',
payload: message
});
});
ws.on('close', () => {
queue.push({
type: 'close',
payload: null
});
});
ws.on('error', (error) => {
queue.push({
type: 'error',
payload: error
});
});
queue.on('close', () => {
online = false;
if (socket) {
queue.stop();
socket.destroy();
}
log('miner connection closed');
});
queue.on('error', (error) => {
if (socket) {
queue.stop();
socket.destroy();
}
log('miner connection error', error.message);
});
queue.on('message', function (message) {
log('\nmessage from miner to pool:\n\n', message);
const data = JSON.parse(message);
switch (data.type) {
case 'auth': {
let login = data.params.site_key;
if (data.params.user) {
login += '.' + data.params.user;
}
sendToPool({
id: getRpcId(),
method: 'login',
params: {
login: login,
pass: 'x'
},
});
break;
}
case 'submit': {
sendToPool({
id: getRpcId(),
method: 'submit',
params: {
id: workerId,
job_id: data.params.job_id,
nonce: data.params.nonce,
result: data.params.result
}
});
break;
}
}
})
socket = new net.Socket();
log('tcp socket created');
socket.connect(+constructorOptions.port, constructorOptions.host, function () {
log('connected to pool');
log('host', constructorOptions.host);
log('port', constructorOptions.port);
online = true;
workerId = null;
rpcId = 1;
hashes = 1;
getRpcId = () => rpcId++;
getHashes = () => (hashes++);
sendToPool = (payload) => {
const stratumMessage = JSON.stringify(payload) + '\n';
socket.write(stratumMessage);

@@ -40,32 +119,2 @@ log('\nmessage sent to pool:\n\n', stratumMessage);

}
log('new websocket connection');
ws.on('message', function (message) {
log('\nmessage from miner to pool:\n\n', message);
const data = JSON.parse(message);
switch (data.type) {
case 'auth': {
let login = data.params.site_key;
if (data.params.user) {
login += '.' + data.params.user;
}
sendToPool({
id: getRpcId(),
method: 'login',
params: {
login: login,
pass: 'x'
},
});
break;
}
case 'submit': {
sendToPool({
id: getRpcId(),
method: 'submit',
params: data.params
});
break;
}
}
});
socket.on('data', function (buffer) {

@@ -107,15 +156,14 @@ const stratumMessage = buffer.toString('utf8');

});
ws.on('close', () => {
online = false;
});
ws.on('error', (error) => {
log('miner connection error', error);
});
socket.on('close', function () {
log('connection to pool closed');
ws.close();
queue.stop();
});
socket.on('error', function (error) {
log('pool connection error', error);
log('pool connection error', error && error.message ? error.message : error);
ws.close();
queue.stop();
});
queue.start();
log('queue started');
});

@@ -122,0 +170,0 @@ })

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc