From c28784c611a97647442857b4f63ce3ff23dddc4b Mon Sep 17 00:00:00 2001 From: kanoi Date: Sun, 19 Oct 2014 13:05:55 +1100 Subject: [PATCH] ckdb - add paymentaddresses dump code and fix removal of old ones --- src/ckdb.c | 1 + src/ckdb.h | 3 ++- src/ckdb_cmd.c | 6 +++++- src/ckdb_data.c | 21 +++++++++++++++++++-- src/ckdb_dbio.c | 2 +- src/ktree.c | 3 +++ 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/ckdb.c b/src/ckdb.c index 59f94fcc..8c57682c 100644 --- a/src/ckdb.c +++ b/src/ckdb.c @@ -907,6 +907,7 @@ static void alloc_storage() LIMIT_PAYMENTADDRESSES, true); paymentaddresses_store = k_new_store(paymentaddresses_free); paymentaddresses_root = new_ktree(); + paymentaddresses_free->dsp_func = dsp_paymentaddresses; payments_free = k_new_list("Payments", sizeof(PAYMENTS), ALLOC_PAYMENTS, LIMIT_PAYMENTS, true); diff --git a/src/ckdb.h b/src/ckdb.h index e3661bd6..bc68be96 100644 --- a/src/ckdb.h +++ b/src/ckdb.h @@ -52,7 +52,7 @@ #define DB_VLOCK "1" #define DB_VERSION "0.9.2" -#define CKDB_VERSION DB_VERSION"-0.515" +#define CKDB_VERSION DB_VERSION"-0.516" #define WHERE_FFL " - from %s %s() line %d" #define WHERE_FFL_HERE __FILE__, __func__, __LINE__ @@ -1283,6 +1283,7 @@ extern K_ITEM *new_worker(PGconn *conn, bool update, int64_t userid, char *worke char *code, char *inet, tv_t *cd, K_TREE *trf_root); extern K_ITEM *new_default_worker(PGconn *conn, bool update, int64_t userid, char *workername, char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root); +extern void dsp_paymentaddresses(K_ITEM *item, FILE *stream); extern cmp_t cmp_paymentaddresses(K_ITEM *a, K_ITEM *b); extern K_ITEM *find_paymentaddresses(int64_t userid); extern cmp_t cmp_payments(K_ITEM *a, K_ITEM *b); diff --git a/src/ckdb_cmd.c b/src/ckdb_cmd.c index 6c0146dd..ffe6f3e6 100644 --- a/src/ckdb_cmd.c +++ b/src/ckdb_cmd.c @@ -3275,7 +3275,11 @@ static char *cmd_dsp(__maybe_unused PGconn *conn, __maybe_unused char *cmd, dsp_ktree(transfer_free, trf_root, transfer_data(i_file), NULL); - dsp_ktree(sharesummary_free, sharesummary_root, transfer_data(i_file), NULL); + dsp_ktree(paymentaddresses_free, paymentaddresses_root, + transfer_data(i_file), NULL); + + dsp_ktree(sharesummary_free, sharesummary_root, + transfer_data(i_file), NULL); dsp_ktree(userstats_free, userstats_root, transfer_data(i_file), NULL); diff --git a/src/ckdb_data.c b/src/ckdb_data.c index c612c814..30a113f3 100644 --- a/src/ckdb_data.c +++ b/src/ckdb_data.c @@ -1006,6 +1006,25 @@ static K_ITEM *new_worker_find_user(PGconn *conn, bool update, char *username, } */ +void dsp_paymentaddresses(K_ITEM *item, FILE *stream) +{ + char expirydate_buf[DATE_BUFSIZ], createdate_buf[DATE_BUFSIZ]; + PAYMENTADDRESSES *pa; + + if (!item) + fprintf(stream, "%s() called with (null) item\n", __func__); + else { + DATA_PAYMENTADDRESSES(pa, item); + tv_to_buf(&(pa->expirydate), expirydate_buf, sizeof(expirydate_buf)); + tv_to_buf(&(pa->createdate), createdate_buf, sizeof(createdate_buf)); + fprintf(stream, " id=%"PRId64" userid=%"PRId64" addr='%s' " + "ratio=%"PRId32" exp=%s cd=%s\n", + pa->paymentaddressid, pa->userid, + pa->payaddress, pa->payratio, + expirydate_buf, createdate_buf); + } +} + // order by userid asc,expirydate desc,payaddress asc cmp_t cmp_paymentaddresses(K_ITEM *a, K_ITEM *b) { @@ -1429,7 +1448,6 @@ void dsp_sharesummary(K_ITEM *item, FILE *stream) fprintf(stream, "%s() called with (null) item\n", __func__); else { DATA_SHARESUMMARY(s, item); - tv_to_buf(&(s->createdate), createdate_buf, sizeof(createdate_buf)); fprintf(stream, " uid=%"PRId64" wn='%s' wid=%"PRId64" " "da=%f ds=%f ss=%f c='%s' cd=%s\n", @@ -1697,7 +1715,6 @@ void dsp_blocks(K_ITEM *item, FILE *stream) fprintf(stream, "%s() called with (null) item\n", __func__); else { DATA_BLOCKS(b, item); - dsp_hash(b->blockhash, hash_dsp, sizeof(hash_dsp)); tv_to_buf(&(b->createdate), createdate_buf, sizeof(createdate_buf)); tv_to_buf(&(b->expirydate), expirydate_buf, sizeof(expirydate_buf)); diff --git a/src/ckdb_dbio.c b/src/ckdb_dbio.c index 414c9b4e..97e71b7d 100644 --- a/src/ckdb_dbio.c +++ b/src/ckdb_dbio.c @@ -1531,7 +1531,7 @@ unitem: else { // Remove from ram, old (unneeded) records pa.userid = userid; - pa.expirydate.tv_sec = 0L; + pa.expirydate.tv_sec = DATE_S_EOT; pa.payaddress[0] = '\0'; INIT_PAYMENTADDRESSES(&look); look.data = (void *)(&pa); diff --git a/src/ktree.c b/src/ktree.c index c6e8d3d1..57525c4e 100644 --- a/src/ktree.c +++ b/src/ktree.c @@ -133,6 +133,9 @@ void _dsp_ktree(K_LIST *list, K_TREE *root, char *filename, char *msg, KTREE_FFL time_t now_t; char stamp[128]; + if (!list->dsp_func) + FAIL("%s", "NULLDSP NULL dsp_func"); + now_t = time(NULL); localtime_r(&now_t, &tm); snprintf(stamp, sizeof(stamp),