csminer/csminer.go

135 lines
4.9 KiB
Go
Raw Normal View History

2020-06-20 01:21:08 +03:00
// Copyright 2020 cryptonote.social. All rights reserved. Use of this source code is governed by
// the license found in the LICENSE file.
package csminer
import (
"flag"
"fmt"
"github.com/cryptonote-social/csminer/crylog"
"strconv"
"strings"
)
const (
APPLICATION_NAME = "cryptonote.social Monero miner"
2020-12-25 03:49:37 +03:00
VERSION_STRING = "0.3.0"
2020-06-20 01:21:08 +03:00
STATS_WEBPAGE = "https://cryptonote.social/xmr"
DONATE_USERNAME = "donate-getmonero-org"
INVALID_EXCLUDE_FORMAT_MESSAGE = "invalid format for exclude specified. Specify XX-YY, e.g. 11-16 for 11:00am to 4:00pm."
)
var (
saver = flag.Bool("saver", true, "run only when screen is locked")
t = flag.Int("threads", 1, "number of threads")
uname = flag.String("user", DONATE_USERNAME, "your pool username from https://cryptonote.social/xmr")
rigid = flag.String("rigid", "csminer", "your rig id")
tls = flag.Bool("tls", false, "whether to use TLS when connecting to the pool")
exclude = flag.String("exclude", "", "pause mining during these hours, e.g. -exclude=11-16 will pause mining between 11am and 4pm")
config = flag.String("config", "", "advanced pool configuration options, e.g. start_diff=1000;donate=1.0")
wallet = flag.String("wallet", "", "your wallet id. only specify this when establishing a new username, or specifying a 'secure' config change such as a change in donation amount")
2020-06-20 01:21:08 +03:00
)
2020-08-21 06:13:30 +03:00
func MultiMain(s MachineStater, agent string) {
2020-06-20 01:21:08 +03:00
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "==== %s %s ====\n", APPLICATION_NAME, VERSION_STRING)
fmt.Fprint(flag.CommandLine.Output(),
`Usage of ./csminer
-user <string>
your pool username from https://cryptonote.social/xmr (default "donate-getmonero-org")
-saver=<bool>
2020-06-20 01:21:08 +03:00
mine only when screen is locked (default true)
-exclude <string>
pause mining during the specified hours. Format is XX-YY where XX and YY are hours of
the day designated in 24 hour time. For example, -exclude=11-16 will pause mining betwen
11:00am and 4:00pm. This can be used, for example, to pause mining during times of high
machine usage or high electricity rates.
-threads <int>
number of threads (default 1)
-rigid <string>
your rig id (default "csminer")
-tls <bool>
whether to use TLS when connecting to the pool (default false)
-config <string>
advanced pool config option string, for specifying starting diff, donation percentage,
email address for notifications, and more. See "advanced configuration options" under Get
Started on the pool site for details. Some options will require you to also specify your
wallet id (see below) in order to be changed.
-wallet <string>
your wallet id. You only need to specify this when establishing a new username, or if
specifying a 'secure' config parameter change such as a new pool donation amount or email
address. New usernames will be established upon submitting at least one valid share.
2020-06-20 01:21:08 +03:00
`)
fmt.Fprintf(flag.CommandLine.Output(), "\nMonitor your miner progress at: %s\n", STATS_WEBPAGE)
fmt.Fprint(flag.CommandLine.Output(), "Send feedback to: cryptonote.social@gmail.com\n")
}
flag.Parse()
var hr1, hr2 int
hr1 = -1
var err error
if len(*exclude) > 0 {
hrs := strings.Split(*exclude, "-")
if len(hrs) != 2 {
crylog.Fatal(INVALID_EXCLUDE_FORMAT_MESSAGE)
2020-06-20 01:21:08 +03:00
return
}
hr1, err = strconv.Atoi(hrs[0])
if err != nil {
crylog.Fatal(INVALID_EXCLUDE_FORMAT_MESSAGE, err)
2020-06-20 01:21:08 +03:00
return
}
hr2, err = strconv.Atoi(hrs[1])
if err != nil {
crylog.Fatal(INVALID_EXCLUDE_FORMAT_MESSAGE, err)
2020-06-20 01:21:08 +03:00
return
}
if hr1 > 24 || hr1 < 0 || hr2 > 24 || hr2 < 0 {
crylog.Fatal("INVALID_EXCLUDE_FORMAT_MESSAGE", ": XX and YY must each be between 0 and 24")
2020-06-20 01:21:08 +03:00
return
}
}
fmt.Printf("==== %s v%s ====\n", APPLICATION_NAME, VERSION_STRING)
if *uname == DONATE_USERNAME {
fmt.Printf("\nNo username specified, mining on behalf of donate.getmonero.org.\n")
}
if *saver {
fmt.Printf("\nNOTE: Mining only when screen is locked. Specify -saver=false to mine always.\n")
}
if *t == 1 {
2020-06-20 01:21:08 +03:00
fmt.Printf("\nMining with only one thread. Specify -threads=X to use more.\n")
fmt.Printf("Or use the [i] keyboard command to add threads dynamically.\n")
2020-06-20 01:21:08 +03:00
}
if hr1 != -1 {
fmt.Printf("\nMining will be paused between the hours of %v:00 and %v:00.\n", hr1, hr2)
}
fmt.Printf("\nMonitor your mining progress at: %s\n", STATS_WEBPAGE)
fmt.Printf("\nSend feedback to: cryptonote.social@gmail.com\n")
fmt.Println("\n==== Status/Debug output follows ====")
crylog.Info("Miner username:", *uname)
crylog.Info("Threads:", *t)
2020-06-20 01:21:08 +03:00
2020-08-17 02:31:54 +03:00
if hr1 == -1 || hr2 == -1 {
hr1 = 0
hr2 = 0
}
config := MinerConfig{
2020-08-21 06:13:30 +03:00
MachineStater: s,
Threads: *t,
Username: *uname,
RigID: *rigid,
Wallet: *wallet,
Agent: agent,
Saver: *saver,
ExcludeHrStart: hr1,
ExcludeHrEnd: hr2,
UseTLS: *tls,
AdvancedConfig: *config,
}
2020-08-17 02:31:54 +03:00
if err = Mine(&config); err != nil {
crylog.Fatal("Miner failed:", err)
2020-06-20 01:21:08 +03:00
}
}