github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/plugins/cgminer/bitmine/bitmine_bind.go (about)

     1  // This file is part of the Smart Home
     2  // Program complex distribution https://github.com/e154/smart-home
     3  // Copyright (C) 2016-2023, Filippov Alex
     4  //
     5  // This library is free software: you can redistribute it and/or
     6  // modify it under the terms of the GNU Lesser General Public
     7  // License as published by the Free Software Foundation; either
     8  // version 3 of the License, or (at your option) any later version.
     9  //
    10  // This library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13  // Library General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Lesser General Public
    16  // License along with this library.  If not, see
    17  // <https://www.gnu.org/licenses/>.
    18  
    19  package bitmine
    20  
    21  // Javascript Binding
    22  //
    23  // Miner
    24  //
    25  //		.stats() result
    26  //	 .devs() result
    27  //	 .summary() result
    28  //	 .pools() result
    29  //	 .addPool(url string) result
    30  //	 .version() result
    31  //	 .enable(poolId int64) result
    32  //	 .disable(poolId int64) result
    33  //	 .delete(poolId int64) result
    34  //	 .switchPool(poolId int64) result
    35  //	 .restart() result
    36  type BitmineBind struct {
    37  	bitmine *Bitmine
    38  }
    39  
    40  // NewBitmineBind ...
    41  func NewBitmineBind(bitmine *Bitmine) *BitmineBind {
    42  	return &BitmineBind{
    43  		bitmine: bitmine,
    44  	}
    45  }
    46  
    47  // Result ...
    48  type Result struct {
    49  	Error      bool   `json:"error"`
    50  	ErrMessage string `json:"errMessage"`
    51  	Result     string `json:"result"`
    52  }
    53  
    54  // Stats ...
    55  func (b *BitmineBind) Stats() (res Result) {
    56  	data, err := b.bitmine.Stats()
    57  	if err != nil {
    58  		res.Error = true
    59  		res.ErrMessage = err.Error()
    60  		//log.Error(err.Error())
    61  		return
    62  	}
    63  	res.Result = string(data)
    64  	return
    65  }
    66  
    67  // Devs ...
    68  func (b *BitmineBind) Devs() (res Result) {
    69  	data, err := b.bitmine.Devs()
    70  	if err != nil {
    71  		res.Error = true
    72  		res.ErrMessage = err.Error()
    73  		log.Error(err.Error())
    74  		return
    75  	}
    76  	res.Result = string(data)
    77  	return
    78  }
    79  
    80  // Summary ...
    81  func (b *BitmineBind) Summary() (res Result) {
    82  	data, err := b.bitmine.Summary()
    83  	if err != nil {
    84  		res.Error = true
    85  		res.ErrMessage = err.Error()
    86  		log.Error(err.Error())
    87  		return
    88  	}
    89  	res.Result = string(data)
    90  	return
    91  }
    92  
    93  // Pools ...
    94  func (b *BitmineBind) Pools() (res Result) {
    95  	data, err := b.bitmine.Pools()
    96  	if err != nil {
    97  		res.Error = true
    98  		res.ErrMessage = err.Error()
    99  		log.Error(err.Error())
   100  		return
   101  	}
   102  	res.Result = string(data)
   103  	return
   104  }
   105  
   106  // AddPool ...
   107  func (b *BitmineBind) AddPool(url string) (res Result) {
   108  	err := b.bitmine.AddPool(url)
   109  	if err != nil {
   110  		res.Error = true
   111  		res.ErrMessage = err.Error()
   112  		log.Error(err.Error())
   113  		return
   114  	}
   115  	return
   116  }
   117  
   118  // Version ...
   119  func (b *BitmineBind) Version() (res Result) {
   120  	data, err := b.bitmine.Version()
   121  	if err != nil {
   122  		res.Error = true
   123  		res.ErrMessage = err.Error()
   124  		log.Error(err.Error())
   125  		return
   126  	}
   127  	res.Result = string(data)
   128  	return
   129  }
   130  
   131  // Enable ...
   132  func (b *BitmineBind) Enable(poolId int64) (res Result) {
   133  	err := b.bitmine.Enable(poolId)
   134  	if err != nil {
   135  		res.Error = true
   136  		res.ErrMessage = err.Error()
   137  		log.Error(err.Error())
   138  		return
   139  	}
   140  	return
   141  }
   142  
   143  // Disable ...
   144  func (b *BitmineBind) Disable(poolId int64) (res Result) {
   145  	err := b.bitmine.Disable(poolId)
   146  	if err != nil {
   147  		res.Error = true
   148  		res.ErrMessage = err.Error()
   149  		log.Error(err.Error())
   150  		return
   151  	}
   152  	return
   153  }
   154  
   155  // Delete ...
   156  func (b *BitmineBind) Delete(poolId int64) (res Result) {
   157  	err := b.bitmine.Delete(poolId)
   158  	if err != nil {
   159  		res.Error = true
   160  		res.ErrMessage = err.Error()
   161  		log.Error(err.Error())
   162  		return
   163  	}
   164  	return
   165  }
   166  
   167  // SwitchPool ...
   168  func (b *BitmineBind) SwitchPool(poolId int64) (res Result) {
   169  	err := b.bitmine.SwitchPool(poolId)
   170  	if err != nil {
   171  		res.Error = true
   172  		res.ErrMessage = err.Error()
   173  		log.Error(err.Error())
   174  		return
   175  	}
   176  	return
   177  }
   178  
   179  // Restart ...
   180  func (b *BitmineBind) Restart() (res Result) {
   181  	err := b.bitmine.Restart()
   182  	if err != nil {
   183  		res.Error = true
   184  		res.ErrMessage = err.Error()
   185  		log.Error(err.Error())
   186  		return
   187  	}
   188  	return
   189  }