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. 25
      src/ckdb_dbio.c

2
src/ckdb.h

@ -52,7 +52,7 @@
#define DB_VLOCK "1" #define DB_VLOCK "1"
#define DB_VERSION "0.9.2" #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 " - from %s %s() line %d"
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ #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; return c;
} }
// Only one for now ...
K_ITEM *find_paymentaddresses(int64_t userid) K_ITEM *find_paymentaddresses(int64_t userid)
{ {
PAYMENTADDRESSES paymentaddresses, *pa; PAYMENTADDRESSES paymentaddresses, *pa;

25
src/ckdb_dbio.c

@ -1424,7 +1424,9 @@ bool workers_fill(PGconn *conn)
return ok; 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, K_ITEM *paymentaddresses_set(PGconn *conn, int64_t userid, char *payaddress,
char *by, char *code, char *inet, tv_t *cd, char *by, char *code, char *inet, tv_t *cd,
K_TREE *trf_root) K_TREE *trf_root)
@ -1529,12 +1531,13 @@ unitem:
if (!ok) if (!ok)
k_add_head(paymentaddresses_free, item); k_add_head(paymentaddresses_free, item);
else { else {
// Remove from ram, old (unneeded) records // Change the expiry on all the old ones
pa.userid = userid; pa.userid = userid;
pa.expirydate.tv_sec = DATE_S_EOT; pa.expirydate.tv_sec = DATE_S_EOT;
pa.payaddress[0] = '\0'; pa.payaddress[0] = '\0';
INIT_PAYMENTADDRESSES(&look); INIT_PAYMENTADDRESSES(&look);
look.data = (void *)(&pa); look.data = (void *)(&pa);
// Tree order is expirydate desc
old = find_after_in_ktree(paymentaddresses_root, &look, old = find_after_in_ktree(paymentaddresses_root, &look,
cmp_paymentaddresses, ctx); cmp_paymentaddresses, ctx);
while (old) { while (old) {
@ -1543,9 +1546,15 @@ unitem:
if (thispa->userid != userid) if (thispa->userid != userid)
break; break;
old = next_in_ktree(ctx); old = next_in_ktree(ctx);
/* 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, paymentaddresses_root = remove_from_ktree(paymentaddresses_root, this,
cmp_paymentaddresses, ctx2); cmp_paymentaddresses, ctx2);
k_add_head(paymentaddresses_free, this); copy_tv(&(thispa->expirydate), cd);
paymentaddresses_root = add_to_ktree(paymentaddresses_root, this,
cmp_paymentaddresses);
}
} }
paymentaddresses_root = add_to_ktree(paymentaddresses_root, item, paymentaddresses_root = add_to_ktree(paymentaddresses_root, item,
cmp_paymentaddresses); cmp_paymentaddresses);
@ -1565,8 +1574,7 @@ bool paymentaddresses_fill(PGconn *conn)
PGresult *res; PGresult *res;
K_ITEM *item; K_ITEM *item;
PAYMENTADDRESSES *row; PAYMENTADDRESSES *row;
char *params[1]; int n, i;
int n, i, par = 0;
char *field; char *field;
char *sel; char *sel;
int fields = 4; int fields = 4;
@ -1577,11 +1585,8 @@ bool paymentaddresses_fill(PGconn *conn)
sel = "select " sel = "select "
"paymentaddressid,userid,payaddress,payratio" "paymentaddressid,userid,payaddress,payratio"
HISTORYDATECONTROL HISTORYDATECONTROL
" from paymentaddresses where expirydate=$1"; " from paymentaddresses";
par = 0; res = PQexec(conn, sel, CKPQ_READ);
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);
rescode = PQresultStatus(res); rescode = PQresultStatus(res);
if (!PGOK(rescode)) { if (!PGOK(rescode)) {
PGLOGERR("Select", rescode, conn); PGLOGERR("Select", rescode, conn);

Loading…
Cancel
Save