rossihwang
rossihwang

Reputation: 29

How can the miner access the host like stratum+tcp:// directly

I found many resources about the Getwork in Bitcoin or Litecoin. It needs me to run a proxy on my computer so that the miner software can get work from the mining pool.

I was wondering how can one access a host like stratum+tcp:// directly?

Is there any protocol or example code that you know - preferably in 'C' or Python?

Upvotes: 2

Views: 1443

Answers (3)

Xylen
Xylen

Reputation: 59

Here is a basic example to connect to a Monero mining pool and receive a job:

import socket
import json

# Stratum server details
host = 'stratum.cudopool.com'
port = 30010
username = 'o:899531:n:pythonproxytest'
password = 'x'

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
    # Connect to the Stratum server
    sock.connect((host, port))
    
    # Send subscription request (mining.subscribe)
    subscribe_message = {
        "id": 1,
        "method": "mining.subscribe",
        "params": ["xmrig/6.14.1"]
    }
    
    print(f"Sending subscribe message: {subscribe_message}")
    sock.sendall((json.dumps(subscribe_message) + '\n').encode('utf-8'))
    
    # Send authorization request 
    authorize_message = {"id":1,"jsonrpc":"2.0","method":"login","params":{"login":"o:899531:n:pythonproxytest","pass":"x","agent":"XMRig/6.22.2 (Windows NT 10.0; Win64; x64) libuv/1.49.2 msvc/2019","algo":["rx/0","rx/wow","rx/arq","rx/graft","rx/sfx","rx/yada"]}}

    print(f"Sending authorize message: {authorize_message}")
    sock.sendall((json.dumps(authorize_message) + '\n').encode('utf-8'))

    # Receive and print server responses
    while True:
        data = sock.recv(1024).decode('utf-8')  # Receive data from the server
        if data:
            print('Received data...') # this will contain job data
            for message in data.split('\n'):
                if message:  # Ignore empty messages
                    try:
                        json_message = json.loads(message)
                        print(json.dumps(json_message, indent=4))  # Pretty print JSON
                    except json.JSONDecodeError:
                        print(f"Failed to decode message: {message}")

except Exception as e:
    print(f"An error occurred: {e}")

finally:
    sock.close()  # Close the connection

example job (response after authorization):

{
    "id": 1,
    "jsonrpc": "2.0",
    "error": null,
    "result": {
        "id": "0",
        "job": {
            "blob": "somereallybigthingy",
            "height": 3334630,
            "job_id": "0",
            "seed_hash": "anotherbigthingybutsmaller",
            "target": "somethingbutnottoobig"
        },
        "status": "OK"
    }
}

Upvotes: 0

snapo
snapo

Reputation: 704

Was thinking about the same and i think i did reverse engineer the stratum+tcp protocol so far...

import socket
import json

# Stratum server details
host = 'solo.ckpool.org'
port = 3333
username = '199QiJj1miojVSAop7gpAamscHd77r12ET'
password = 'x'

# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

try:
    # Connect to the Stratum server
    sock.connect((host, port))
    
    # Send subscription request (mining.subscribe)
    subscribe_message = {
        "id": 1,
        "method": "mining.subscribe",
        "params": []
    }
    print(f"Sending subscribe message: {subscribe_message}")
    sock.sendall((json.dumps(subscribe_message) + '\n').encode('utf-8'))

    # Send authorization request (mining.authorize)
    authorize_message = {
        "id": 2,
        "method": "mining.authorize",
        "params": [username, password]
    }
    print(f"Sending authorize message: {authorize_message}")
    sock.sendall((json.dumps(authorize_message) + '\n').encode('utf-8'))
    
    # Receive and print server responses
    while True:
        data = sock.recv(1024).decode('utf-8')  # Receive data from the server
        if data:
            for message in data.split('\n'):
                if message:  # Ignore empty messages
                    try:
                        json_message = json.loads(message)
                        print(json.dumps(json_message, indent=4))  # Pretty print JSON
                    except json.JSONDecodeError:
                        print(f"Failed to decode message: {message}")

except Exception as e:
    print(f"An error occurred: {e}")

finally:
    sock.close()  # Close the connection

what i still have a issue is / have to figure out is some params (did not yet all encode) but it might help you as a start.

Upvotes: 1

Yan LimaBenua
Yan LimaBenua

Reputation: 85

no directly but fun. test >> miningcore >> to make you stratum...

Upvotes: -1

Related Questions