diff options
Diffstat (limited to 'src/exchangedb/plugin_exchangedb_postgres.c')
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index d27ff7783..61b1bfb97 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -3525,6 +3525,15 @@ prepare_statements (struct PostgresClosure *pg) " FROM exchange_do_purse_merge" " ($1, $2, $3, $4, $5, $6);", 6), + /* Used in #postgres_do_reserve_purse() */ + GNUNET_PQ_make_prepare ( + "call_reserve_purse", + "SELECT" + " out_no_funds AS insufficient_funds" + ",out_conflict AS conflict" + " FROM exchange_do_reserve_purse" + " ($1, $2, $3, $4, $5, $6, $7);", + 7), /* Used in #postgres_select_purse_merge */ GNUNET_PQ_make_prepare ( "select_purse_merge", @@ -13562,6 +13571,59 @@ postgres_do_purse_merge ( /** + * Function called insert request to merge a purse into a reserve by the + * respective purse merge key. The purse must not have been merged into a + * different reserve. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param purse_pub purse to merge + * @param merge_sig signature affirming the merge + * @param merge_timestamp time of the merge + * @param reserve_sig signature of the reserve affirming the merge + * @param purse_fee amount to charge the reserve for the purse creation + * @param reserve_pub public key of the reserve to credit + * @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already + * @param[out] insufficient_funds set to true if @a reserve_pub has insufficient capacity to create another purse + * @return transaction status code + */ +static enum GNUNET_DB_QueryStatus +postgres_do_reserve_purse ( + void *cls, + const struct TALER_PurseContractPublicKeyP *purse_pub, + const struct TALER_PurseMergeSignatureP *merge_sig, + const struct GNUNET_TIME_Timestamp merge_timestamp, + const struct TALER_ReserveSignatureP *reserve_sig, + const struct TALER_Amount *purse_fee, + const struct TALER_ReservePublicKeyP *reserve_pub, + bool *in_conflict, + bool *insufficient_funds) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_auto_from_type (purse_pub), + GNUNET_PQ_query_param_auto_from_type (merge_sig), + GNUNET_PQ_query_param_timestamp (&merge_timestamp), + GNUNET_PQ_query_param_auto_from_type (reserve_sig), + TALER_PQ_query_param_amount (purse_fee), + GNUNET_PQ_query_param_auto_from_type (reserve_pub), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_bool ("insufficient_funds", + insufficient_funds), + GNUNET_PQ_result_spec_bool ("conflict", + in_conflict), + GNUNET_PQ_result_spec_end + }; + + return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "call_reserve_purse", + params, + rs); +} + + +/** * Function called to approve merging of a purse with * an account, made by the receiving account. * @@ -13967,6 +14029,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) = &postgres_get_purse_deposit; plugin->do_purse_merge = &postgres_do_purse_merge; + plugin->do_reserve_purse + = &postgres_do_reserve_purse; plugin->select_purse_merge = &postgres_select_purse_merge; plugin->do_account_merge |