Documentation
¶
Overview ¶
stratum mining JSON: http://mining.bitcoin.cz/stratum-mining/
subscribe:
{"id": 1, "method": "mining.subscribe", "params": []} -> subscribe to notifications
{"id": 1, "result": [
[["mining.set_difficulty",
"b4b6693b72a50c7116db18d6497cac52"], -> subscription id to cancel this type of notification
["mining.notify",
"ae6812eb4cd7735a302a8a9dd95cf71f"]], -> subscription id to cancel this type of notification
"08000002", -> Extranonce1 -> Hex-encoded, per-connection unique string which will be used for coinbase serialization later
4], -> Extranonce2_size -> Represents expected length of extranonce2 which will be generated by the miner
"error": null}
authenticate: (for each miner thread)
{"id": 2, "method": "mining.authorize", "params": ["slush.miner1", "password"]} -> miner authenticate
{"id": 2, "error": null, "result": true}
notification: new block to mine
{"id": null, "method": "mining.notify", "params": [
"bf", -> job_id
"4d16b6f85af6e2198f44ae2a6de67f78487ae5611b77c6c0440b921e00000000",
"01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff20020862062f503253482f04b8864e5008",
"072f736c7573682f000000000100f2052a010000001976a914d23fcdf86f7e756a64a7a9688ef9903327048ed988ac00000000",
[], -> merkle_branch
"00000002", -> version
"1c2ac4af", -> nbits
"504e86b9", -> ntime
false]} -> clean_jobs
job_id - ID of the job. Use this ID while submitting share generated from this job.
prevhash - Hash of previous block.
coinbase1 - Initial part of coinbase transaction.
coinbase2 - Final part of coinbase transaction.
merkle_branch - List of hashes, will be used for calculation of merkle root.
This is not a list of all transactions, it only contains prepared hashes of steps of merkle tree algorithm.
version - Bitcoin block version.
nbits - Encoded current network difficulty
ntime - Current ntime
clean_jobs - When true, server indicates that submitting shares from previous jobs don't have a sense and such shares will be rejected.
When this flag is set, miner should also drop all previous jobs, so job_ids can be eventually rotated.
notfication: change difficulty
{"id": null, "method": "mining.set_difficulty", "params": [2]}
-> This means that difficulty 2 will be applied to every next job received from the server.
submit share:
{"id": 4, "method": "mining.submit", "params": [
"slush.miner1", -> previously authorised worker name
"bf", -> job_id from a previous notification
"00000001", -> extranonce2 (size must match)
"504e86ed", -> ntime (32 bit)
"b2957c02"]} -> nonce (32 bit)
{"error": null, "id": 4, "result": true}
error codes:
20 - Other/Unknown
21 - Job not found (=stale)
22 - Duplicate share
23 - Low difficulty share
24 - Unauthorized worker
25 - Not subscribed
Package rpc provides access to the exported methods of an object across a
network or other I/O connection. A server registers an object, making it visible
as a service with the name of the type of the object. After registration, exported
methods of the object will be accessible remotely. A server may register multiple
objects (services) of different types but it is an error to register multiple
objects of the same type.
Only methods that satisfy these criteria will be made available for remote access;
other methods will be ignored:
- the method is exported.
- the method has two arguments, both exported (or builtin) types.
- the method's second argument is a pointer.
- the method has return type error.
In effect, the method must look schematically like
func (t *T) MethodName(argType T1, replyType *T2) error
where T, T1 and T2 can be marshaled by encoding/gob.
These requirements apply even if a different codec is used.
(In the future, these requirements may soften for custom codecs.)
The method's first argument represents the arguments provided by the caller; the
second argument represents the result parameters to be returned to the caller.
The method's return value, if non-nil, is passed back as a string that the client
sees as if created by errors.New. If an error is returned, the reply parameter
will not be sent back to the client.
Here is a simple example. A server wishes to export an object of type Arith:
Note: arg:"N" annotation is required because this RPC
parameter values are passsed as an array and must be
extracted from this array into the struct. Not needed for
the result type as this will be directly converted to JSON.
package server
type Args struct {
A int `arg:"0"`
B int `arg:"1"`
}
type Quotient struct {
Quo, Rem int
}
type Arith int
func (t *Arith) Multiply(args *Args, reply *int) error {
*reply = args.A * args.B
return nil
}
func (t *Arith) Divide(args *Args, quo *Quotient) error {
if args.B == 0 {
return errors.New("divide by zero")
}
quo.Quo = args.A / args.B
quo.Rem = args.A % args.B
return nil
}
The server calls:
arith := new(Arith)
rpc.Register(arith)
Index ¶
- Variables
- func Callback(conn io.ReadWriteCloser, argument interface{})
- func ConnectionCount() uint64
- func Finalise() error
- func Initialise() error
- func ServeConnection(conn io.ReadWriter, server *Server, background NotificationFunc, ...) error
- type AB
- type AuthoriseArguments
- type CC
- type Mining
- func (mining *Mining) Authorize(arguments AuthoriseArguments, reply *bool) error
- func (mining *Mining) Submit(arguments SubmitArguments, reply *bool) error
- func (mining *Mining) Subscribe(arguments SubscribeArguments, reply *SubscribeReply) error
- func (mining *Mining) T(arguments AB, reply *CC) error
- type NotificationFunc
- type Notifier
- type Server
- type ServerArgument
- type SubmitArguments
- type SubscribeArguments
- type SubscribeReply
Constants ¶
This section is empty.
Variables ¶
var ( ErrOtherUnknown = errors.New("20 - Other/Unknown") ErrJobNotFound = errors.New("21 - Job not found (=stale)") ErrNotSubscribed = errors.New("25 - Not subscribed") )
RPC error codes
Functions ¶
func ConnectionCount ¶
func ConnectionCount() uint64
func ServeConnection ¶
func ServeConnection(conn io.ReadWriter, server *Server, background NotificationFunc, argument interface{}) error
Types ¶
type AuthoriseArguments ¶
type Mining ¶
type Mining struct {
// contains filtered or unexported fields
}
type to hold Peer
func (*Mining) Authorize ¶
func (mining *Mining) Authorize(arguments AuthoriseArguments, reply *bool) error
miner log in
func (*Mining) Submit ¶
func (mining *Mining) Submit(arguments SubmitArguments, reply *bool) error
miner submit result
func (*Mining) Subscribe ¶
func (mining *Mining) Subscribe(arguments SubscribeArguments, reply *SubscribeReply) error
type NotificationFunc ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an RPC Server.
func (*Server) Register ¶
Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:
- exported method
- two arguments, both of exported type
- the second argument is a pointer
- one return value, of type error
It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.
func (*Server) RegisterName ¶
RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.
type ServerArgument ¶
the argument passed to the callback
type SubmitArguments ¶
type SubscribeArguments ¶
type SubscribeReply ¶
type SubscribeReply []interface{}