gitlab.com/SiaPrime/SiaPrime@v1.4.1/types/stratum.go (about)

     1  package types
     2  
     3  //ExtraNonce2 is the nonce modified by the miner
     4  type ExtraNonce2 struct {
     5  	Value uint64
     6  	Size  uint
     7  }
     8  
     9  //Bytes is a bigendian representation of the extranonce2
    10  func (en *ExtraNonce2) Bytes() (b []byte) {
    11  	b = make([]byte, en.Size, en.Size)
    12  	for i := uint(0); i < en.Size; i++ {
    13  		b[(en.Size-1)-i] = byte(en.Value >> (i * 8))
    14  	}
    15  	return
    16  }
    17  
    18  //Increment increases the nonce with 1, an error is returned if the resulting is value is bigger than possible given the size
    19  func (en *ExtraNonce2) Increment() (err error) {
    20  	en.Value++
    21  	//TODO: check if does not overflow compared to the allowed size
    22  	return
    23  }
    24  
    25  // StratumRequest contains stratum request messages received over TCP
    26  // request : A remote method is invoked by sending a request to the remote stratum service.
    27  type StratumRequest struct {
    28  	ID     uint64        `json:"id"`
    29  	Method string        `json:"method"`
    30  	Params []interface{} `json:"params"`
    31  }
    32  
    33  // StratumResponse contains stratum response messages sent over TCP
    34  // notification is an inline struct to easily decode messages in a response/notification
    35  // using a json marshaller
    36  type StratumResponse struct {
    37  	ID                  uint64        `json:"id"`
    38  	Result              interface{}   `json:"result"`
    39  	Error               []interface{} `json:"error"`
    40  	StratumNotification `json:",inline"`
    41  }
    42  
    43  // StratumNotification is a special kind of Request, it has no ID and is sent from the server
    44  // to the client
    45  type StratumNotification struct {
    46  	Method string        `json:"method"`
    47  	Params []interface{} `json:"params"`
    48  }