diff options
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 10 | ||||
-rw-r--r-- | src/exchangedb/procedures.sql | 29 |
2 files changed, 18 insertions, 21 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 39c1be4bf..e593b0df9 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -4450,10 +4450,9 @@ prepare_statements (struct PostgresClosure *pg) "SELECT" " out_no_partner AS no_partner" ",out_no_balance AS no_balance" - ",out_no_reserve AS no_reserve" ",out_conflict AS conflict" " FROM exchange_do_purse_merge" - " ($1, $2, $3, $4, $5, $6, $7);", + " ($1, $2, $3, $4, $5, $6, $7, $8);", 7), /* Used in #postgres_do_reserve_purse() */ GNUNET_PQ_make_prepare ( @@ -16007,7 +16006,6 @@ postgres_get_purse_deposit ( * @param reserve_pub public key of the reserve to credit * @param[out] no_partner set to true if @a partner_url is unknown * @param[out] no_balance set to true if the @a purse_pub is not paid up yet - * @param[out] no_reserve set to true if the @a reserve_pub is not known * @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already * @return transaction status code */ @@ -16022,11 +16020,12 @@ postgres_do_purse_merge ( const struct TALER_ReservePublicKeyP *reserve_pub, bool *no_partner, bool *no_balance, - bool *no_reserve, bool *in_conflict) { struct PostgresClosure *pg = cls; struct TALER_PaytoHashP h_payto; + struct GNUNET_TIME_Timestamp expiration + = GNUNET_TIME_relative_to_timestamp (GNUNET_TIME_UNIT_YEARS); /* FIXME: make this configurable? */ struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (purse_pub), GNUNET_PQ_query_param_auto_from_type (merge_sig), @@ -16037,6 +16036,7 @@ postgres_do_purse_merge ( : GNUNET_PQ_query_param_string (partner_url), GNUNET_PQ_query_param_auto_from_type (reserve_pub), GNUNET_PQ_query_param_auto_from_type (&h_payto), + GNUNET_PQ_query_param_timestamp (&expiration), GNUNET_PQ_query_param_end }; struct GNUNET_PQ_ResultSpec rs[] = { @@ -16044,8 +16044,6 @@ postgres_do_purse_merge ( no_partner), GNUNET_PQ_result_spec_bool ("no_balance", no_balance), - GNUNET_PQ_result_spec_bool ("no_reserve", - no_reserve), GNUNET_PQ_result_spec_bool ("conflict", in_conflict), GNUNET_PQ_result_spec_end diff --git a/src/exchangedb/procedures.sql b/src/exchangedb/procedures.sql index 28a074b45..0c21ae41f 100644 --- a/src/exchangedb/procedures.sql +++ b/src/exchangedb/procedures.sql @@ -1606,9 +1606,9 @@ CREATE OR REPLACE FUNCTION exchange_do_purse_merge( IN in_partner_url VARCHAR, IN in_reserve_pub BYTEA, IN in_wallet_h_payto BYTEA, + IN in_expiration_date INT8, OUT out_no_partner BOOLEAN, OUT out_no_balance BOOLEAN, - OUT out_no_reserve BOOLEAN, OUT out_conflict BOOLEAN) LANGUAGE plpgsql AS $$ @@ -1642,7 +1642,6 @@ ELSE THEN out_no_partner=TRUE; out_conflict=FALSE; - out_no_reserve=FALSE; RETURN; END IF; END IF; @@ -1670,7 +1669,6 @@ IF NOT FOUND THEN out_no_balance=TRUE; out_conflict=FALSE; - out_no_reserve=FALSE; RETURN; END IF; out_no_balance=FALSE; @@ -1703,29 +1701,30 @@ THEN THEN -- Purse was merged, but to some other reserve. Not allowed. out_conflict=TRUE; - out_no_reserve=FALSE; RETURN; END IF; -- "success" out_conflict=FALSE; - out_no_reserve=FALSE; RETURN; END IF; out_conflict=FALSE; ASSERT NOT my_finished, 'internal invariant failed'; -PERFORM - FROM exchange.reserves - WHERE reserve_pub=in_reserve_pub; -IF NOT FOUND -THEN - out_no_reserve=TRUE; - RETURN; -END IF; -out_no_reserve=FALSE; +-- Initialize reserve, if not yet exists. +INSERT INTO reserves + (reserve_pub + ,expiration_date + ,gc_date) + VALUES + (in_reserve_pub + ,in_expiration_date + ,in_expiration_date) + ON CONFLICT DO NOTHING; + + -- Store account merge signature. @@ -1785,7 +1784,7 @@ RETURN; END $$; -COMMENT ON FUNCTION exchange_do_purse_merge(BYTEA, BYTEA, INT8, BYTEA, VARCHAR, BYTEA, BYTEA) +COMMENT ON FUNCTION exchange_do_purse_merge(BYTEA, BYTEA, INT8, BYTEA, VARCHAR, BYTEA, BYTEA, INT8) IS 'Checks that the partner exists, the purse has not been merged with a different reserve and that the purse is full. If so, persists the merge data and either merges the purse with the reserve or marks it as ready for the taler-exchange-router. Caller MUST abort the transaction on failures so as to not persist data by accident.'; |