updating DB schema for new wire history operations and future auditor checks of wire transfers

This commit is contained in:
Christian Grothoff 2017-05-05 13:41:32 +02:00
parent 2c05a4b278
commit 76545519c6
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
9 changed files with 91 additions and 32 deletions

View File

@ -615,6 +615,8 @@ struct ReserveContext
* @param credit amount that was received
* @param sender_account_details information about the sender's bank account
* @param transfer_details information that uniquely identifies the wire transfer
* @param wire_reference unique reference identifying the wire transfer (binary blob)
* @param wire_reference_size number of bytes in @a wire_reference
* @param execution_date when did we receive the funds
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
@ -625,6 +627,8 @@ handle_reserve_in (void *cls,
const struct TALER_Amount *credit,
const json_t *sender_account_details,
const json_t *transfer_details,
const void *wire_reference,
size_t wire_reference_size,
struct GNUNET_TIME_Absolute execution_date)
{
struct ReserveContext *rc = cls;

View File

@ -95,6 +95,8 @@ run_transaction (const struct TALER_ReservePublicKeyP *reserve_pub,
add_value,
GNUNET_TIME_absolute_get (),
jdetails,
"FIXME",
5,
tdetails);
if (GNUNET_SYSERR == ret)
{

View File

@ -1880,6 +1880,8 @@ TEH_DB_execute_admin_add_incoming (struct MHD_Connection *connection,
amount,
execution_time,
sender_account_details,
"FIXME",
5,
transfer_details);
if (GNUNET_SYSERR == ret)
{

View File

@ -251,13 +251,15 @@ history_cb (void *cls,
return GNUNET_OK;
}
// FIXME: store row_off+row_off_size instead of json_t?
// FIXME: create json!
ret = db_plugin->reserves_in_insert (db_plugin->cls,
session,
&reserve_pub,
&details->amount,
details->execution_date,
details->account_details,
row_off,
row_off_size,
NULL /* FIXME */);
if (GNUNET_OK != ret)
{

View File

@ -1394,6 +1394,8 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
&reserve->reserve.balance,
GNUNET_TIME_absolute_get (),
sndr,
"PERF",
4,
just);
GNUNET_assert (GNUNET_SYSERR != ret);
json_decref (sndr);

View File

@ -46,6 +46,7 @@ common_free_reserve_history (void *cls,
json_decref (bt->sender_account_details);
if (NULL != bt->transfer_details)
json_decref (bt->transfer_details);
GNUNET_free_non_null (bt->wire_reference);
GNUNET_free (bt);
break;
case TALER_EXCHANGEDB_RO_WITHDRAW_COIN:

View File

@ -352,13 +352,14 @@ postgres_create_tables (void *cls)
SQLEXEC("CREATE TABLE IF NOT EXISTS reserves_in"
"(reserve_in_serial_id BIGSERIAL"
",reserve_pub BYTEA NOT NULL REFERENCES reserves (reserve_pub) ON DELETE CASCADE"
",wire_reference BYTEA NOT NULL"
",credit_val INT8 NOT NULL"
",credit_frac INT4 NOT NULL"
",credit_curr VARCHAR("TALER_CURRENCY_LEN_STR") NOT NULL"
",sender_account_details TEXT NOT NULL"
",transfer_details TEXT NOT NULL"
",execution_date INT8 NOT NULL"
",PRIMARY KEY (reserve_pub, transfer_details)"
",PRIMARY KEY (reserve_pub, wire_reference)"
");");
/* Create indices on reserves_in */
SQLEXEC_INDEX ("CREATE INDEX reserves_in_execution_index"
@ -758,6 +759,7 @@ postgres_prepare (PGconn *db_conn)
PREPARE ("reserves_in_add_transaction",
"INSERT INTO reserves_in "
"(reserve_pub"
",wire_reference"
",credit_val"
",credit_frac"
",credit_curr"
@ -765,8 +767,8 @@ postgres_prepare (PGconn *db_conn)
",transfer_details"
",execution_date"
") VALUES "
"($1, $2, $3, $4, $5, $6, $7);",
7, NULL);
"($1, $2, $3, $4, $5, $6, $7, $8);",
8, NULL);
/* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound
@ -774,6 +776,7 @@ postgres_prepare (PGconn *db_conn)
PREPARE ("audit_reserves_in_get_transactions_incr",
"SELECT"
" reserve_pub"
",wire_reference"
",credit_val"
",credit_frac"
",credit_curr"
@ -790,7 +793,8 @@ postgres_prepare (PGconn *db_conn)
for a reserve */
PREPARE ("reserves_in_get_transactions",
"SELECT"
" credit_val"
" wire_reference"
",credit_val"
",credit_frac"
",credit_curr"
",execution_date"
@ -2074,6 +2078,8 @@ reserves_update (void *cls,
* @param balance the amount that has to be added to the reserve
* @param execution_time when was the amount added
* @param sender_account_details account information for the sender
* @param wire_reference unique reference identifying the wire transfer (binary blob)
* @param wire_reference_size number of bytes in @a wire_reference
* @param transfer_details information that uniquely identifies the transfer
* @return #GNUNET_OK upon success; #GNUNET_NO if the given
* @a details are already known for this @a reserve_pub,
@ -2086,6 +2092,8 @@ postgres_reserves_in_insert (void *cls,
const struct TALER_Amount *balance,
struct GNUNET_TIME_Absolute execution_time,
const json_t *sender_account_details,
const void *wire_reference,
size_t wire_reference_size,
const json_t *transfer_details)
{
struct PostgresClosure *pg = cls;
@ -2166,6 +2174,8 @@ postgres_reserves_in_insert (void *cls,
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (&reserve.pub),
GNUNET_PQ_query_param_fixed_size (wire_reference,
wire_reference_size),
TALER_PQ_query_param_amount (balance),
TALER_PQ_query_param_json (sender_account_details),
TALER_PQ_query_param_json (transfer_details),
@ -2460,6 +2470,9 @@ postgres_get_reserve_history (void *cls,
bt = GNUNET_new (struct TALER_EXCHANGEDB_BankTransfer);
{
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_variable_size ("wire_reference",
&bt->wire_reference,
&bt->wire_reference_size),
TALER_PQ_result_spec_amount ("credit",
&bt->amount),
GNUNET_PQ_result_spec_absolute_time ("execution_date",
@ -5830,10 +5843,15 @@ postgres_select_reserves_in_above_serial_id (void *cls,
json_t *transfer_details;
struct GNUNET_TIME_Absolute execution_date;
uint64_t rowid;
void *wire_reference;
size_t wire_reference_size;
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
&reserve_pub),
GNUNET_PQ_result_spec_variable_size ("wire_reference",
&wire_reference,
&wire_reference_size),
TALER_PQ_result_spec_amount ("credit",
&credit),
GNUNET_PQ_result_spec_absolute_time("execution_date",
@ -5862,6 +5880,8 @@ postgres_select_reserves_in_above_serial_id (void *cls,
&credit,
sender_account_details,
transfer_details,
wire_reference,
wire_reference_size,
execution_date);
GNUNET_PQ_cleanup_result (rs);
if (GNUNET_OK != ret)

View File

@ -1033,6 +1033,8 @@ audit_refund_cb (void *cls,
* @param credit amount that was received
* @param sender_account_details information about the sender's bank account
* @param transfer_details information that uniquely identifies the wire transfer
* @param wire_reference unique reference identifying the wire transfer (binary blob)
* @param wire_reference_size number of bytes in @a wire_reference
* @param execution_date when did we receive the funds
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
@ -1043,6 +1045,8 @@ audit_reserve_in_cb (void *cls,
const struct TALER_Amount *credit,
const json_t *sender_account_details,
const json_t *transfer_details,
const void *wire_reference,
size_t wire_reference_size,
struct GNUNET_TIME_Absolute execution_date)
{
auditor_row_cnt++;
@ -1511,6 +1515,8 @@ run (void *cls)
&value,
GNUNET_TIME_absolute_get (),
sndr,
"TEST",
4,
just));
json_decref (just);
FAILIF (GNUNET_OK !=
@ -1527,6 +1533,8 @@ run (void *cls)
&value,
GNUNET_TIME_absolute_get (),
sndr,
"TEST2",
5,
just));
json_decref (just);
json_decref (sndr);

View File

@ -61,6 +61,16 @@ struct TALER_EXCHANGEDB_BankTransfer
*/
json_t *transfer_details;
/**
* Data uniquely identifying the wire transfer (wire transfer-type specific)
*/
void *wire_reference;
/**
* Number of bytes in @e wire_reference.
*/
size_t wire_reference_size;
};
@ -800,6 +810,8 @@ typedef int
* @param credit amount that was received
* @param sender_account_details information about the sender's bank account
* @param transfer_details information that uniquely identifies the wire transfer
* @param wire_reference unique identifier for the wire transfer (plugin-specific format)
* @param wire_reference_size number of bytes in @a wire_reference
* @param execution_date when did we receive the funds
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
@ -810,6 +822,8 @@ typedef int
const struct TALER_Amount *credit,
const json_t *sender_account_details,
const json_t *transfer_details,
const void *wire_reference,
size_t wire_reference_size,
struct GNUNET_TIME_Absolute execution_date);
@ -1181,6 +1195,8 @@ struct TALER_EXCHANGEDB_Plugin
* @param balance the amount that has to be added to the reserve
* @param execution_time when was the amount added
* @param sender_account_details information about the sender's bank account
* @param wire_reference unique reference identifying the wire transfer (binary blob)
* @param wire_reference_size number of bytes in @a wire_reference
* @param transfer_details information that uniquely identifies the wire transfer
* @return #GNUNET_OK upon success; #GNUNET_NO if the given
* @a details are already known for this @a reserve_pub,
@ -1193,6 +1209,8 @@ struct TALER_EXCHANGEDB_Plugin
const struct TALER_Amount *balance,
struct GNUNET_TIME_Absolute execution_time,
const json_t *sender_account_details,
const void *wire_reference,
size_t wire_reference_size,
const json_t *transfer_details);