implement taler-auditor-sync support for profit_drains table (#4960)

This commit is contained in:
Christian Grothoff 2022-07-30 10:29:24 +02:00
parent 75888adff2
commit 033a5dc93b
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
5 changed files with 156 additions and 2 deletions

View File

@ -1,6 +1,6 @@
/*
This file is part of TALER
Copyright (C) 2020 Taler Systems SA
Copyright (C) 2020-2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@ -125,6 +125,7 @@ static struct Table tables[] = {
{ .rt = TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES},
{ .rt = TALER_EXCHANGEDB_RT_WADS_IN},
{ .rt = TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES},
{ .rt = TALER_EXCHANGEDB_RT_PROFIT_DRAINS},
{ .end = true }
};

View File

@ -1131,4 +1131,37 @@ irbt_cb_table_wads_in_entries (struct PostgresClosure *pg,
}
/**
* Function called with profit_drains records to insert into table.
*
* @param pg plugin context
* @param td record to insert
*/
static enum GNUNET_DB_QueryStatus
irbt_cb_table_profit_drains (struct PostgresClosure *pg,
const struct TALER_EXCHANGEDB_TableData *td)
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint64 (&td->serial),
GNUNET_PQ_query_param_auto_from_type (
&td->details.profit_drains.wtid),
GNUNET_PQ_query_param_string (
td->details.profit_drains.account_section),
GNUNET_PQ_query_param_string (
td->details.profit_drains.payto_uri),
GNUNET_PQ_query_param_timestamp (
&td->details.profit_drains.trigger_date),
TALER_PQ_query_param_amount (
&td->details.profit_drains.amount),
GNUNET_PQ_query_param_auto_from_type (
&td->details.profit_drains.master_sig),
GNUNET_PQ_query_param_end
};
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"insert_into_table_profit_drains",
params);
}
/* end of irbt_callbacks.c */

View File

@ -2120,4 +2120,65 @@ lrbt_cb_table_wads_in_entries (void *cls,
}
/**
* Function called with profit_drains table entries.
*
* @param cls closure
* @param result the postgres result
* @param num_results the number of results in @a result
*/
static void
lrbt_cb_table_profit_drains (void *cls,
PGresult *result,
unsigned int num_results)
{
struct LookupRecordsByTableContext *ctx = cls;
struct PostgresClosure *pg = ctx->pg;
struct TALER_EXCHANGEDB_TableData td = {
.table = TALER_EXCHANGEDB_RT_PROFIT_DRAINS
};
for (unsigned int i = 0; i<num_results; i++)
{
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint64 (
"profit_drain_serial_id",
&td.serial),
GNUNET_PQ_result_spec_auto_from_type (
"wtid",
&td.details.profit_drains.wtid),
GNUNET_PQ_result_spec_string (
"account_section",
&td.details.profit_drains.account_section),
GNUNET_PQ_result_spec_string (
"payto_uri",
&td.details.profit_drains.payto_uri),
GNUNET_PQ_result_spec_timestamp (
"trigger_date",
&td.details.profit_drains.trigger_date),
TALER_PQ_RESULT_SPEC_AMOUNT (
"amount",
&td.details.profit_drains.amount),
GNUNET_PQ_result_spec_auto_from_type (
"master_sig",
&td.details.profit_drains.master_sig),
GNUNET_PQ_result_spec_end
};
if (GNUNET_OK !=
GNUNET_PQ_extract_result (result,
rs,
i))
{
GNUNET_break (0);
ctx->error = true;
return;
}
ctx->cb (ctx->cb_cls,
&td);
GNUNET_PQ_cleanup_result (rs);
}
}
/* end of lrbt_callbacks.c */

View File

@ -3149,6 +3149,14 @@ prepare_statements (struct PostgresClosure *pg)
" ORDER BY wad_in_entry_serial_id DESC"
" LIMIT 1;",
0),
GNUNET_PQ_make_prepare (
"select_serial_by_table_profit_drains",
"SELECT"
" profit_drain_serial_id AS serial"
" FROM profit_drains"
" ORDER BY profit_drain_serial_id DESC"
" LIMIT 1;",
0),
/* For postgres_lookup_records_by_table */
GNUNET_PQ_make_prepare (
"select_above_serial_by_table_denominations",
@ -3652,6 +3660,21 @@ prepare_statements (struct PostgresClosure *pg)
" WHERE wad_in_entry_serial_id > $1"
" ORDER BY wad_in_entry_serial_id ASC;",
1),
GNUNET_PQ_make_prepare (
"select_above_serial_by_table_profit_drains",
"SELECT"
" profit_drain_serial_id"
",wtid"
",account_section"
",payto_uri"
",trigger_date"
",amount_val"
",amount_frac"
",master_sig"
" FROM profit_drains"
" WHERE profit_drain_serial_id > $1"
" ORDER BY profit_drain_serial_id ASC;",
1),
/* For postgres_insert_records_by_table */
GNUNET_PQ_make_prepare (
"insert_into_table_denominations",
@ -4128,7 +4151,21 @@ prepare_statements (struct PostgresClosure *pg)
",purse_sig"
") VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);",
3),
15),
GNUNET_PQ_make_prepare (
"insert_into_table_profit_drains",
"INSERT INTO profit_drains"
"(profit_drain_serial_id"
",wtid"
",account_section"
",payto_uri"
",trigger_date"
",amount_val"
",amount_frac"
",master_sig"
") VALUES "
"($1, $2, $3, $4, $5, $6, $7, $8);",
8),
/* Used in #postgres_begin_shard() */
GNUNET_PQ_make_prepare (
@ -14253,6 +14290,9 @@ postgres_lookup_serial_by_table (void *cls,
case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
statement = "select_serial_by_table_wads_in_entries";
break;
case TALER_EXCHANGEDB_RT_PROFIT_DRAINS:
statement = "select_serial_by_table_profit_drains";
break;
default:
GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR;
@ -14474,6 +14514,10 @@ postgres_lookup_records_by_table (void *cls,
statement = "select_above_serial_by_table_wads_in_entries";
rh = &lrbt_cb_table_wads_in_entries;
break;
case TALER_EXCHANGEDB_RT_PROFIT_DRAINS:
statement = "select_above_serial_by_table_profit_drains";
rh = &lrbt_cb_table_profit_drains;
break;
default:
GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR;
@ -14641,6 +14685,9 @@ postgres_insert_records_by_table (void *cls,
case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
rh = &irbt_cb_table_wads_in_entries;
break;
case TALER_EXCHANGEDB_RT_PROFIT_DRAINS:
rh = &irbt_cb_table_profit_drains;
break;
default:
GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR;

View File

@ -228,6 +228,7 @@ enum TALER_EXCHANGEDB_ReplicatedTable
TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES,
TALER_EXCHANGEDB_RT_WADS_IN,
TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES,
TALER_EXCHANGEDB_RT_PROFIT_DRAINS,
};
@ -588,6 +589,17 @@ struct TALER_EXCHANGEDB_TableData
struct TALER_PurseContractSignatureP purse_sig;
} wads_in_entries;
struct
{
uint64_t profit_drain_serial_id;
struct TALER_WireTransferIdentifierRawP wtid;
char *account_section;
char *payto_uri;
struct GNUNET_TIME_Timestamp trigger_date;
struct TALER_Amount amount;
struct TALER_MasterSignatureP master_sig;
} profit_drains;
} details;
};