mine

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2016 License: ISC Imports: 27 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	ErrOtherUnknown       = errors.New("20 - Other/Unknown")
	ErrJobNotFound        = errors.New("21 - Job not found (=stale)")
	ErrDuplicateShare     = errors.New("22 - Duplicate share")
	ErrLowDifficultyShare = errors.New("23 - Low difficulty share")
	ErrUnauthorizedWorker = errors.New("24 - Unauthorized worker")
	ErrNotSubscribed      = errors.New("25 - Not subscribed")
)

RPC error codes

Functions

func Callback

func Callback(conn io.ReadWriteCloser, argument interface{})

listener callback

func ConnectionCount

func ConnectionCount() uint64

func Finalise

func Finalise() error

finialise - stop all background tasks

func Initialise

func Initialise() error

initialise the background process

func ServeConnection

func ServeConnection(conn io.ReadWriter, server *Server, background NotificationFunc, argument interface{}) error

Types

type AB

type AB struct {
	A float64 `arg:"0"`
	B float64 `arg:"1"`
}

type AuthoriseArguments

type AuthoriseArguments struct {
	Username string `arg:"0"`
	Password string `arg:"1"`
}

type CC

type CC struct {
	C float64 `json:"sum"`
}

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

func (*Mining) T

func (mining *Mining) T(arguments AB, reply *CC) error

type NotificationFunc

type NotificationFunc func(conn Notifier, stop <-chan bool, argument interface{})

type Notifier

type Notifier struct {
	io.Writer
}

func (*Notifier) Notify

func (conn *Notifier) Notify(method string, params []interface{}) error

send a notification

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents an RPC Server.

func NewServer

func NewServer() *Server

NewServer returns a new Server.

func (*Server) Call

func (server *Server) Call(ServiceMethod string, in []interface{}, out interface{}) (err error)

execute a server side call

func (*Server) Register

func (server *Server) Register(rcvr interface{}) error

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

func (server *Server) RegisterName(name string, rcvr interface{}) error

RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.

type ServerArgument

type ServerArgument struct {
	Log *logger.L
}

the argument passed to the callback

type SubmitArguments

type SubmitArguments struct {
	Username    string `arg:"0"` // miner identifier
	JobId       string `arg:"1"` // ID of the job from notification
	ExtraNonce2 string `arg:"2"` // ExtraNonce2 used by miner found by miner
	Ntime       string `arg:"3"` // Current ntime
	Nonce       string `arg:"4"` // Nonce fount by miner
}

type SubscribeArguments

type SubscribeArguments struct {
	MinerName string `arg:"0"`
	NotifyId  string `arg:"1"`
}

type SubscribeReply

type SubscribeReply []interface{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL