Exemplo n.º 1
0
// QueryStatus is a StringItemHandlerFunc for key `mrr.status` which returns the status
// of a rentals.
func QueryStatus(request []string) (string, error) {
	// parse first param as int64
	rentalid, err := strconv.ParseInt(request[2], 10, 64)
	if err != nil {
		return "na", errors.New("Invalid rentalid format")
	}
	lock := filemutex.MakeFileMutex(filepath.Join(os.TempDir(), "mrr-"+request[0]))
	lock.Lock()
	defer lock.Unlock()
	client := miningrigrentals.New(request[0], request[1])
	rentals, err := client.GetRentalDetails(rentalid)
	if err != nil {
		return "na", err
	}
	return rentals.Status, nil
}
Exemplo n.º 2
0
// DiscoverRentals is a DiscoveryItemHandlerFunc for key `mrr.discovery` which returns JSON
// encoded discovery data for all rentals
func DiscoverRentals(request []string) (lld.DiscoveryData, error) {
	// init discovery data
	d := make(lld.DiscoveryData, 0)
	lock := filemutex.MakeFileMutex(filepath.Join(os.TempDir(), "mrr-"+request[0]))
	lock.Lock()
	defer lock.Unlock()
	client := miningrigrentals.New(request[0], request[1])
	rentals, err := client.ListMyRentals()
	if err != nil {
		return nil, err
	}
	for _, rent := range rentals {
		item := make(lld.DiscoveryItem, 0)
		item["ID"] = strconv.FormatInt(int64(rent.Id), 10)
		item["TYPE"] = rent.Type
		item["NAME"] = rent.Name
		d = append(d, item)
	}
	return d, nil
}
Exemplo n.º 3
0
// QuerySpeed is a DoubleItemHandlerFunc for key `mrr.speedpercent` which returns the speed percentage
// for a rentals.
func QuerySpeed(request []string) (float64, error) {
	// parse first param as int64
	rentalid, err := strconv.ParseInt(request[2], 10, 64)
	if err != nil {
		return 0.00, errors.New("Invalid rentalid format")
	}
	lock := filemutex.MakeFileMutex(filepath.Join(os.TempDir(), "mrr-"+request[0]))
	lock.Lock()
	defer lock.Unlock()
	client := miningrigrentals.New(request[0], request[1])
	rentals, err := client.GetRentalDetails(rentalid)
	if err != nil {
		return 0.00, err
	}
	var speedpercent float64
	if speedpercent = 0.00; rentals.HashRate.HashRate5m > 0 {
		speedpercent = 100.0 * float64(rentals.HashRate.Advertised) / rentals.HashRate.HashRate5m
	}
	//	fmt.Printf("%T %+v\n", rentals, rentals)
	return speedpercent, nil
}