-implement missing functions
This commit is contained in:
parent
5c0b8e3240
commit
a51517f64c
@ -1 +1 @@
|
||||
Subproject commit 2b89e6cc727a605351dcf7ddc80c52b0200376b8
|
||||
Subproject commit 9657bf77de05c0ac17ff39629306a604066b21de
|
@ -170,8 +170,8 @@ CREATE INDEX IF NOT EXISTS auditor_reserves_by_reserve_pub
|
||||
CREATE TABLE IF NOT EXISTS auditor_purses
|
||||
(purse_pub BYTEA NOT NULL CHECK(LENGTH(purse_pub)=32)
|
||||
,master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
|
||||
,balance_val INT8 NOT NULL
|
||||
,balance_frac INT4 NOT NULL
|
||||
,balance_val INT8 NOT NULL DEFAULT(0)
|
||||
,balance_frac INT4 NOT NULL DEFAULT(0)
|
||||
,target_val INT8 NOT NULL
|
||||
,target_frac INT4 NOT NULL
|
||||
,expiration_date INT8 NOT NULL
|
||||
@ -185,6 +185,20 @@ CREATE INDEX IF NOT EXISTS auditor_purses_by_purse_pub
|
||||
(purse_pub);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS auditor_purse_summary
|
||||
(master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
|
||||
,balance_val INT8 NOT NULL
|
||||
,balance_frac INT4 NOT NULL
|
||||
,open_purses INT8 NOT NULL
|
||||
);
|
||||
COMMENT ON TABLE auditor_purse_summary
|
||||
IS 'sum of the balances in open purses';
|
||||
|
||||
CREATE INDEX IF NOT EXISTS auditor_purses_by_purse_pub
|
||||
ON auditor_purses
|
||||
(purse_pub);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS auditor_reserve_balance
|
||||
(master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
|
||||
,reserve_balance_val INT8 NOT NULL
|
||||
|
@ -25,10 +25,26 @@
|
||||
#include "pg_delete_purse_info.h"
|
||||
#include "pg_helper.h"
|
||||
|
||||
|
||||
enum GNUNET_DB_QueryStatus
|
||||
TAH_PG_delete_purse_info (
|
||||
void *cls,
|
||||
const struct TALER_PurseContractPublicKeyP *purse_pub,
|
||||
const struct TALER_MasterPublicKeyP *master_pub)
|
||||
{
|
||||
struct PostgresClosure *pg = cls;
|
||||
struct GNUNET_PQ_QueryParam params[] = {
|
||||
GNUNET_PQ_query_param_auto_from_type (purse_pub),
|
||||
GNUNET_PQ_query_param_auto_from_type (master_pub),
|
||||
GNUNET_PQ_query_param_end
|
||||
};
|
||||
|
||||
PREPARE (pg,
|
||||
"auditor_purses_delete",
|
||||
"DELETE FROM auditor_purses "
|
||||
" WHERE purse_pub=$1"
|
||||
" AND master_pub=$2;");
|
||||
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
|
||||
"auditor_purses_delete",
|
||||
params);
|
||||
}
|
||||
|
@ -34,4 +34,33 @@ TAH_PG_get_purse_info (
|
||||
struct TALER_Amount *balance,
|
||||
struct GNUNET_TIME_Timestamp *expiration_date)
|
||||
{
|
||||
struct PostgresClosure *pg = cls;
|
||||
struct GNUNET_PQ_QueryParam params[] = {
|
||||
GNUNET_PQ_query_param_auto_from_type (purse_pub),
|
||||
GNUNET_PQ_query_param_auto_from_type (master_pub),
|
||||
GNUNET_PQ_query_param_end
|
||||
};
|
||||
struct GNUNET_PQ_ResultSpec rs[] = {
|
||||
TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
|
||||
balance),
|
||||
GNUNET_PQ_result_spec_timestamp ("expiration_date",
|
||||
expiration_date),
|
||||
GNUNET_PQ_result_spec_uint64 ("auditor_purses_rowid",
|
||||
rowid),
|
||||
GNUNET_PQ_result_spec_end
|
||||
};
|
||||
|
||||
PREPARE (pg,
|
||||
"auditor_get_purse_info",
|
||||
"SELECT"
|
||||
" expiration_date"
|
||||
",balance_val"
|
||||
",balance_frac"
|
||||
" FROM auditor_purses"
|
||||
" WHERE purse_pub=$1"
|
||||
" AND master_pub=$2;");
|
||||
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
|
||||
"auditor_get_purse_info",
|
||||
params,
|
||||
rs);
|
||||
}
|
||||
|
@ -25,9 +25,35 @@
|
||||
#include "pg_get_purse_summary.h"
|
||||
#include "pg_helper.h"
|
||||
|
||||
|
||||
enum GNUNET_DB_QueryStatus
|
||||
TAH_PG_get_purse_summary (void *cls,
|
||||
const struct TALER_MasterPublicKeyP *master_pub,
|
||||
struct TALER_AUDITORDB_PurseBalance *sum)
|
||||
{
|
||||
struct PostgresClosure *pg = cls;
|
||||
struct GNUNET_PQ_QueryParam params[] = {
|
||||
GNUNET_PQ_query_param_auto_from_type (master_pub),
|
||||
GNUNET_PQ_query_param_end
|
||||
};
|
||||
struct GNUNET_PQ_ResultSpec rs[] = {
|
||||
TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
|
||||
&sum->balance),
|
||||
GNUNET_PQ_result_spec_uint64 ("open_purses",
|
||||
&sum->open_purses),
|
||||
GNUNET_PQ_result_spec_end
|
||||
};
|
||||
|
||||
PREPARE (pg,
|
||||
"auditor_get_purse_summary",
|
||||
"SELECT"
|
||||
" open_purses"
|
||||
",balance_val"
|
||||
",balance_frac"
|
||||
" FROM auditor_purse_summary"
|
||||
" WHERE master_pub=$1;");
|
||||
return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
|
||||
"auditor_get_purse_summary",
|
||||
params,
|
||||
rs);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "pg_insert_purse_info.h"
|
||||
#include "pg_helper.h"
|
||||
|
||||
|
||||
enum GNUNET_DB_QueryStatus
|
||||
TAH_PG_insert_purse_info (
|
||||
void *cls,
|
||||
@ -33,4 +34,25 @@ TAH_PG_insert_purse_info (
|
||||
const struct TALER_Amount *balance,
|
||||
struct GNUNET_TIME_Timestamp expiration_date)
|
||||
{
|
||||
struct PostgresClosure *pg = cls;
|
||||
struct GNUNET_PQ_QueryParam params[] = {
|
||||
GNUNET_PQ_query_param_auto_from_type (purse_pub),
|
||||
GNUNET_PQ_query_param_auto_from_type (master_pub),
|
||||
TALER_PQ_query_param_amount (balance),
|
||||
GNUNET_PQ_query_param_timestamp (&expiration_date),
|
||||
GNUNET_PQ_query_param_end
|
||||
};
|
||||
|
||||
PREPARE (pg,
|
||||
"auditor_purses_insert",
|
||||
"INSERT INTO auditor_purses "
|
||||
"(purse_pub"
|
||||
",master_pub"
|
||||
",target_val"
|
||||
",target_frac"
|
||||
",expiration_date"
|
||||
") VALUES ($1,$2,$3,$4,$5);");
|
||||
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
|
||||
"auditor_purses_insert",
|
||||
params);
|
||||
}
|
||||
|
@ -25,10 +25,30 @@
|
||||
#include "pg_insert_purse_summary.h"
|
||||
#include "pg_helper.h"
|
||||
|
||||
|
||||
enum GNUNET_DB_QueryStatus
|
||||
TAH_PG_insert_purse_summary (
|
||||
void *cls,
|
||||
const struct TALER_MasterPublicKeyP *master_pub,
|
||||
const struct TALER_AUDITORDB_PurseBalance *sum)
|
||||
{
|
||||
struct PostgresClosure *pg = cls;
|
||||
struct GNUNET_PQ_QueryParam params[] = {
|
||||
GNUNET_PQ_query_param_auto_from_type (master_pub),
|
||||
TALER_PQ_query_param_amount (&sum->balance),
|
||||
GNUNET_PQ_query_param_uint64 (&sum->open_purses),
|
||||
GNUNET_PQ_query_param_end
|
||||
};
|
||||
|
||||
PREPARE (pg,
|
||||
"auditor_purse_summary_insert",
|
||||
"INSERT INTO auditor_purse_summary "
|
||||
"(master_pub"
|
||||
",balance_val"
|
||||
",balance_frac"
|
||||
",open_purses"
|
||||
") VALUES ($1,$2,$3,$4);");
|
||||
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
|
||||
"auditor_purse_summary_insert",
|
||||
params);
|
||||
}
|
||||
|
@ -25,6 +25,87 @@
|
||||
#include "pg_select_purse_expired.h"
|
||||
#include "pg_helper.h"
|
||||
|
||||
|
||||
/**
|
||||
* Closure for #purse_expired_cb().
|
||||
*/
|
||||
struct PurseExpiredContext
|
||||
{
|
||||
|
||||
/**
|
||||
* Function to call for each expired purse.
|
||||
*/
|
||||
TALER_AUDITORDB_ExpiredPurseCallback cb;
|
||||
|
||||
/**
|
||||
* Closure for @e cb
|
||||
*/
|
||||
void *cb_cls;
|
||||
|
||||
/**
|
||||
* Plugin context.
|
||||
*/
|
||||
struct PostgresClosure *pg;
|
||||
|
||||
/**
|
||||
* Query status to return.
|
||||
*/
|
||||
enum GNUNET_DB_QueryStatus qs;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Helper function for #TAH_PG_select_purse_expired().
|
||||
* To be called with the results of a SELECT statement
|
||||
* that has returned @a num_results results.
|
||||
*
|
||||
* @param cls closure of type `struct PurseExpiredContext *`
|
||||
* @param result the postgres result
|
||||
* @param num_results the number of results in @a result
|
||||
*/
|
||||
static void
|
||||
purse_expired_cb (void *cls,
|
||||
PGresult *result,
|
||||
unsigned int num_results)
|
||||
{
|
||||
struct PurseExpiredContext *eic = cls;
|
||||
struct PostgresClosure *pg = eic->pg;
|
||||
|
||||
for (unsigned int i = 0; i < num_results; i++)
|
||||
{
|
||||
struct TALER_PurseContractPublicKeyP purse_pub;
|
||||
struct GNUNET_TIME_Timestamp expiration_date;
|
||||
struct TALER_Amount balance;
|
||||
struct GNUNET_PQ_ResultSpec rs[] = {
|
||||
GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
|
||||
&purse_pub),
|
||||
TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
|
||||
&balance),
|
||||
GNUNET_PQ_result_spec_timestamp ("expiration_date",
|
||||
&expiration_date),
|
||||
GNUNET_PQ_result_spec_end
|
||||
};
|
||||
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_PQ_extract_result (result,
|
||||
rs,
|
||||
i))
|
||||
{
|
||||
GNUNET_break (0);
|
||||
eic->qs = GNUNET_DB_STATUS_HARD_ERROR;
|
||||
return;
|
||||
}
|
||||
eic->qs = i + 1;
|
||||
if (GNUNET_OK !=
|
||||
eic->cb (eic->cb_cls,
|
||||
&purse_pub,
|
||||
&balance,
|
||||
expiration_date))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum GNUNET_DB_QueryStatus
|
||||
TAH_PG_select_purse_expired (
|
||||
void *cls,
|
||||
@ -32,4 +113,38 @@ TAH_PG_select_purse_expired (
|
||||
TALER_AUDITORDB_ExpiredPurseCallback cb,
|
||||
void *cb_cls)
|
||||
{
|
||||
struct PostgresClosure *pg = cls;
|
||||
struct GNUNET_TIME_Timestamp now
|
||||
= GNUNET_TIME_timestamp_get ();
|
||||
struct GNUNET_PQ_QueryParam params[] = {
|
||||
GNUNET_PQ_query_param_auto_from_type (master_pub),
|
||||
GNUNET_PQ_query_param_timestamp (&now),
|
||||
GNUNET_PQ_query_param_end
|
||||
};
|
||||
struct PurseExpiredContext eic = {
|
||||
.cb = cb,
|
||||
.cb_cls = cb_cls,
|
||||
.pg = pg
|
||||
};
|
||||
enum GNUNET_DB_QueryStatus qs;
|
||||
|
||||
PREPARE (pg,
|
||||
"auditor_select_expired_purses",
|
||||
"SELECT"
|
||||
" purse_pub"
|
||||
",expiration_date"
|
||||
",balance_val"
|
||||
",balance_frac"
|
||||
" FROM auditor_purses"
|
||||
" WHERE master_pub=$1"
|
||||
" AND expiration_date<$2;");
|
||||
qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
|
||||
"auditor_select_expired_purses",
|
||||
params,
|
||||
&purse_expired_cb,
|
||||
&eic);
|
||||
if (qs > 0)
|
||||
return eic.qs;
|
||||
GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
|
||||
return qs;
|
||||
}
|
||||
|
@ -33,4 +33,23 @@ TAH_PG_update_purse_info (
|
||||
const struct TALER_MasterPublicKeyP *master_pub,
|
||||
const struct TALER_Amount *balance)
|
||||
{
|
||||
|
||||
struct PostgresClosure *pg = cls;
|
||||
struct GNUNET_PQ_QueryParam params[] = {
|
||||
GNUNET_PQ_query_param_auto_from_type (purse_pub),
|
||||
GNUNET_PQ_query_param_auto_from_type (master_pub),
|
||||
TALER_PQ_query_param_amount (balance),
|
||||
GNUNET_PQ_query_param_end
|
||||
};
|
||||
|
||||
PREPARE (pg,
|
||||
"auditor_purses_update",
|
||||
"UPDATE auditor_purses SET "
|
||||
" balance_val=$3"
|
||||
",balance_frac=$4"
|
||||
" WHERE purse_pub=$1"
|
||||
" AND master_pub=$2;");
|
||||
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
|
||||
"auditor_purses_update",
|
||||
params);
|
||||
}
|
||||
|
@ -32,4 +32,22 @@ TAH_PG_update_purse_summary (
|
||||
const struct TALER_MasterPublicKeyP *master_pub,
|
||||
const struct TALER_AUDITORDB_PurseBalance *sum)
|
||||
{
|
||||
struct PostgresClosure *pg = cls;
|
||||
struct GNUNET_PQ_QueryParam params[] = {
|
||||
GNUNET_PQ_query_param_auto_from_type (master_pub),
|
||||
TALER_PQ_query_param_amount (&sum->balance),
|
||||
GNUNET_PQ_query_param_uint64 (&sum->open_purses),
|
||||
GNUNET_PQ_query_param_end
|
||||
};
|
||||
|
||||
PREPARE (pg,
|
||||
"auditor_purse_summary_update",
|
||||
"UPDATE auditor_purse_summary SET"
|
||||
" balance_val=$2"
|
||||
",balance_frac=$3"
|
||||
",open_purses=$4"
|
||||
" WHERE master_pub=$1;");
|
||||
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
|
||||
"auditor_purse_summary_update",
|
||||
params);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user