-implement DB logic for forcing reserve close
This commit is contained in:
parent
e68206b1f9
commit
615b4621e3
@ -3605,6 +3605,7 @@ END $$;
|
|||||||
|
|
||||||
CREATE OR REPLACE FUNCTION exchange_do_close_request(
|
CREATE OR REPLACE FUNCTION exchange_do_close_request(
|
||||||
IN in_reserve_pub BYTEA,
|
IN in_reserve_pub BYTEA,
|
||||||
|
IN in_close_timestamp INT8,
|
||||||
IN in_reserve_sig BYTEA,
|
IN in_reserve_sig BYTEA,
|
||||||
OUT out_final_balance_val INT8,
|
OUT out_final_balance_val INT8,
|
||||||
OUT out_final_balance_frac INT4,
|
OUT out_final_balance_frac INT4,
|
||||||
@ -3613,7 +3614,45 @@ CREATE OR REPLACE FUNCTION exchange_do_close_request(
|
|||||||
LANGUAGE plpgsql
|
LANGUAGE plpgsql
|
||||||
AS $$
|
AS $$
|
||||||
BEGIN
|
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 $$;
|
END $$;
|
||||||
|
|
||||||
|
|
||||||
|
@ -741,22 +741,6 @@ prepare_statements (struct PostgresClosure *pg)
|
|||||||
") VALUES ($1, $2, $3, $4, $5, $6, $7)"
|
") VALUES ($1, $2, $3, $4, $5, $6, $7)"
|
||||||
" ON CONFLICT DO NOTHING;",
|
" ON CONFLICT DO NOTHING;",
|
||||||
7),
|
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
|
/* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound
|
||||||
transactions for reserves with serial id '\geq' the given parameter */
|
transactions for reserves with serial id '\geq' the given parameter */
|
||||||
GNUNET_PQ_make_prepare (
|
GNUNET_PQ_make_prepare (
|
||||||
@ -4268,8 +4252,8 @@ prepare_statements (struct PostgresClosure *pg)
|
|||||||
" out_final_balance_val"
|
" out_final_balance_val"
|
||||||
",out_final_balance_frac"
|
",out_final_balance_frac"
|
||||||
" FROM exchange_do_close_request"
|
" FROM exchange_do_close_request"
|
||||||
" ($1, $2)",
|
" ($1, $2, $3)",
|
||||||
2),
|
3),
|
||||||
|
|
||||||
GNUNET_PQ_PREPARED_STATEMENT_END
|
GNUNET_PQ_PREPARED_STATEMENT_END
|
||||||
};
|
};
|
||||||
@ -15868,28 +15852,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
|
* Function called to persist a signature that
|
||||||
* prove that the client requested an
|
* prove that the client requested an
|
||||||
@ -15953,10 +15915,26 @@ postgres_insert_close_request (
|
|||||||
void *cls,
|
void *cls,
|
||||||
const struct TALER_ReservePublicKeyP *reserve_pub,
|
const struct TALER_ReservePublicKeyP *reserve_pub,
|
||||||
const struct TALER_ReserveSignatureP *reserve_sig,
|
const struct TALER_ReserveSignatureP *reserve_sig,
|
||||||
|
struct GNUNET_TIME_Timestamp request_timestamp,
|
||||||
struct TALER_Amount *final_balance)
|
struct TALER_Amount *final_balance)
|
||||||
{
|
{
|
||||||
GNUNET_break (0); // FIXME
|
struct PostgresClosure *pg = cls;
|
||||||
return GNUNET_DB_STATUS_HARD_ERROR;
|
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;
|
= &postgres_do_reserve_purse;
|
||||||
plugin->select_purse_merge
|
plugin->select_purse_merge
|
||||||
= &postgres_select_purse_merge;
|
= &postgres_select_purse_merge;
|
||||||
plugin->do_account_merge
|
|
||||||
= &postgres_do_account_merge;
|
|
||||||
plugin->insert_history_request
|
plugin->insert_history_request
|
||||||
= &postgres_insert_history_request;
|
= &postgres_insert_history_request;
|
||||||
plugin->insert_close_request
|
plugin->insert_close_request
|
||||||
|
@ -5462,24 +5462,6 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
struct TALER_ReservePublicKeyP *reserve_pub);
|
struct TALER_ReservePublicKeyP *reserve_pub);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
enum GNUNET_DB_QueryStatus
|
|
||||||
(*do_account_merge)(
|
|
||||||
void *cls,
|
|
||||||
const struct TALER_PurseContractPublicKeyP *purse_pub,
|
|
||||||
const struct TALER_ReservePublicKeyP *reserve_pub,
|
|
||||||
const struct TALER_ReserveSignatureP *reserve_sig);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function called to persist a signature that
|
* Function called to persist a signature that
|
||||||
* prove that the client requested an
|
* prove that the client requested an
|
||||||
@ -5513,6 +5495,7 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
* @param cls the @e cls of this struct with the plugin-specific state
|
* @param cls the @e cls of this struct with the plugin-specific state
|
||||||
* @param reserve_pub public key of the account to close
|
* @param reserve_pub public key of the account to close
|
||||||
* @param reserve_sig signature affiming that the account is to be closed
|
* @param reserve_sig signature affiming that the account is to be closed
|
||||||
|
* @param request_timestamp timestamp of the close request
|
||||||
* @param[out] final_balance set to the final balance in the account that will be wired back to the origin account
|
* @param[out] final_balance set to the final balance in the account that will be wired back to the origin account
|
||||||
* @return transaction status code
|
* @return transaction status code
|
||||||
*/
|
*/
|
||||||
@ -5520,6 +5503,7 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
(*insert_close_request)(void *cls,
|
(*insert_close_request)(void *cls,
|
||||||
const struct TALER_ReservePublicKeyP *reserve_pub,
|
const struct TALER_ReservePublicKeyP *reserve_pub,
|
||||||
const struct TALER_ReserveSignatureP *reserve_sig,
|
const struct TALER_ReserveSignatureP *reserve_sig,
|
||||||
|
struct GNUNET_TIME_Timestamp request_timestamp,
|
||||||
struct TALER_Amount *final_balance);
|
struct TALER_Amount *final_balance);
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user