Browse Source

ckdb/php - a useful payments page

master
kanoi 10 years ago
parent
commit
939c17cd87
  1. 43
      pool/page_payments.php
  2. 2
      src/ckdb.h
  3. 89
      src/ckdb_cmd.c

43
pool/page_payments.php

@ -1,5 +1,10 @@
<?php <?php
# #
function sortheight($a, $b)
{
return $b['height'] - $a['height'];
}
#
function dopayments($data, $user) function dopayments($data, $user)
{ {
$bc = 'https://blockchain.info/address/'; $bc = 'https://blockchain.info/address/';
@ -13,14 +18,27 @@ function dopayments($data, $user)
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n"; $pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
$pg .= "<tr class=title>"; $pg .= "<tr class=title>";
$pg .= "<td class=dl>Date</td>"; $pg .= "<td class=dl>Block</td>";
$pg .= "<td class=dl>Address</td>"; $pg .= "<td class=dl>Address</td>";
$pg .= "<td class=dl>Status</td>";
$pg .= "<td class=dr>BTC</td>"; $pg .= "<td class=dr>BTC</td>";
$pg .= "<td class=dl></td>";
$pg .= "</tr>\n"; $pg .= "</tr>\n";
if ($ans['STATUS'] == 'ok') if ($ans['STATUS'] == 'ok')
{ {
$all = array();
$count = $ans['rows']; $count = $ans['rows'];
for ($i = 0; $i < $count; $i++) 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) if (($i % 2) == 0)
$row = 'even'; $row = 'even';
@ -28,11 +46,28 @@ function dopayments($data, $user)
$row = 'odd'; $row = 'odd';
$pg .= "<tr class=$row>"; $pg .= "<tr class=$row>";
$pg .= '<td class=dl>'.$ans['paydate:'.$i].'</td>'; $pg .= '<td class=dl>'.$all[$i]['height'].'</td>';
$pg .= '<td class=dl>'.$ans['payaddress:'.$i].'</td>'; $pg .= '<td class=dl>'.$all[$i]['payaddress'].'</td>';
$pg .= '<td class=dr>'.btcfmt($ans['amount:'.$i]).'</td>'; $pg .= '<td class=dl>&nbsp;</td>';
$amount = $all[$i]['amount'];
if ($amount < '10000')
{
$dust = '<span class=st1>*</span>';
$hasdust = true;
}
else
$dust = '&nbsp;';
$pg .= '<td class=dr>'.btcfmt($amount).'</td>';
$pg .= "<td class=dl>$dust</td>";
$pg .= "</tr>\n"; $pg .= "</tr>\n";
} }
if ($hasdust === true)
{
$pg .= '<tr><td colspan=5 class=dc>';
$pg .= '<font size=-1><span class=st1>*</span> ';
$pg .= 'Dust payments are not automatically sent out';
$pg .= '</font></td></tr>';
}
} }
$pg .= "</table>\n"; $pg .= "</table>\n";

2
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "1.0.0" #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 " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #define WHERE_FFL_HERE __FILE__, __func__, __LINE__

89
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 tv_t *notcd,
__maybe_unused K_TREE *trf_root) __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]; K_TREE_CTX ctx[1];
PAYMENTS *payments, curr; K_STORE *pay_store;
PAYMENTS *payments, *last_payments = NULL;
PAYOUTS *payouts;
USERS *users; USERS *users;
char reply[1024] = ""; char reply[1024] = "";
char tmp[1024]; char tmp[1024];
@ -1102,6 +1104,7 @@ static char *cmd_payments(__maybe_unused PGconn *conn, char *cmd, char *id,
char *buf; char *buf;
size_t len, off; size_t len, off;
int rows; int rows;
bool pok;
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); 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"); return strdup("bad");
DATA_USERS(users, u_item); DATA_USERS(users, u_item);
bzero(&curr, sizeof(curr));
APPEND_REALLOC_INIT(buf, off, len); APPEND_REALLOC_INIT(buf, off, len);
APPEND_REALLOC(buf, off, len, "ok."); APPEND_REALLOC(buf, off, len, "ok.");
rows = 0; rows = 0;
pay_store = k_new_store(payments_free);
K_RLOCK(payments_free); K_WLOCK(payments_free);
p_item = find_first_payments(users->userid, ctx); p_item = find_first_payments(users->userid, ctx);
DATA_PAYMENTS_NULL(payments, p_item); DATA_PAYMENTS_NULL(payments, p_item);
/* TODO: allow to see details of a single payoutid /* TODO: allow to see details of a single payoutid
* if it has multiple items (percent payout user) */ * if it has multiple items (percent payout user) */
while (p_item && payments->userid == users->userid) { while (p_item && payments->userid == users->userid) {
if (CURRENT(&(payments->expirydate))) { if (CURRENT(&(payments->expirydate))) {
if (curr.payoutid && curr.payoutid != payments->payoutid) { if (!last_payments || payments->payoutid != last_payments->payoutid) {
tv_to_buf(&(curr.paydate), reply, sizeof(reply)); p2_item = k_unlink_head(payments_free);
snprintf(tmp, sizeof(tmp), "paydate:%d=%s%c", rows, reply, FLDSEP); DATA_PAYMENTS_NULL(last_payments, p2_item);
APPEND_REALLOC(buf, off, len, tmp); memcpy(last_payments, payments, sizeof(*last_payments));
k_add_tail(pay_store, p2_item);
str_to_buf(curr.payaddress, reply, sizeof(reply)); } else {
snprintf(tmp, sizeof(tmp), "payaddress:%d=%s%c", rows, reply, FLDSEP); STRNCPY(last_payments->payaddress, "*Multiple");
APPEND_REALLOC(buf, off, len, tmp); last_payments->amount += payments->amount;
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 (!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); p_item = next_in_ktree(ctx);
DATA_PAYMENTS_NULL(payments, p_item); DATA_PAYMENTS_NULL(payments, p_item);
} }
K_RUNLOCK(payments_free); K_WUNLOCK(payments_free);
if (curr.payoutid) {
tv_to_buf(&(curr.paydate), reply, sizeof(reply)); p_item = pay_store->head;
snprintf(tmp, sizeof(tmp), "paydate:%d=%s%c", rows, reply, FLDSEP); while (p_item) {
APPEND_REALLOC(buf, off, len, tmp); 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)); int_to_buf(payouts->height, reply, sizeof(reply));
snprintf(tmp, sizeof(tmp), "payaddress:%d=%s%c", rows, reply, FLDSEP); snprintf(tmp, sizeof(tmp), "height:%d=%s%c", rows, reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
bigint_to_buf(curr.amount, reply, sizeof(reply)); str_to_buf(payments->payaddress, reply, sizeof(reply));
snprintf(tmp, sizeof(tmp), "amount:%d=%s%c", rows, reply, FLDSEP); snprintf(tmp, sizeof(tmp), "payaddress:%d=%s%c", rows, reply, FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); 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", snprintf(tmp, sizeof(tmp), "rows=%d%cflds=%s%c",
rows, FLDSEP, rows, FLDSEP,
"paydate,payaddress,amount", FLDSEP); "payoutid,height,payaddress,amount,paydate", FLDSEP);
APPEND_REALLOC(buf, off, len, tmp); APPEND_REALLOC(buf, off, len, tmp);
snprintf(tmp, sizeof(tmp), "arn=%s%carp=%s", "Payments", FLDSEP, ""); snprintf(tmp, sizeof(tmp), "arn=%s%carp=%s", "Payments", FLDSEP, "");

Loading…
Cancel
Save