Documentation
¶
Overview ¶
Package stratum implements the basic stratum protocol. This is normal jsonrpc but the go standard library is insufficient since we need features like notifications.
Index ¶
- func HexStringToBytes(v interface{}) (result []byte, err error)
- type ClientConnection
- func (c *ClientConnection) Call(serviceMethod string, args []interface{}) (reply interface{}, err error)
- func (c *ClientConnection) Close()
- func (c *ClientConnection) Listen()
- func (c *ClientConnection) MiningAuthorizeHandler(m message)
- func (c *ClientConnection) MiningSubscribeHandler(m message)
- func (c *ClientConnection) Notify(serviceMethod string, args []interface{}) (err error)
- func (c *ClientConnection) Reply(ID uint64, result interface{}, errorResult []interface{}) (err error)
- func (c *ClientConnection) SendDifficulty()
- func (c *ClientConnection) SetNotificationHandler(method string, handler NotificationHandler)
- type ErrorCallback
- type ExtraNonce2
- type NotificationHandler
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HexStringToBytes ¶
HexStringToBytes converts a hex encoded string (but as go type interface{}) to a byteslice If v is no valid string or the string contains invalid characters, an error is returned
Types ¶
type ClientConnection ¶
type ClientConnection struct { ErrorCallback ErrorCallback MinerVersion string User string // contains filtered or unexported fields }
ClientConnection maintains a connection to a stratum client and (de)serializes requests/reponses/notifications
func (*ClientConnection) Call ¶
func (c *ClientConnection) Call(serviceMethod string, args []interface{}) (reply interface{}, err error)
Call invokes the named function, waits for it to complete, and returns its error status.
func (*ClientConnection) Close ¶
func (c *ClientConnection) Close()
Close releases the tcp connection
func (*ClientConnection) Listen ¶
func (c *ClientConnection) Listen()
Listen reads data from the open connection, deserializes it and dispatches the reponses and notifications This is a blocking function and will continue to listen until an error occurs (io or deserialization)
func (*ClientConnection) MiningAuthorizeHandler ¶
func (c *ClientConnection) MiningAuthorizeHandler(m message)
MiningAuthorizeHandler handles the mining.authorize request
func (*ClientConnection) MiningSubscribeHandler ¶
func (c *ClientConnection) MiningSubscribeHandler(m message)
MiningSubscribeHandler handles the mining.subscribe request
func (*ClientConnection) Notify ¶
func (c *ClientConnection) Notify(serviceMethod string, args []interface{}) (err error)
Notify sends a notification to the client
func (*ClientConnection) Reply ¶
func (c *ClientConnection) Reply(ID uint64, result interface{}, errorResult []interface{}) (err error)
func (*ClientConnection) SendDifficulty ¶
func (c *ClientConnection) SendDifficulty()
SendDifficulty sends the current difficulty to the miner
func (*ClientConnection) SetNotificationHandler ¶
func (c *ClientConnection) SetNotificationHandler(method string, handler NotificationHandler)
SetNotificationHandler registers a function to handle notification for a specific method. This function is not threadsafe and all notificationhandlers should be set prior to calling the Dial function
type ErrorCallback ¶
type ErrorCallback func(err error)
ErrorCallback is the type of function that be registered to be notified of errors requiring a client connection to be dropped and a new one to be created
type ExtraNonce2 ¶
ExtraNonce2 is the nonce modified by the miner
func (*ExtraNonce2) Bytes ¶
func (en *ExtraNonce2) Bytes() (b []byte)
Bytes is a bigendian representation of the extranonce2
func (*ExtraNonce2) Increment ¶
func (en *ExtraNonce2) Increment() (err error)
Increment increases the nonce with 1, an error is returned if the resulting is value is bigger than possible given the size
type NotificationHandler ¶
type NotificationHandler func(args []interface{})
NotificationHandler is the signature for a function that handles notifications
type Server ¶
type Server struct { ErrorCallback ErrorCallback // contains filtered or unexported fields }
Server Listens on a connection for incoming connections
func NewServer ¶
func NewServer(laddr string, shareChain *sharechain.ShareChain) (server *Server)
NewServer creates a stratum server for listening on the local network address laddr. During the Accept() call, a listening socket is created ( https://golang.org/pkg/net/#Listen ) using "tcp" as network and laddr as specified.
func (*Server) Accept ¶
Accept creates connections on the listener and serves requests for each incoming connection. Accept blocks until the underlying tcp listener returns a non-nil error or Close is called on the server. The caller typically invokes Accept in a go statement.
func (*Server) NewClientConnection ¶
func (server *Server) NewClientConnection(socket net.Conn) (c *ClientConnection)
NewClientConnection creates a new ClientConnection given a socket