mirror of
https://github.com/cryptonote-social/csminer.git
synced 2024-09-11 05:35:23 +03:00
empty strings instead of nulls
This commit is contained in:
parent
f56eae1134
commit
1f645f1280
@ -8,22 +8,22 @@
|
||||
typedef struct pool_login_args {
|
||||
// username: a properly formatted pool username.
|
||||
const char* username;
|
||||
// rigid: a properly formatted rig id, or null if no rigid is specified by the user.
|
||||
// rigid: a properly formatted rig id, or empty string if no rigid is specified by the user.
|
||||
const char* rigid;
|
||||
// wallet: a properly formatted wallet address; can be null for username-only logins. If wallet is
|
||||
// null, pool server will return a warning if the username has not previously been
|
||||
// wallet: a properly formatted wallet address; can be empty for username-only logins. If wallet is
|
||||
// empty string, pool server will return a warning if the username has not previously been
|
||||
// associated with a wallet.
|
||||
const char* wallet;
|
||||
// agent: a string that informs the pool server of the miner client details, e.g. name and version
|
||||
// of the software using this API.
|
||||
const char* agent;
|
||||
// config: advanced options config string, can be null.
|
||||
// config: advanced options config string, can be empty string
|
||||
const char* config;
|
||||
} pool_login_args;
|
||||
|
||||
|
||||
typedef struct pool_login_response {
|
||||
// code = 1: login successful; if message is non-null, it's a warning/info message from pool
|
||||
// code = 1: login successful; if message is non-empty, it's a warning/info message from pool
|
||||
// server that should be shown to the user
|
||||
//
|
||||
// code < 0: login unsuccessful; couldn't reach pool server. Caller should retry later. message
|
||||
@ -40,18 +40,13 @@ typedef struct pool_login_response {
|
||||
pool_login_response pool_login(const pool_login_args *args) {
|
||||
struct PoolLogin_return r;
|
||||
r = PoolLogin((char*)args->username,
|
||||
args->rigid == NULL ? "" : (char*)args->rigid,
|
||||
args->wallet == NULL ? "" : (char*)args->wallet,
|
||||
(char*)args->rigid,
|
||||
(char*)args->wallet,
|
||||
(char*)args->agent,
|
||||
args->config == NULL ? "" : (char*)args->config);
|
||||
(char*)args->config);
|
||||
pool_login_response response;
|
||||
response.code = (int)r.r0;
|
||||
if (strlen(r.r1) > 0) {
|
||||
response.message = r.r1;
|
||||
} else {
|
||||
free((void*)r.r1);
|
||||
response.message = NULL;
|
||||
}
|
||||
response.message = r.r1;
|
||||
return response;
|
||||
}
|
||||
|
||||
@ -87,12 +82,7 @@ init_miner_response init_miner(const init_miner_args *args) {
|
||||
InitMiner((GoInt)args->threads, (GoInt)args->exclude_hour_start, (GoInt)args->exclude_hour_end);
|
||||
init_miner_response response;
|
||||
response.code = (int)r.r0;
|
||||
if (strlen(r.r1) > 0) {
|
||||
response.message = r.r1;
|
||||
} else {
|
||||
free((void*)r.r1);
|
||||
response.message = NULL;
|
||||
}
|
||||
response.message = r.r1;
|
||||
return response;
|
||||
}
|
||||
|
||||
@ -132,8 +122,8 @@ typedef struct get_miner_state_response {
|
||||
|
||||
// username of the miner whose pool stats appear below. Small chance this username may not match
|
||||
// the currently logged in user if a new login recently took place, so always check the username
|
||||
// matches before displaying the stats below. This value may be null (no user currently logged in)
|
||||
// in which case stats below should be ignored.
|
||||
// matches before displaying the stats below. This value may be empty string (no user currently
|
||||
// logged in) in which case stats below should be ignored.
|
||||
//
|
||||
// NOTE: you must free() username
|
||||
const char* username;
|
||||
@ -164,15 +154,8 @@ get_miner_state_response get_miner_state() {
|
||||
response.mining_activity = (int)r.r0;
|
||||
response.threads = (int)r.r1;
|
||||
response.recent_hashrate = (float)r.r2;
|
||||
if (strlen(r.r3) > 0) {
|
||||
response.username = r.r3;
|
||||
response.time_to_reward = r.r9;
|
||||
} else {
|
||||
response.username = NULL;
|
||||
response.time_to_reward = NULL;
|
||||
free((void*)r.r3);
|
||||
free((void*)r.r9);
|
||||
}
|
||||
response.username = r.r3;
|
||||
response.time_to_reward = r.r9;
|
||||
response.seconds_old = (int)r.r4;
|
||||
response.lifetime_hashes = (long)r.r5;
|
||||
response.paid = (float)r.r6;
|
||||
|
12
miner.go
12
miner.go
@ -152,12 +152,10 @@ func printStats() {
|
||||
msg := getActivityMessage(s.MiningActivity)
|
||||
crylog.Info("")
|
||||
crylog.Info("===============================================================================")
|
||||
crylog.Info("Mining", msg)
|
||||
crylog.Info("===============================================================================")
|
||||
if s.RecentHashrate < 0 {
|
||||
crylog.Info("Recent Hashrate : --calculating--")
|
||||
crylog.Info("Current Hashrate : --calculating--")
|
||||
} else {
|
||||
crylog.Info("Recent Hashrate :", strconv.FormatFloat(s.RecentHashrate, 'f', 2, 64))
|
||||
crylog.Info("Current Hashrate :", strconv.FormatFloat(s.RecentHashrate, 'f', 2, 64))
|
||||
}
|
||||
crylog.Info("Hashrate since inception :", strconv.FormatFloat(s.Hashrate, 'f', 2, 64))
|
||||
crylog.Info("Threads :", s.Threads)
|
||||
@ -170,11 +168,15 @@ func printStats() {
|
||||
crylog.Info("Last pool stats refresh :", s.SecondsOld, "seconds ago")
|
||||
crylog.Info(" Lifetime hashes :", prettyInt(s.LifetimeHashes))
|
||||
crylog.Info(" Paid :", strconv.FormatFloat(s.Paid, 'f', 12, 64), "$XMR")
|
||||
crylog.Info(" Owed :", strconv.FormatFloat(s.Owed, 'f', 12, 64), "$XMR")
|
||||
if s.Owed > 0.0 {
|
||||
crylog.Info(" Owed :", strconv.FormatFloat(s.Owed, 'f', 12, 64), "$XMR")
|
||||
}
|
||||
crylog.Info(" Time to next reward (est.) :", s.TimeToReward)
|
||||
crylog.Info(" Accumulated (est.) :", strconv.FormatFloat(s.Accumulated, 'f', 12, 64), "$XMR")
|
||||
crylog.Info("===============================================================================")
|
||||
}
|
||||
crylog.Info("Mining", msg)
|
||||
crylog.Info("===============================================================================")
|
||||
crylog.Info("")
|
||||
}
|
||||
|
||||
|
@ -154,14 +154,17 @@ func getMiningActivityState() int {
|
||||
// Called by the user to log into the pool for the first time, or re-log into the pool with new
|
||||
// credentials.
|
||||
func PoolLogin(args *PoolLoginArgs) *PoolLoginResponse {
|
||||
crylog.Info("Pool login called")
|
||||
doneChanMutex.Lock()
|
||||
defer doneChanMutex.Unlock()
|
||||
if miningLoopDoneChan != nil {
|
||||
crylog.Info("Pool login: shutting down previous mining loop")
|
||||
// trigger close of previous mining loop
|
||||
pokeJobDispatcher(EXIT_LOOP_POKE)
|
||||
// wait until previous mining loop completes
|
||||
<-miningLoopDoneChan
|
||||
miningLoopDoneChan = nil
|
||||
crylog.Info("Pool login: Previous loop done")
|
||||
}
|
||||
|
||||
configMutex.Lock()
|
||||
@ -181,6 +184,7 @@ func PoolLogin(args *PoolLoginArgs) *PoolLoginResponse {
|
||||
config := args.Config
|
||||
rigid := args.RigID
|
||||
|
||||
crylog.Info("Pool login: Connecting to pool server")
|
||||
err, code, message, jc := cl.Connect("cryptonote.social:5555", args.UseTLS, agent, loginName, config, rigid)
|
||||
if err != nil {
|
||||
if code != 0 {
|
||||
@ -216,6 +220,7 @@ func PoolLogin(args *PoolLoginArgs) *PoolLoginResponse {
|
||||
go stats.RefreshPoolStats(plArgs.Username)
|
||||
miningLoopDoneChan = make(chan bool, 1)
|
||||
go MiningLoop(jc)
|
||||
crylog.Info("Successful login:", plArgs.Username)
|
||||
return r
|
||||
}
|
||||
|
||||
@ -462,6 +467,7 @@ func GetMiningState() *GetMiningStateResponse {
|
||||
s.PoolUsername = ""
|
||||
s.SecondsOld = -1.0
|
||||
} else if plArgs.Username != s.PoolUsername {
|
||||
// Pool stats do not (yet) reflect the currently logged in user, so tag them as invalid.
|
||||
s.PoolUsername = plArgs.Username
|
||||
s.SecondsOld = -1.0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user