diff options
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/exchange-0001-part.sql | 41 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 64 |
2 files changed, 60 insertions, 45 deletions
diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql index cc34b6be3..e24129957 100644 --- a/src/exchangedb/exchange-0001-part.sql +++ b/src/exchangedb/exchange-0001-part.sql @@ -3605,6 +3605,7 @@ END $$; CREATE OR REPLACE FUNCTION exchange_do_close_request( IN in_reserve_pub BYTEA, + IN in_close_timestamp INT8, IN in_reserve_sig BYTEA, OUT out_final_balance_val INT8, OUT out_final_balance_frac INT4, @@ -3613,7 +3614,45 @@ CREATE OR REPLACE FUNCTION exchange_do_close_request( LANGUAGE plpgsql AS $$ BEGIN - -- FIXME + + SELECT + current_balance_val + ,current_balance_frac + INTO + out_final_balance_val + ,out_final_balance_frac + FROM reserves + WHERE reserve_pub=in_reserve_pub; + + IF NOT FOUND + THEN + out_final_balance_val=0; + out_final_balance_frac=0; + out_balance_ok = FALSE; + out_conflict = FALSE; + END IF; + + INSERT INTO close_requests + (reserve_pub + ,close_timestamp + ,reserve_sig + ,close_val + ,close_frac) + VALUES + (in_reserve_pub + ,in_close_timestamp + ,in_reserve_sig + ,out_final_balance_val + ,out_final_balance_frac) + ON CONFLICT DO NOTHING; + out_conflict = NOT FOUND; + + UPDATE reserves SET + current_balance_val=0 + ,current_balance_frac=0 + WHERE reserve_pub=in_reserve_pub; + out_balance_ok = TRUE; + END $$; diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 5985fa95d..cbacebbd6 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -741,22 +741,6 @@ prepare_statements (struct PostgresClosure *pg) ") VALUES ($1, $2, $3, $4, $5, $6, $7)" " ON CONFLICT DO NOTHING;", 7), -#if FIXME_DEAD - /* Used in #postgres_reserves_in_insert() to store transaction details */ - GNUNET_PQ_make_prepare ( - "reserves_in_add_by_pub", - "INSERT INTO reserves_in " - "(reserve_pub" - ",wire_reference" - ",credit_val" - ",credit_frac" - ",exchange_account_section" - ",wire_source_h_payto" - ",execution_date" - ") VALUES ($1, $2, $3, $4, $5, $6, $7)" - " ON CONFLICT DO NOTHING;", - 7), -#endif /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound transactions for reserves with serial id '\geq' the given parameter */ GNUNET_PQ_make_prepare ( @@ -4268,8 +4252,8 @@ prepare_statements (struct PostgresClosure *pg) " out_final_balance_val" ",out_final_balance_frac" " FROM exchange_do_close_request" - " ($1, $2)", - 2), + " ($1, $2, $3)", + 3), GNUNET_PQ_PREPARED_STATEMENT_END }; @@ -15869,28 +15853,6 @@ postgres_select_purse_merge ( /** - * Function called to approve merging of a purse with - * an account, made by the receiving account. - * - * @param cls the @e cls of this struct with the plugin-specific state - * @param purse_pub public key of the purse being merged - * @param reserve_pub public key of the account being credited - * @param reserve_sig signature of the account holder affirming the merge - * @return transaction status code - */ -static enum GNUNET_DB_QueryStatus -postgres_do_account_merge ( - void *cls, - const struct TALER_PurseContractPublicKeyP *purse_pub, - const struct TALER_ReservePublicKeyP *reserve_pub, - const struct TALER_ReserveSignatureP *reserve_sig) -{ - GNUNET_break (0); // FIXME: Function dead, eliminate? (DCE) - return GNUNET_DB_STATUS_HARD_ERROR; -} - - -/** * Function called to persist a signature that * prove that the client requested an * account history. Debits the @a history_fee from @@ -15953,10 +15915,26 @@ postgres_insert_close_request ( void *cls, const struct TALER_ReservePublicKeyP *reserve_pub, const struct TALER_ReserveSignatureP *reserve_sig, + struct GNUNET_TIME_Timestamp request_timestamp, struct TALER_Amount *final_balance) { - GNUNET_break (0); // FIXME - return GNUNET_DB_STATUS_HARD_ERROR; + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (reserve_pub), + GNUNET_PQ_query_param_timestamp (&request_timestamp), + GNUNET_PQ_query_param_auto_from_type (reserve_sig), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + TALER_PQ_RESULT_SPEC_AMOUNT ("out_final_balance", + final_balance), + GNUNET_PQ_result_spec_end + }; + + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "call_account_close", + params, + rs); } @@ -16272,8 +16250,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) = &postgres_do_reserve_purse; plugin->select_purse_merge = &postgres_select_purse_merge; - plugin->do_account_merge - = &postgres_do_account_merge; plugin->insert_history_request = &postgres_insert_history_request; plugin->insert_close_request |