diff --git a/miners/cryptodredge.go b/miners/cryptodredge.go new file mode 100644 index 00000000..030973ac --- /dev/null +++ b/miners/cryptodredge.go @@ -0,0 +1,72 @@ +package miners + +import ( + "strconv" + "strings" + + "github.com/vertcoin-project/one-click-miner-vnext/logging" +) + +// Compile time assertion on interface +var _ MinerImpl = &CryptoDredgeMinerImpl{} + +type CryptoDredgeMinerImpl struct { + binaryRunner *BinaryRunner + hashRates map[int64]uint64 +} + +func NewCryptoDredgeMinerImpl(br *BinaryRunner) MinerImpl { + return &CryptoDredgeMinerImpl{binaryRunner: br, hashRates: map[int64]uint64{}} +} + +func (l *CryptoDredgeMinerImpl) Configure(args BinaryArguments) error { + return nil +} + +func (l *CryptoDredgeMinerImpl) ParseOutput(line string) { + if l.binaryRunner.Debug { + logging.Debugf("[cryptodredge] %s\n", line) + } + line = strings.TrimSpace(line) + + if strings.Contains(line, "GPU #") && strings.HasSuffix(line, "H/s") { + startDeviceIdx := strings.Index(line, "GPU #") + endDeviceIdx := strings.Index(line[startDeviceIdx:], ":") + deviceIdxString := line[startDeviceIdx+5 : startDeviceIdx+endDeviceIdx] + deviceIdx, err := strconv.ParseInt(deviceIdxString, 10, 64) + if err != nil { + return + } + + startMHs := strings.LastIndex(line, ", ") + if startMHs > -1 { + hashRateUnit := strings.ToUpper(line[len(line)-4 : len(line)-3]) + line = line[startMHs+2 : len(line)-5] + f, err := strconv.ParseFloat(line, 64) + if err != nil { + logging.Errorf("Error parsing hashrate: %s\n", err.Error()) + } + if hashRateUnit == "K" { + f = f * 1000 + } else if hashRateUnit == "M" { + f = f * 1000 * 1000 + } else if hashRateUnit == "G" { + f = f * 1000 * 1000 * 1000 + } + + l.hashRates[deviceIdx] = uint64(f) + } + } +} + +func (l *CryptoDredgeMinerImpl) HashRate() uint64 { + totalHash := uint64(0) + for _, h := range l.hashRates { + totalHash += h + } + return totalHash +} + +func (l *CryptoDredgeMinerImpl) ConstructCommandlineArgs(args BinaryArguments) []string { + return []string{"--intensity", "5", "--no-color", "-a", "lyra2v3", "-o", args.StratumUrl, "-u", args.StratumUsername, "-p", args.StratumPassword} +} diff --git a/miners/miners.go b/miners/miners.go index a7d0c0b4..7ac8643e 100644 --- a/miners/miners.go +++ b/miners/miners.go @@ -58,6 +58,8 @@ func NewBinaryRunner(m MinerBinary) (*BinaryRunner, error) { br.MinerImpl = NewCCMinerImpl(br) } else if strings.HasPrefix(m.MainExecutableName, "teamred") { br.MinerImpl = NewTeamRedMinerImpl(br) + } else if strings.HasPrefix(m.MainExecutableName, "Cryptodredge") { + br.MinerImpl = NewCryptoDredgeMinerImpl(br) } else { return nil, fmt.Errorf("Could not determine implementation for miner binary") }