Browse Source

ckdb - keep address history for txn payment processing

master
kanoi 10 years ago
parent
commit
cd0facf0e9
  1. 2
      src/ckdb.h
  2. 1
      src/ckdb_data.c
  3. 29
      src/ckdb_dbio.c

2
src/ckdb.h

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

1
src/ckdb_data.c

@ -1040,6 +1040,7 @@ cmp_t cmp_paymentaddresses(K_ITEM *a, K_ITEM *b)
return c;
}
// Only one for now ...
K_ITEM *find_paymentaddresses(int64_t userid)
{
PAYMENTADDRESSES paymentaddresses, *pa;

29
src/ckdb_dbio.c

@ -1424,7 +1424,9 @@ bool workers_fill(PGconn *conn)
return ok;
}
// Whatever the current paymentaddresses are, replace them with this one
/* Whatever the current paymentaddresses are, replace them with this one
* Code allows for zero, one or more current payment address
* even though there currently can only be zero or one */
K_ITEM *paymentaddresses_set(PGconn *conn, int64_t userid, char *payaddress,
char *by, char *code, char *inet, tv_t *cd,
K_TREE *trf_root)
@ -1529,12 +1531,13 @@ unitem:
if (!ok)
k_add_head(paymentaddresses_free, item);
else {
// Remove from ram, old (unneeded) records
// Change the expiry on all the old ones
pa.userid = userid;
pa.expirydate.tv_sec = DATE_S_EOT;
pa.payaddress[0] = '\0';
INIT_PAYMENTADDRESSES(&look);
look.data = (void *)(&pa);
// Tree order is expirydate desc
old = find_after_in_ktree(paymentaddresses_root, &look,
cmp_paymentaddresses, ctx);
while (old) {
@ -1543,9 +1546,15 @@ unitem:
if (thispa->userid != userid)
break;
old = next_in_ktree(ctx);
paymentaddresses_root = remove_from_ktree(paymentaddresses_root, this,
cmp_paymentaddresses, ctx2);
k_add_head(paymentaddresses_free, this);
/* Tree remove+add below doesn't matter since
* this test will avoid reprocessing */
if (CURRENT(&(thispa->expirydate))) {
paymentaddresses_root = remove_from_ktree(paymentaddresses_root, this,
cmp_paymentaddresses, ctx2);
copy_tv(&(thispa->expirydate), cd);
paymentaddresses_root = add_to_ktree(paymentaddresses_root, this,
cmp_paymentaddresses);
}
}
paymentaddresses_root = add_to_ktree(paymentaddresses_root, item,
cmp_paymentaddresses);
@ -1565,8 +1574,7 @@ bool paymentaddresses_fill(PGconn *conn)
PGresult *res;
K_ITEM *item;
PAYMENTADDRESSES *row;
char *params[1];
int n, i, par = 0;
int n, i;
char *field;
char *sel;
int fields = 4;
@ -1577,11 +1585,8 @@ bool paymentaddresses_fill(PGconn *conn)
sel = "select "
"paymentaddressid,userid,payaddress,payratio"
HISTORYDATECONTROL
" from paymentaddresses where expirydate=$1";
par = 0;
params[par++] = tv_to_buf((tv_t *)(&default_expiry), NULL, 0);
PARCHK(par, params);
res = PQexecParams(conn, sel, par, NULL, (const char **)params, NULL, NULL, 0, CKPQ_READ);
" from paymentaddresses";
res = PQexec(conn, sel, CKPQ_READ);
rescode = PQresultStatus(res);
if (!PGOK(rescode)) {
PGLOGERR("Select", rescode, conn);

Loading…
Cancel
Save