diff --git a/pool/base.php b/pool/base.php index 1c9824f2..4a64a75e 100644 --- a/pool/base.php +++ b/pool/base.php @@ -63,6 +63,26 @@ function howlongago($sec) return $des; } # +function howmanyhrs($sec) +{ + if ($sec < 60) + $des = $sec.'s'; + else + { + $min = floor($sec / 60); + $sec -= $min * 60; + if ($min < 60) + $des = $min.'m '.$sec.'s'; + else + { + $hr = floor($min / 60); + $min -= $hr * 60; + $des = $hr.'hr '.$min.'m '.$sec.'s'; + } + } + return $des; +} +# function btcfmt($amt) { $amt /= 100000000; diff --git a/pool/db.php b/pool/db.php index 7002d0d5..cd9d347c 100644 --- a/pool/db.php +++ b/pool/db.php @@ -258,6 +258,18 @@ function getPayments($user) return repDecode($rep); } # +function getMPayouts($user) +{ + if ($user == false) + showIndex(); + $flds = array('username' => $user); + $msg = msgEncode('mpayouts', 'mp', $flds, $user); + $rep = sendsockreply('getMPayments', $msg); + if (!$rep) + dbdown(); + return repDecode($rep); +} +# function getBlocks($user) { if ($user == false) diff --git a/pool/prime.php b/pool/prime.php index 0cfe79af..56973cda 100644 --- a/pool/prime.php +++ b/pool/prime.php @@ -67,6 +67,7 @@ function check() 'Home' => '' ), 'Account' => array( + 'MPayouts' => 'mpayouts', 'Payments' => 'payments', 'Settings' => 'settings', 'User Settings' => 'userset' diff --git a/src/ckdb.c b/src/ckdb.c index 23e88ba7..2c8d44c3 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -2664,6 +2664,7 @@ static void *socketer(__maybe_unused void *arg) case CMD_PPLNS: case CMD_PPLNS2: case CMD_PAYOUTS: + case CMD_MPAYOUTS: case CMD_DSP: case CMD_BLOCKSTATUS: if (!startup_complete) { @@ -2883,6 +2884,7 @@ static bool reload_line(PGconn *conn, char *filename, uint64_t count, char *buf) case CMD_PPLNS: case CMD_PPLNS2: case CMD_PAYOUTS: + case CMD_MPAYOUTS: case CMD_USERSTATUS: case CMD_MARKS: LOGERR("%s() Message line %"PRIu64" '%s' - invalid - ignored", diff --git a/src/ckdb.h b/src/ckdb.h index f9d554b5..35de904e 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -52,7 +52,7 @@ #define DB_VLOCK "1" #define DB_VERSION "1.0.0" -#define CKDB_VERSION DB_VERSION"-1.009" +#define CKDB_VERSION DB_VERSION"-1.010" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -342,6 +342,7 @@ enum cmd_values { CMD_PPLNS, CMD_PPLNS2, CMD_PAYOUTS, + CMD_MPAYOUTS, CMD_USERSTATUS, CMD_MARKS, CMD_END diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 16c6de30..31659147 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -4271,6 +4271,122 @@ static char *cmd_payouts(PGconn *conn, char *cmd, char *id, tv_t *now, LOGWARNING("%s.%s", id, reply); return strdup(reply); } + +static char *cmd_mpayouts(__maybe_unused PGconn *conn, char *cmd, char *id, + __maybe_unused tv_t *now, __maybe_unused char *by, + __maybe_unused char *code, __maybe_unused char *inet, + __maybe_unused tv_t *notcd, + __maybe_unused K_TREE *trf_root) +{ + K_ITEM *i_username, *u_item, *mp_item, *po_item; + K_TREE_CTX ctx[1]; + MININGPAYOUTS *mp; + PAYOUTS *payouts; + USERS *users; + char reply[1024] = ""; + char tmp[1024]; + size_t siz = sizeof(reply); + char *buf; + size_t len, off; + int rows; + + LOGDEBUG("%s(): cmd '%s'", __func__, cmd); + + i_username = require_name(trf_root, "username", 3, (char *)userpatt, reply, siz); + if (!i_username) + return strdup(reply); + + K_RLOCK(users_free); + u_item = find_users(transfer_data(i_username)); + K_RUNLOCK(users_free); + if (!u_item) + return strdup("bad"); + DATA_USERS(users, u_item); + + APPEND_REALLOC_INIT(buf, off, len); + APPEND_REALLOC(buf, off, len, "ok."); + rows = 0; + K_RLOCK(payouts_free); + po_item = last_in_ktree(payouts_root, ctx); + DATA_PAYOUTS_NULL(payouts, po_item); + /* TODO: allow to see details of a single payoutid + * if it has multiple items (percent payout user) */ + while (po_item) { + if (CURRENT(&(payouts->expirydate)) && + PAYGENERATED(payouts->status)) { + // Not locked ... for now + mp_item = find_miningpayouts(payouts->payoutid, + users->userid); + if (mp_item) { + DATA_MININGPAYOUTS(mp, mp_item); + + bigint_to_buf(payouts->payoutid, reply, + sizeof(reply)); + snprintf(tmp, sizeof(tmp), "payoutid:%d=%s%c", + rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + + int_to_buf(payouts->height, reply, + sizeof(reply)); + snprintf(tmp, sizeof(tmp), "height:%d=%s%c", + rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + + bigint_to_buf(payouts->elapsed, reply, + sizeof(reply)); + snprintf(tmp, sizeof(tmp), "elapsed:%d=%s%c", + rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + + bigint_to_buf(mp->amount, reply, sizeof(reply)); + snprintf(tmp, sizeof(tmp), "amount:%d=%s%c", + rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + + double_to_buf(mp->diffacc, reply, sizeof(reply)); + snprintf(tmp, sizeof(tmp), "diffacc:%d=%s%c", + rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + + bigint_to_buf(payouts->minerreward, reply, + sizeof(reply)); + snprintf(tmp, sizeof(tmp), "minerreward:%d=%s%c", + rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + + double_to_buf(payouts->diffused, reply, + sizeof(reply)); + snprintf(tmp, sizeof(tmp), "diffused:%d=%s%c", + rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + + str_to_buf(payouts->status, reply, + sizeof(reply)); + snprintf(tmp, sizeof(tmp), "status:%d=%s%c", + rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + + rows++; + } + } + po_item = prev_in_ktree(ctx); + DATA_PAYOUTS_NULL(payouts, po_item); + } + K_RUNLOCK(miningpayouts_free); + + snprintf(tmp, sizeof(tmp), "rows=%d%cflds=%s%c", + rows, FLDSEP, + "payoutid,height,elapsed,amount,diffacc,minerreward,diffused,status", + FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + + snprintf(tmp, sizeof(tmp), "arn=%s%carp=%s", "MiningPayouts", FLDSEP, ""); + APPEND_REALLOC(buf, off, len, tmp); + + LOGDEBUG("%s.ok.%s", id, transfer_data(i_username)); + return buf; +} + static char *cmd_dsp(__maybe_unused PGconn *conn, __maybe_unused char *cmd, char *id, __maybe_unused tv_t *now, __maybe_unused char *by, __maybe_unused char *code, @@ -4932,6 +5048,7 @@ struct CMDS ckdb_cmds[] = { { CMD_PPLNS, "pplns", false, false, cmd_pplns, ACCESS_SYSTEM ACCESS_WEB }, { CMD_PPLNS2, "pplns2", false, false, cmd_pplns2, ACCESS_SYSTEM ACCESS_WEB }, { CMD_PAYOUTS, "payouts", false, false, cmd_payouts, ACCESS_SYSTEM }, + { CMD_MPAYOUTS, "mpayouts", false, false, cmd_mpayouts, ACCESS_SYSTEM ACCESS_WEB }, { CMD_USERSTATUS,"userstatus", false, false, cmd_userstatus, ACCESS_SYSTEM ACCESS_WEB }, { CMD_MARKS, "marks", false, false, cmd_marks, ACCESS_SYSTEM }, { CMD_END, NULL, false, false, NULL, NULL }