aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb/plugin_exchangedb_postgres.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchangedb/plugin_exchangedb_postgres.c')
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c62
1 files changed, 52 insertions, 10 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 5bd674b2d..93577feb4 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -796,7 +796,7 @@ postgres_get_session (void *cls)
796 "(coin_pub" 796 "(coin_pub"
797 ",amount_with_fee_val" 797 ",amount_with_fee_val"
798 ",amount_with_fee_frac" 798 ",amount_with_fee_frac"
799 ",timestamp" 799 ",wallet_timestamp"
800 ",refund_deadline" 800 ",refund_deadline"
801 ",wire_deadline" 801 ",wire_deadline"
802 ",merchant_pub" 802 ",merchant_pub"
@@ -804,22 +804,28 @@ postgres_get_session (void *cls)
804 ",h_wire" 804 ",h_wire"
805 ",coin_sig" 805 ",coin_sig"
806 ",wire" 806 ",wire"
807 ",exchange_timestamp"
807 ") VALUES " 808 ") VALUES "
808 "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10," 809 "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
809 " $11);", 810 " $11, $12);",
810 11), 811 12),
811 /* Fetch an existing deposit request, used to ensure idempotency 812 /* Fetch an existing deposit request, used to ensure idempotency
812 during /deposit processing. Used in #postgres_have_deposit(). */ 813 during /deposit processing. Used in #postgres_have_deposit(). */
813 GNUNET_PQ_make_prepare ("get_deposit", 814 GNUNET_PQ_make_prepare ("get_deposit",
814 "SELECT" 815 "SELECT"
815 " amount_with_fee_val" 816 " amount_with_fee_val"
816 ",amount_with_fee_frac" 817 ",amount_with_fee_frac"
817 ",timestamp" 818 ",denominations.fee_deposit_val"
819 ",denominations.fee_deposit_frac"
820 ",wallet_timestamp"
821 ",exchange_timestamp"
818 ",refund_deadline" 822 ",refund_deadline"
819 ",wire_deadline" 823 ",wire_deadline"
820 ",h_contract_terms" 824 ",h_contract_terms"
821 ",h_wire" 825 ",h_wire"
822 " FROM deposits" 826 " FROM deposits"
827 " JOIN known_coins USING (coin_pub)"
828 " JOIN denominations USING (denom_pub_hash)"
823 " WHERE ((coin_pub=$1)" 829 " WHERE ((coin_pub=$1)"
824 " AND (merchant_pub=$3)" 830 " AND (merchant_pub=$3)"
825 " AND (h_contract_terms=$2))" 831 " AND (h_contract_terms=$2))"
@@ -830,7 +836,8 @@ postgres_get_session (void *cls)
830 "SELECT" 836 "SELECT"
831 " amount_with_fee_val" 837 " amount_with_fee_val"
832 ",amount_with_fee_frac" 838 ",amount_with_fee_frac"
833 ",timestamp" 839 ",wallet_timestamp"
840 ",exchange_timestamp"
834 ",merchant_pub" 841 ",merchant_pub"
835 ",denom.denom_pub" 842 ",denom.denom_pub"
836 ",coin_pub" 843 ",coin_pub"
@@ -881,6 +888,8 @@ postgres_get_session (void *cls)
881 ",wire" 888 ",wire"
882 ",merchant_pub" 889 ",merchant_pub"
883 ",coin_pub" 890 ",coin_pub"
891 ",exchange_timestamp"
892 ",wallet_timestamp"
884 " FROM deposits" 893 " FROM deposits"
885 " JOIN known_coins USING (coin_pub)" 894 " JOIN known_coins USING (coin_pub)"
886 " JOIN denominations denom USING (denom_pub_hash)" 895 " JOIN denominations denom USING (denom_pub_hash)"
@@ -900,6 +909,8 @@ postgres_get_session (void *cls)
900 ",denom.fee_deposit_val" 909 ",denom.fee_deposit_val"
901 ",denom.fee_deposit_frac" 910 ",denom.fee_deposit_frac"
902 ",wire_deadline" 911 ",wire_deadline"
912 ",exchange_timestamp"
913 ",wallet_timestamp"
903 ",h_contract_terms" 914 ",h_contract_terms"
904 ",coin_pub" 915 ",coin_pub"
905 " FROM deposits" 916 " FROM deposits"
@@ -945,7 +956,7 @@ postgres_get_session (void *cls)
945 ",amount_with_fee_frac" 956 ",amount_with_fee_frac"
946 ",denom.fee_deposit_val" 957 ",denom.fee_deposit_val"
947 ",denom.fee_deposit_frac" 958 ",denom.fee_deposit_frac"
948 ",timestamp" 959 ",wallet_timestamp"
949 ",refund_deadline" 960 ",refund_deadline"
950 ",wire_deadline" 961 ",wire_deadline"
951 ",merchant_pub" 962 ",merchant_pub"
@@ -2571,6 +2582,8 @@ postgres_get_reserve_history (void *cls,
2571 * @param session database connection 2582 * @param session database connection
2572 * @param deposit deposit to search for 2583 * @param deposit deposit to search for
2573 * @param check_extras whether to check extra fields match or not 2584 * @param check_extras whether to check extra fields match or not
2585 * @param[out] deposit_fee set to the deposit fee the exchange charged
2586 * @param[out] exchange_timestamp set to the time when the exchange received the deposit
2574 * @return 1 if we know this operation, 2587 * @return 1 if we know this operation,
2575 * 0 if this exact deposit is unknown to us, 2588 * 0 if this exact deposit is unknown to us,
2576 * otherwise transaction error status 2589 * otherwise transaction error status
@@ -2579,7 +2592,9 @@ static enum GNUNET_DB_QueryStatus
2579postgres_have_deposit (void *cls, 2592postgres_have_deposit (void *cls,
2580 struct TALER_EXCHANGEDB_Session *session, 2593 struct TALER_EXCHANGEDB_Session *session,
2581 const struct TALER_EXCHANGEDB_Deposit *deposit, 2594 const struct TALER_EXCHANGEDB_Deposit *deposit,
2582 int check_extras) 2595 int check_extras,
2596 struct TALER_Amount *deposit_fee,
2597 struct GNUNET_TIME_Absolute *exchange_timestamp)
2583{ 2598{
2584 struct PostgresClosure *pg = cls; 2599 struct PostgresClosure *pg = cls;
2585 struct GNUNET_PQ_QueryParam params[] = { 2600 struct GNUNET_PQ_QueryParam params[] = {
@@ -2592,12 +2607,16 @@ postgres_have_deposit (void *cls,
2592 struct GNUNET_PQ_ResultSpec rs[] = { 2607 struct GNUNET_PQ_ResultSpec rs[] = {
2593 TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", 2608 TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
2594 &deposit2.amount_with_fee), 2609 &deposit2.amount_with_fee),
2595 TALER_PQ_result_spec_absolute_time ("timestamp", 2610 TALER_PQ_result_spec_absolute_time ("wallet_timestamp",
2596 &deposit2.timestamp), 2611 &deposit2.timestamp),
2612 TALER_PQ_result_spec_absolute_time ("exchange_timestamp",
2613 exchange_timestamp),
2597 TALER_PQ_result_spec_absolute_time ("refund_deadline", 2614 TALER_PQ_result_spec_absolute_time ("refund_deadline",
2598 &deposit2.refund_deadline), 2615 &deposit2.refund_deadline),
2599 TALER_PQ_result_spec_absolute_time ("wire_deadline", 2616 TALER_PQ_result_spec_absolute_time ("wire_deadline",
2600 &deposit2.wire_deadline), 2617 &deposit2.wire_deadline),
2618 TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
2619 deposit_fee),
2601 GNUNET_PQ_result_spec_auto_from_type ("h_wire", 2620 GNUNET_PQ_result_spec_auto_from_type ("h_wire",
2602 &deposit2.h_wire), 2621 &deposit2.h_wire),
2603 GNUNET_PQ_result_spec_end 2622 GNUNET_PQ_result_spec_end
@@ -2776,6 +2795,8 @@ postgres_get_ready_deposit (void *cls,
2776 struct TALER_Amount amount_with_fee; 2795 struct TALER_Amount amount_with_fee;
2777 struct TALER_Amount deposit_fee; 2796 struct TALER_Amount deposit_fee;
2778 struct GNUNET_TIME_Absolute wire_deadline; 2797 struct GNUNET_TIME_Absolute wire_deadline;
2798 struct GNUNET_TIME_Absolute wallet_timestamp;
2799 struct GNUNET_TIME_Absolute exchange_timestamp;
2779 struct GNUNET_HashCode h_contract_terms; 2800 struct GNUNET_HashCode h_contract_terms;
2780 struct TALER_MerchantPublicKeyP merchant_pub; 2801 struct TALER_MerchantPublicKeyP merchant_pub;
2781 struct TALER_CoinSpendPublicKeyP coin_pub; 2802 struct TALER_CoinSpendPublicKeyP coin_pub;
@@ -2788,6 +2809,10 @@ postgres_get_ready_deposit (void *cls,
2788 &amount_with_fee), 2809 &amount_with_fee),
2789 TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", 2810 TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
2790 &deposit_fee), 2811 &deposit_fee),
2812 TALER_PQ_result_spec_absolute_time ("exchange_timestamp",
2813 &exchange_timestamp),
2814 TALER_PQ_result_spec_absolute_time ("wallet_timestamp",
2815 &wallet_timestamp),
2791 TALER_PQ_result_spec_absolute_time ("wire_deadline", 2816 TALER_PQ_result_spec_absolute_time ("wire_deadline",
2792 &wire_deadline), 2817 &wire_deadline),
2793 GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", 2818 GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
@@ -2817,6 +2842,8 @@ postgres_get_ready_deposit (void *cls,
2817 2842
2818 qs = deposit_cb (deposit_cb_cls, 2843 qs = deposit_cb (deposit_cb_cls,
2819 serial_id, 2844 serial_id,
2845 exchange_timestamp,
2846 wallet_timestamp,
2820 &merchant_pub, 2847 &merchant_pub,
2821 &coin_pub, 2848 &coin_pub,
2822 &amount_with_fee, 2849 &amount_with_fee,
@@ -2898,6 +2925,8 @@ match_deposit_cb (void *cls,
2898 { 2925 {
2899 struct TALER_Amount amount_with_fee; 2926 struct TALER_Amount amount_with_fee;
2900 struct TALER_Amount deposit_fee; 2927 struct TALER_Amount deposit_fee;
2928 struct GNUNET_TIME_Absolute exchange_timestamp;
2929 struct GNUNET_TIME_Absolute wallet_timestamp;
2901 struct GNUNET_TIME_Absolute wire_deadline; 2930 struct GNUNET_TIME_Absolute wire_deadline;
2902 struct GNUNET_HashCode h_contract_terms; 2931 struct GNUNET_HashCode h_contract_terms;
2903 struct TALER_CoinSpendPublicKeyP coin_pub; 2932 struct TALER_CoinSpendPublicKeyP coin_pub;
@@ -2912,6 +2941,10 @@ match_deposit_cb (void *cls,
2912 &deposit_fee), 2941 &deposit_fee),
2913 TALER_PQ_result_spec_absolute_time ("wire_deadline", 2942 TALER_PQ_result_spec_absolute_time ("wire_deadline",
2914 &wire_deadline), 2943 &wire_deadline),
2944 TALER_PQ_result_spec_absolute_time ("exchange_timestamp",
2945 &exchange_timestamp),
2946 TALER_PQ_result_spec_absolute_time ("wallet_timestamp",
2947 &wallet_timestamp),
2915 GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms", 2948 GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
2916 &h_contract_terms), 2949 &h_contract_terms),
2917 GNUNET_PQ_result_spec_auto_from_type ("coin_pub", 2950 GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
@@ -2930,6 +2963,8 @@ match_deposit_cb (void *cls,
2930 } 2963 }
2931 qs = mdc->deposit_cb (mdc->deposit_cb_cls, 2964 qs = mdc->deposit_cb (mdc->deposit_cb_cls,
2932 serial_id, 2965 serial_id,
2966 exchange_timestamp,
2967 wallet_timestamp,
2933 mdc->merchant_pub, 2968 mdc->merchant_pub,
2934 &coin_pub, 2969 &coin_pub,
2935 &amount_with_fee, 2970 &amount_with_fee,
@@ -3210,12 +3245,14 @@ postgres_ensure_coin_known (void *cls,
3210 * 3245 *
3211 * @param cls the `struct PostgresClosure` with the plugin-specific state 3246 * @param cls the `struct PostgresClosure` with the plugin-specific state
3212 * @param session connection to the database 3247 * @param session connection to the database
3248 * @param exchange_timestamp time the exchange received the deposit request
3213 * @param deposit deposit information to store 3249 * @param deposit deposit information to store
3214 * @return query result status 3250 * @return query result status
3215 */ 3251 */
3216static enum GNUNET_DB_QueryStatus 3252static enum GNUNET_DB_QueryStatus
3217postgres_insert_deposit (void *cls, 3253postgres_insert_deposit (void *cls,
3218 struct TALER_EXCHANGEDB_Session *session, 3254 struct TALER_EXCHANGEDB_Session *session,
3255 struct GNUNET_TIME_Absolute exchange_timestamp,
3219 const struct TALER_EXCHANGEDB_Deposit *deposit) 3256 const struct TALER_EXCHANGEDB_Deposit *deposit)
3220{ 3257{
3221 struct GNUNET_PQ_QueryParam params[] = { 3258 struct GNUNET_PQ_QueryParam params[] = {
@@ -3229,6 +3266,7 @@ postgres_insert_deposit (void *cls,
3229 GNUNET_PQ_query_param_auto_from_type (&deposit->h_wire), 3266 GNUNET_PQ_query_param_auto_from_type (&deposit->h_wire),
3230 GNUNET_PQ_query_param_auto_from_type (&deposit->csig), 3267 GNUNET_PQ_query_param_auto_from_type (&deposit->csig),
3231 TALER_PQ_query_param_json (deposit->receiver_wire_account), 3268 TALER_PQ_query_param_json (deposit->receiver_wire_account),
3269 TALER_PQ_query_param_absolute_time (&exchange_timestamp),
3232 GNUNET_PQ_query_param_end 3270 GNUNET_PQ_query_param_end
3233 }; 3271 };
3234 3272
@@ -4042,7 +4080,7 @@ add_coin_deposit (void *cls,
4042 &deposit->amount_with_fee), 4080 &deposit->amount_with_fee),
4043 TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit", 4081 TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
4044 &deposit->deposit_fee), 4082 &deposit->deposit_fee),
4045 TALER_PQ_result_spec_absolute_time ("timestamp", 4083 TALER_PQ_result_spec_absolute_time ("wallet_timestamp",
4046 &deposit->timestamp), 4084 &deposit->timestamp),
4047 TALER_PQ_result_spec_absolute_time ("refund_deadline", 4085 TALER_PQ_result_spec_absolute_time ("refund_deadline",
4048 &deposit->refund_deadline), 4086 &deposit->refund_deadline),
@@ -5462,14 +5500,17 @@ deposit_serial_helper_cb (void *cls,
5462 for (unsigned int i = 0; i<num_results; i++) 5500 for (unsigned int i = 0; i<num_results; i++)
5463 { 5501 {
5464 struct TALER_EXCHANGEDB_Deposit deposit; 5502 struct TALER_EXCHANGEDB_Deposit deposit;
5503 struct GNUNET_TIME_Absolute exchange_timestamp;
5465 struct TALER_DenominationPublicKey denom_pub; 5504 struct TALER_DenominationPublicKey denom_pub;
5466 uint8_t done = 0; 5505 uint8_t done = 0;
5467 uint64_t rowid; 5506 uint64_t rowid;
5468 struct GNUNET_PQ_ResultSpec rs[] = { 5507 struct GNUNET_PQ_ResultSpec rs[] = {
5469 TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee", 5508 TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
5470 &deposit.amount_with_fee), 5509 &deposit.amount_with_fee),
5471 TALER_PQ_result_spec_absolute_time ("timestamp", 5510 TALER_PQ_result_spec_absolute_time ("wallet_timestamp",
5472 &deposit.timestamp), 5511 &deposit.timestamp),
5512 TALER_PQ_result_spec_absolute_time ("exchange_timestamp",
5513 &exchange_timestamp),
5473 GNUNET_PQ_result_spec_auto_from_type ("merchant_pub", 5514 GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
5474 &deposit.merchant_pub), 5515 &deposit.merchant_pub),
5475 GNUNET_PQ_result_spec_rsa_public_key ("denom_pub", 5516 GNUNET_PQ_result_spec_rsa_public_key ("denom_pub",
@@ -5505,6 +5546,7 @@ deposit_serial_helper_cb (void *cls,
5505 } 5546 }
5506 ret = dsc->cb (dsc->cb_cls, 5547 ret = dsc->cb (dsc->cb_cls,
5507 rowid, 5548 rowid,
5549 exchange_timestamp,
5508 deposit.timestamp, 5550 deposit.timestamp,
5509 &deposit.merchant_pub, 5551 &deposit.merchant_pub,
5510 &denom_pub, 5552 &denom_pub,