Skip to content

Commit

Permalink
Added initial CryptoDredge implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gertjaap committed Jul 10, 2019
1 parent 32316c4 commit 414ea1a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
72 changes: 72 additions & 0 deletions miners/cryptodredge.go
Original file line number Diff line number Diff line change
@@ -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}
}
2 changes: 2 additions & 0 deletions miners/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 414ea1a

Please sign in to comment.