1+ // Package miners provides functionality for discovering and controlling cryptocurrency miners.
12package miners
23
34import (
@@ -15,9 +16,13 @@ import (
1516 "time"
1617)
1718
19+ // Sender is a function type for sending data over a network connection.
1820type Sender func (conn net.Conn ) error
21+
22+ // Receiver is a generic function type for receiving data over a network connection.
1923type Receiver [T any ] func (conn net.Conn ) (T , error )
2024
25+ // UnmarshalJSON implements custom JSON unmarshaling for StatsItem.
2126func (s * StatsItem ) UnmarshalJSON (data []byte ) error {
2227 var raw map [string ]string
2328 if err := json .Unmarshal (data , & raw ); err != nil {
@@ -196,7 +201,7 @@ func (s *StatsItem) UnmarshalJSON(data []byte) error {
196201 }
197202 case "PCOMM_E" :
198203 if i , err := strconv .Atoi (value ); err == nil {
199- stats .PCOMM_E = i
204+ stats .PCommE = i
200205 }
201206 case "GHSspd" :
202207 if f , err := strconv .ParseFloat (value , 64 ); err == nil {
@@ -315,6 +320,7 @@ func (s *StatsItem) UnmarshalJSON(data []byte) error {
315320 return nil
316321}
317322
323+ // Discover searches for Avalon miners on the specified network and returns a list of discovered hosts.
318324func Discover (ctx context.Context , network string ) []* AvalonQHost {
319325 hosts := make ([]* AvalonQHost , 0 )
320326 var wg sync.WaitGroup
@@ -351,6 +357,7 @@ func getAddresses(network string) iter.Seq[netip.Addr] {
351357 }
352358}
353359
360+ // Standby puts the Avalon miner into standby mode.
354361func (h * AvalonQHost ) Standby (ctx context.Context ) (string , error ) {
355362 if _ , err := h .SetWorkMode (ctx , AvalonEcoMode , true ); err != nil {
356363 return "" , err
@@ -364,6 +371,7 @@ func (h *AvalonQHost) Standby(ctx context.Context) (string, error) {
364371 )
365372}
366373
374+ // SetWorkMode sets the work mode of the Avalon miner.
367375func (h * AvalonQHost ) SetWorkMode (ctx context.Context , mode AvalonWorkMode , resetHistory bool ) (string , error ) {
368376 if resetHistory {
369377 h .ResetLiteStats ()
@@ -377,6 +385,7 @@ func (h *AvalonQHost) SetWorkMode(ctx context.Context, mode AvalonWorkMode, rese
377385 )
378386}
379387
388+ // WakeUp wakes up the Avalon miner from standby mode.
380389func (h * AvalonQHost ) WakeUp (ctx context.Context ) (string , error ) {
381390 h .ResetLiteStats ()
382391 return send (ctx , h .Address , h .Port ,
@@ -388,14 +397,15 @@ func (h *AvalonQHost) WakeUp(ctx context.Context) (string, error) {
388397 )
389398}
390399
400+ // RefreshLiteStats refreshes the lite statistics for the Avalon miner.
391401func (h * AvalonQHost ) RefreshLiteStats (ctx context.Context ) {
392402 stats , err := send (ctx , h .Address , h .Port ,
393403 func (conn net.Conn ) error {
394404 return writeCommand ("litestats" , conn )
395405 },
396406 func (conn net.Conn ) (* AvalonQLiteStats , error ) {
397407 stats := & AvalonQLiteStats {}
398- if err := readJsonResponse (conn , stats ); err != nil {
408+ if err := readJSONResponse (conn , stats ); err != nil {
399409 return nil , err
400410 }
401411 return stats , nil
@@ -417,7 +427,7 @@ func version(ctx context.Context, address string, port int) (*AvalonQVersion, er
417427 },
418428 func (conn net.Conn ) (* AvalonQVersion , error ) {
419429 v := & AvalonQVersion {}
420- if err := readJsonResponse (conn , v ); err != nil {
430+ if err := readJSONResponse (conn , v ); err != nil {
421431 return nil , err
422432 }
423433 return v , nil
@@ -465,7 +475,7 @@ func readStringResponse(conn net.Conn) (string, error) {
465475 return string (r ), nil
466476}
467477
468- func readJsonResponse (conn net.Conn , response any ) error {
478+ func readJSONResponse (conn net.Conn , response any ) error {
469479 dec := json .NewDecoder (conn )
470480 return dec .Decode (response )
471481}
0 commit comments