Browse Source

ckdb - add paymentaddresses dump code and fix removal of old ones

master
kanoi 10 years ago
parent
commit
c28784c611
  1. 1
      src/ckdb.c
  2. 3
      src/ckdb.h
  3. 6
      src/ckdb_cmd.c
  4. 21
      src/ckdb_data.c
  5. 2
      src/ckdb_dbio.c
  6. 3
      src/ktree.c

1
src/ckdb.c

@ -907,6 +907,7 @@ static void alloc_storage()
LIMIT_PAYMENTADDRESSES, true); LIMIT_PAYMENTADDRESSES, true);
paymentaddresses_store = k_new_store(paymentaddresses_free); paymentaddresses_store = k_new_store(paymentaddresses_free);
paymentaddresses_root = new_ktree(); paymentaddresses_root = new_ktree();
paymentaddresses_free->dsp_func = dsp_paymentaddresses;
payments_free = k_new_list("Payments", sizeof(PAYMENTS), payments_free = k_new_list("Payments", sizeof(PAYMENTS),
ALLOC_PAYMENTS, LIMIT_PAYMENTS, true); ALLOC_PAYMENTS, LIMIT_PAYMENTS, true);

3
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.515" #define CKDB_VERSION DB_VERSION"-0.516"
#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__
@ -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); 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, 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); 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 cmp_t cmp_paymentaddresses(K_ITEM *a, K_ITEM *b);
extern K_ITEM *find_paymentaddresses(int64_t userid); extern K_ITEM *find_paymentaddresses(int64_t userid);
extern cmp_t cmp_payments(K_ITEM *a, K_ITEM *b); extern cmp_t cmp_payments(K_ITEM *a, K_ITEM *b);

6
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(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); dsp_ktree(userstats_free, userstats_root, transfer_data(i_file), NULL);

21
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 // order by userid asc,expirydate desc,payaddress asc
cmp_t cmp_paymentaddresses(K_ITEM *a, K_ITEM *b) 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__); fprintf(stream, "%s() called with (null) item\n", __func__);
else { else {
DATA_SHARESUMMARY(s, item); DATA_SHARESUMMARY(s, item);
tv_to_buf(&(s->createdate), createdate_buf, sizeof(createdate_buf)); tv_to_buf(&(s->createdate), createdate_buf, sizeof(createdate_buf));
fprintf(stream, " uid=%"PRId64" wn='%s' wid=%"PRId64" " fprintf(stream, " uid=%"PRId64" wn='%s' wid=%"PRId64" "
"da=%f ds=%f ss=%f c='%s' cd=%s\n", "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__); fprintf(stream, "%s() called with (null) item\n", __func__);
else { else {
DATA_BLOCKS(b, item); DATA_BLOCKS(b, item);
dsp_hash(b->blockhash, hash_dsp, sizeof(hash_dsp)); dsp_hash(b->blockhash, hash_dsp, sizeof(hash_dsp));
tv_to_buf(&(b->createdate), createdate_buf, sizeof(createdate_buf)); tv_to_buf(&(b->createdate), createdate_buf, sizeof(createdate_buf));
tv_to_buf(&(b->expirydate), expirydate_buf, sizeof(expirydate_buf)); tv_to_buf(&(b->expirydate), expirydate_buf, sizeof(expirydate_buf));

2
src/ckdb_dbio.c

@ -1531,7 +1531,7 @@ unitem:
else { else {
// Remove from ram, old (unneeded) records // Remove from ram, old (unneeded) records
pa.userid = userid; pa.userid = userid;
pa.expirydate.tv_sec = 0L; 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);

3
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; time_t now_t;
char stamp[128]; char stamp[128];
if (!list->dsp_func)
FAIL("%s", "NULLDSP NULL dsp_func");
now_t = time(NULL); now_t = time(NULL);
localtime_r(&now_t, &tm); localtime_r(&now_t, &tm);
snprintf(stamp, sizeof(stamp), snprintf(stamp, sizeof(stamp),

Loading…
Cancel
Save