Browse Source

ckdb/php pplns handle user with multiple payout addresses

master
kanoi 10 years ago
parent
commit
cf3658d881
  1. 5
      pool/page_pplns.php
  2. 2
      src/ckdb.h
  3. 63
      src/ckdb_cmd.c

5
pool/page_pplns.php

@ -42,10 +42,11 @@ function calctx($ans, $count, $miner_sat, $diffacc_total)
$payaddress = $ans['payaddress:'.$i];
if ($payaddress == 'none')
{
$len = strlen($username);
$c0 = substr($username, 0, 1);
$parts = explode('.', $username);
$len = strlen($parts[0]);
if (($c0 == '1' || $c0 == '3') && $len > 26 && $len < 37)
$payaddress = $username;
$payaddress = $parts[0];
else
{
if ($pay_sat > 0)

2
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1"
#define DB_VERSION "0.9.6"
#define CKDB_VERSION DB_VERSION"-0.742"
#define CKDB_VERSION DB_VERSION"-0.743"
#define WHERE_FFL " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__

63
src/ckdb_cmd.c

@ -3390,43 +3390,72 @@ static char *cmd_pplns(__maybe_unused PGconn *conn, char *cmd, char *id,
K_RLOCK(users_free);
u_item = find_userid(miningpayouts->userid);
K_RUNLOCK(users_free);
if (u_item) {
if (!u_item) {
snprintf(reply, siz,
"ERR.unknown userid %"PRId64,
miningpayouts->userid);
goto shazbot;
}
DATA_USERS(users, u_item);
K_ITEM *pa_item;
PAYMENTADDRESSES *pa;
char *payaddress;
int64_t paytotal;
double amount;
int count;
// TODO: handle multiple addresses for one user
K_RLOCK(paymentaddresses_free);
pa_item = find_paymentaddresses(miningpayouts->userid, pay_ctx);
if (pa_item) {
paytotal = 0;
DATA_PAYMENTADDRESSES(pa, pa_item);
payaddress = pa->payaddress;
} else
payaddress = "none";
while (pa_item && CURRENT(&(pa->expirydate)) &&
pa->userid == miningpayouts->userid) {
paytotal += pa->payratio;
pa_item = prev_in_ktree(pay_ctx);
DATA_PAYMENTADDRESSES_NULL(pa, pa_item);
}
count = 0;
pa_item = find_paymentaddresses(miningpayouts->userid, pay_ctx);
DATA_PAYMENTADDRESSES_NULL(pa, pa_item);
while (pa_item && CURRENT(&(pa->expirydate)) &&
pa->userid == miningpayouts->userid) {
amount = (double)(miningpayouts->amount) *
(double)pa->payratio / (double)paytotal;
DATA_USERS(users, u_item);
snprintf(tmp, sizeof(tmp),
"user:%d=%s%cpayaddress:%d=%s%c",
rows, users->username, FLDSEP,
rows, payaddress, FLDSEP);
"user:%d=%s.%d%cpayaddress:%d=%s%c",
rows, users->username, ++count, FLDSEP,
rows, pa->payaddress, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp),
"diffacc_user:%d=%.1f%c",
rows, amount, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
rows++;
pa_item = prev_in_ktree(pay_ctx);
DATA_PAYMENTADDRESSES_NULL(pa, pa_item);
}
K_RUNLOCK(paymentaddresses_free);
} else {
K_RUNLOCK(paymentaddresses_free);
snprintf(tmp, sizeof(tmp),
"user:%d=%"PRId64"%cpayaddress:%d=none%c",
rows, miningpayouts->userid, FLDSEP,
rows, FLDSEP);
}
"user:%d=%s.0%cpayaddress:%d=%s%c",
rows, users->username, FLDSEP,
rows, "none", FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp),
"diffacc_user:%d=%"PRId64"%c",
rows,
miningpayouts->amount,
FLDSEP);
APPEND_REALLOC(buf, off, len, tmp);
mu_item = next_in_ktree(ctx);
rows++;
}
mu_item = next_in_ktree(ctx);
}
snprintf(tmp, sizeof(tmp),
"rows=%d%cflds=%s%c",
rows, FLDSEP,

Loading…
Cancel
Save