mining.subscribe stratum method easy examples and explanations

Follow and share now!

mining.subscribe is a in the stratum protocol defined methods for a miner to subscript an encrypted currency mining pool for work:

Function of mining.subscribe:

mining.subscribe is except of the relative new mining.configuration usual the first data, a miner send after build up a TCP connection. It is send like all stratum methods as a JSON map and has a required and an optional parameter. The return value is a complex list structure, containing the initial difficulty, subscription id, Extranonce1 and Extranonce2_size. The Extranonce1 is per-connection unique to protect again repeating work, Extranonce2_size the size of Extranonce2 in bytes. The Nonces are numbers for changing the block headers double SHA-256 hash with the same core data. Many pools answer with a dummy difficulty and send after the answer immediate mining.set_difficulty. The pool starts after that to send work using mining.notify. You get jobs unauthenticated, but you need to send mining.authenticate to get paid for your work. That is usual the next command, the miner send.

mining.subscribe call:

Hint:

Extra line-wrapping for readability. Spaces get ignored but should get filtered out to keep the traffic for miner and pool as low as possible. A call ends with a line feed. (UTF-8 10/0x0A)

Description:

{
"id": <Number>,
"method": "mining.subscribe",
"params": [ <String>, <Number> ]
}
(\n)

The usual id is a for every call with expected return value increasing number, hence 0 or 1, but can be virtually anything. The params list contains a simple text line as personal identifier of the miner software and optional the last Extranonce. The pool may do but don’t need to continue with this.

Example:

{
"id": 0,
"method": "mining.subscribe",
"params": [ "cgminer/4.11.1" ]
}
(\n)

mining.subscribe response:

Description:

{
"id": 0,
"result": [ [ [ "mining.set_difficulty", "1" ], [ "mining.notify", "1" ] ], "066507045fcae8", 4 ],
"error": null
}
(\n)

id contains the same element, the request did. The result is a list. This list contains a list, the Extranonce1 coded as hexadecimal string and the size of Extranonce2 in bytes as number. The inner list contains two lists, each of them contains a property name and a string value. error contains a value to identify a happened error, if any occurred, null otherwise.

Example:

{
"id": 0,
"result": [ [ [ "mining.set_difficulty", "1" ], [ "mining.notify", "1" ] ], "066507045fcae8", 4 ],
"error": null
}
(\n)

Warning:

Make sure to send always the right data type. “4” is not the same as 4!

Java example implementation:

public final class StratumSender {
private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");
private static final String STRATUM_REQUEST_BASE =
"{\"id\":%s,\"method\":\"%s\",\"params\":[%s]}\n";
private final OutputStream out;
public StratumSender(final OutputStream out) {
if(out == null) {
throw new IllegalArgumentException("out == null");
}
this.out = out;
}
public void subscribe(final int id, final String identifier) {
if(identifier == null) {
throw new IllegalArgumentException("identifier == null");
}
final String f = String.format(STRATUM_REQUEST_BASE, id,
"mining.subscribe", identifier);
write(f);
}
public void subscribe(final int id, final String identifier,
final int extranonce) {
if(identifier == null) {
throw new IllegalArgumentException("identifier == null");
}
final String f = String.format(STRATUM_REQUEST_BASE, id,
"mining.subscribe", (identifier + "," + extranonce));
write(f);
}
public void write(final String s) {
write(s.getBytes(DEFAULT_CHARSET));
}
public void write(final byte[] bs) {
if(bs == null) {
throw new IllegalArgumentException("bs == null");
}
try {
out.write(bs);
} catch (final IOException e) {
throw new RuntimeException(e);
}// don't forget to flush the output
}
}

Post Your Comment Here

Your email address will not be published. Required fields are marked *

Free Demo!

Join the Calloway Crypto System now,
to get a free demo account:

Join the Calloway Crypto Soft now!

Read now the whole review!

If you have additional questions or stumble, please email immediate to earnmoneytodayblog@gmail.com or use the simple contact form.

 

earn-money.today successful challenge: 1041/2000 successful trader. Test now Calloway Crypto System or other verified trading systems for free and send us how successful you are and how much profit you made, and may what we can do for you.

52%

Last successful trader:
Antje B.
Be the next!