diff --git a/pool/page_payments.php b/pool/page_payments.php index 280b0a6c..15abade3 100644 --- a/pool/page_payments.php +++ b/pool/page_payments.php @@ -1,5 +1,10 @@ \n"; $pg .= ""; - $pg .= "Date"; + $pg .= "Block"; $pg .= "Address"; + $pg .= "Status"; $pg .= "BTC"; + $pg .= ""; $pg .= "\n"; if ($ans['STATUS'] == 'ok') { + $all = array(); $count = $ans['rows']; for ($i = 0; $i < $count; $i++) + { + $all[] = array('payoutid' => $ans['payoutid:'.$i], + 'height' => $ans['height:'.$i], + 'payaddress' => $ans['payaddress:'.$i], + 'amount' => $ans['amount:'.$i], + 'paydate' => $ans['paydate:'.$i]); + } + usort($all, 'sortheight'); + $hasdust = false; + for ($i = 0; $i < $count; $i++) { if (($i % 2) == 0) $row = 'even'; @@ -28,11 +46,28 @@ function dopayments($data, $user) $row = 'odd'; $pg .= ""; - $pg .= ''.$ans['paydate:'.$i].''; - $pg .= ''.$ans['payaddress:'.$i].''; - $pg .= ''.btcfmt($ans['amount:'.$i]).''; + $pg .= ''.$all[$i]['height'].''; + $pg .= ''.$all[$i]['payaddress'].''; + $pg .= ' '; + $amount = $all[$i]['amount']; + if ($amount < '10000') + { + $dust = '*'; + $hasdust = true; + } + else + $dust = ' '; + $pg .= ''.btcfmt($amount).''; + $pg .= "$dust"; $pg .= "\n"; } + if ($hasdust === true) + { + $pg .= ''; + $pg .= '* '; + $pg .= 'Dust payments are not automatically sent out'; + $pg .= ''; + } } $pg .= "\n"; diff --git a/src/ckdb.h b/src/ckdb.h index 34c91f7c..e7717ef7 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.007" +#define CKDB_VERSION DB_VERSION"-1.008" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index a9c32c77..38cebbe4 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -1092,9 +1092,11 @@ static char *cmd_payments(__maybe_unused PGconn *conn, char *cmd, char *id, __maybe_unused tv_t *notcd, __maybe_unused K_TREE *trf_root) { - K_ITEM *i_username, *u_item, *p_item; + K_ITEM *i_username, *u_item, *p_item, *p2_item, *po_item; K_TREE_CTX ctx[1]; - PAYMENTS *payments, curr; + K_STORE *pay_store; + PAYMENTS *payments, *last_payments = NULL; + PAYOUTS *payouts; USERS *users; char reply[1024] = ""; char tmp[1024]; @@ -1102,6 +1104,7 @@ static char *cmd_payments(__maybe_unused PGconn *conn, char *cmd, char *id, char *buf; size_t len, off; int rows; + bool pok; LOGDEBUG("%s(): cmd '%s'", __func__, cmd); @@ -1116,65 +1119,71 @@ static char *cmd_payments(__maybe_unused PGconn *conn, char *cmd, char *id, return strdup("bad"); DATA_USERS(users, u_item); - bzero(&curr, sizeof(curr)); APPEND_REALLOC_INIT(buf, off, len); APPEND_REALLOC(buf, off, len, "ok."); rows = 0; - - K_RLOCK(payments_free); + pay_store = k_new_store(payments_free); + K_WLOCK(payments_free); p_item = find_first_payments(users->userid, ctx); DATA_PAYMENTS_NULL(payments, p_item); /* TODO: allow to see details of a single payoutid * if it has multiple items (percent payout user) */ while (p_item && payments->userid == users->userid) { if (CURRENT(&(payments->expirydate))) { - if (curr.payoutid && curr.payoutid != payments->payoutid) { - tv_to_buf(&(curr.paydate), reply, sizeof(reply)); - snprintf(tmp, sizeof(tmp), "paydate:%d=%s%c", rows, reply, FLDSEP); - APPEND_REALLOC(buf, off, len, tmp); - - str_to_buf(curr.payaddress, reply, sizeof(reply)); - snprintf(tmp, sizeof(tmp), "payaddress:%d=%s%c", rows, reply, FLDSEP); - APPEND_REALLOC(buf, off, len, tmp); - - bigint_to_buf(curr.amount, reply, sizeof(reply)); - snprintf(tmp, sizeof(tmp), "amount:%d=%s%c", rows, reply, FLDSEP); - APPEND_REALLOC(buf, off, len, tmp); - - rows++; - bzero(&curr, sizeof(curr)); + if (!last_payments || payments->payoutid != last_payments->payoutid) { + p2_item = k_unlink_head(payments_free); + DATA_PAYMENTS_NULL(last_payments, p2_item); + memcpy(last_payments, payments, sizeof(*last_payments)); + k_add_tail(pay_store, p2_item); + } else { + STRNCPY(last_payments->payaddress, "*Multiple"); + last_payments->amount += payments->amount; } - if (!curr.payoutid) { - curr.payoutid = payments->payoutid; - copy_tv(&(curr.paydate), &(payments->paydate)); - STRNCPY(curr.payaddress, payments->payaddress); - } else - STRNCPY(curr.payaddress, "*Multiple"); - curr.amount += payments->amount; } p_item = next_in_ktree(ctx); DATA_PAYMENTS_NULL(payments, p_item); } - K_RUNLOCK(payments_free); - if (curr.payoutid) { - tv_to_buf(&(curr.paydate), reply, sizeof(reply)); - snprintf(tmp, sizeof(tmp), "paydate:%d=%s%c", rows, reply, FLDSEP); - APPEND_REALLOC(buf, off, len, tmp); + K_WUNLOCK(payments_free); + + p_item = pay_store->head; + while (p_item) { + DATA_PAYMENTS(payments, p_item); + pok = false; + K_RLOCK(payouts_free); + po_item = find_payoutid(payments->payoutid); + DATA_PAYOUTS_NULL(payouts, po_item); + if (p_item && PAYGENERATED(payouts->status)) + pok = true; + K_RUNLOCK(payouts_free); + if (pok) { + 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); - str_to_buf(curr.payaddress, reply, sizeof(reply)); - snprintf(tmp, sizeof(tmp), "payaddress:%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(curr.amount, reply, sizeof(reply)); - snprintf(tmp, sizeof(tmp), "amount:%d=%s%c", rows, reply, FLDSEP); - APPEND_REALLOC(buf, off, len, tmp); + str_to_buf(payments->payaddress, reply, sizeof(reply)); + snprintf(tmp, sizeof(tmp), "payaddress:%d=%s%c", rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); - rows++; + bigint_to_buf(payments->amount, reply, sizeof(reply)); + snprintf(tmp, sizeof(tmp), "amount:%d=%s%c", rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + + tv_to_buf(&(payments->paydate), reply, sizeof(reply)); + snprintf(tmp, sizeof(tmp), "paydate:%d=%s%c", rows, reply, FLDSEP); + APPEND_REALLOC(buf, off, len, tmp); + + rows++; + } + p_item = p_item->next; } snprintf(tmp, sizeof(tmp), "rows=%d%cflds=%s%c", rows, FLDSEP, - "paydate,payaddress,amount", FLDSEP); + "payoutid,height,payaddress,amount,paydate", FLDSEP); APPEND_REALLOC(buf, off, len, tmp); snprintf(tmp, sizeof(tmp), "arn=%s%carp=%s", "Payments", FLDSEP, "");