aboutsummaryrefslogtreecommitdiff
path: root/src/mint/taler-mint-httpd_db.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mint/taler-mint-httpd_db.c')
-rw-r--r--src/mint/taler-mint-httpd_db.c79
1 files changed, 48 insertions, 31 deletions
diff --git a/src/mint/taler-mint-httpd_db.c b/src/mint/taler-mint-httpd_db.c
index f64e1508d..6dffbcd63 100644
--- a/src/mint/taler-mint-httpd_db.c
+++ b/src/mint/taler-mint-httpd_db.c
@@ -55,31 +55,35 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
55 const struct Deposit *deposit) 55 const struct Deposit *deposit)
56{ 56{
57 PGconn *db_conn; 57 PGconn *db_conn;
58 struct Deposit existing_deposit; 58 struct TALER_MINT_DB_TransactionList *tl;
59 int res;
60 59
61 if (NULL == (db_conn = TALER_MINT_DB_get_connection ())) 60 if (NULL == (db_conn = TALER_MINT_DB_get_connection ()))
62 { 61 {
63 GNUNET_break (0); 62 GNUNET_break (0);
64 return TALER_MINT_reply_internal_db_error (connection); 63 return TALER_MINT_reply_internal_db_error (connection);
65 } 64 }
66 res = TALER_MINT_DB_get_deposit (db_conn, 65 if (GNUNET_YES ==
67 &deposit->coin.coin_pub, 66 TALER_MINT_DB_have_deposit (db_conn,
68 &existing_deposit); 67 deposit))
69 if (GNUNET_YES == res) 68 {
69 return TALER_MINT_reply_deposit_success (connection,
70 &deposit->coin.coin_pub,
71 &deposit->h_wire,
72 &deposit->h_contract,
73 deposit->transaction_id,
74 &deposit->merchant_pub,
75 &deposit->amount);
76 }
77 if (GNUNET_OK !=
78 TALER_MINT_DB_transaction (db_conn))
79 {
80 GNUNET_break (0);
81 return TALER_MINT_reply_internal_db_error (connection);
82 }
83 tl = TALER_MINT_DB_get_coin_transactions (db_conn,
84 &deposit->coin.coin_pub);
85 if (NULL != tl)
70 { 86 {
71 // FIXME: memory leak
72 // FIXME: memcmp will not actually work here
73 if (0 == memcmp (&existing_deposit,
74 deposit,
75 sizeof (struct Deposit)))
76 return TALER_MINT_reply_deposit_success (connection,
77 &deposit->coin.coin_pub,
78 &deposit->h_wire,
79 &deposit->h_contract,
80 deposit->transaction_id,
81 &deposit->merchant_pub,
82 &deposit->amount);
83 // FIXME: in the future, check if there's enough credits 87 // FIXME: in the future, check if there's enough credits
84 // left on the coin. For now: refuse 88 // left on the coin. For now: refuse
85 // FIXME: return more information here 89 // FIXME: return more information here
@@ -87,15 +91,9 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
87 MHD_HTTP_FORBIDDEN, 91 MHD_HTTP_FORBIDDEN,
88 "{s:s}", 92 "{s:s}",
89 "error", 93 "error",
90 "double spending"); 94 "double spending");
91 } 95 }
92 96
93 if (GNUNET_SYSERR == res)
94 {
95 GNUNET_break (0);
96 /* FIXME: return error message to client via MHD! */
97 return MHD_NO;
98 }
99 97
100 { 98 {
101 struct KnownCoin known_coin; 99 struct KnownCoin known_coin;
@@ -153,6 +151,14 @@ TALER_MINT_db_execute_deposit (struct MHD_Connection *connection,
153} 151}
154 152
155 153
154
155
156
157
158
159
160
161
156/** 162/**
157 * Sign a reserve's status with the current signing key. 163 * Sign a reserve's status with the current signing key.
158 * FIXME: not sure why we do this. Should just return 164 * FIXME: not sure why we do this. Should just return
@@ -474,6 +480,7 @@ refresh_accept_melts (struct MHD_Connection *connection,
474 struct KnownCoin known_coin; 480 struct KnownCoin known_coin;
475 // money the customer gets by melting the current coin 481 // money the customer gets by melting the current coin
476 struct TALER_Amount coin_gain; 482 struct TALER_Amount coin_gain;
483 struct RefreshMelt melt;
477 484
478 dki = &(TALER_MINT_get_denom_key (key_state, 485 dki = &(TALER_MINT_get_denom_key (key_state,
479 coin_public_infos[i].denom_pub)->issue); 486 coin_public_infos[i].denom_pub)->issue);
@@ -523,10 +530,17 @@ refresh_accept_melts (struct MHD_Connection *connection,
523 return GNUNET_SYSERR; 530 return GNUNET_SYSERR;
524 } 531 }
525 532
533 // FIXME: test first if coin was already melted
534 // in this session, etc.
535
536 melt.coin = coin_public_infos[i];
537 melt.session_pub = *session_pub;
538 // melt.coin_sig = FIXME;
539 // melt.amount = FIXME;
540 melt.oldcoin_index = i;
526 if (GNUNET_OK != 541 if (GNUNET_OK !=
527 TALER_MINT_DB_insert_refresh_melt (db_conn, session_pub, i, 542 TALER_MINT_DB_insert_refresh_melt (db_conn,
528 &coin_public_infos[i].coin_pub, 543 &melt))
529 coin_public_infos[i].denom_pub))
530 { 544 {
531 GNUNET_break (0); 545 GNUNET_break (0);
532 return GNUNET_SYSERR; 546 return GNUNET_SYSERR;
@@ -934,9 +948,9 @@ TALER_MINT_db_execute_refresh_reveal (struct MHD_Connection *connection,
934 for (j = 0; j < refresh_session.num_oldcoins; j++) 948 for (j = 0; j < refresh_session.num_oldcoins; j++)
935 { 949 {
936 struct RefreshCommitLink commit_link; 950 struct RefreshCommitLink commit_link;
937 struct GNUNET_CRYPTO_EcdsaPublicKey coin_pub;
938 struct TALER_TransferSecret transfer_secret; 951 struct TALER_TransferSecret transfer_secret;
939 struct TALER_LinkSecret shared_secret; 952 struct TALER_LinkSecret shared_secret;
953 struct RefreshMelt melt;
940 954
941 res = TALER_MINT_DB_get_refresh_commit_link (db_conn, 955 res = TALER_MINT_DB_get_refresh_commit_link (db_conn,
942 refresh_session_pub, 956 refresh_session_pub,
@@ -949,7 +963,10 @@ TALER_MINT_db_execute_refresh_reveal (struct MHD_Connection *connection,
949 return MHD_NO; 963 return MHD_NO;
950 } 964 }
951 965
952 res = TALER_MINT_DB_get_refresh_melt (db_conn, refresh_session_pub, j, &coin_pub); 966 res = TALER_MINT_DB_get_refresh_melt (db_conn,
967 refresh_session_pub,
968 j,
969 &melt);
953 if (GNUNET_OK != res) 970 if (GNUNET_OK != res)
954 { 971 {
955 GNUNET_break (0); 972 GNUNET_break (0);
@@ -962,7 +979,7 @@ TALER_MINT_db_execute_refresh_reveal (struct MHD_Connection *connection,
962 /* FIXME: ECDHE/ECDSA-key type confusion! Can we reduce/avoid this? */ 979 /* FIXME: ECDHE/ECDSA-key type confusion! Can we reduce/avoid this? */
963 if (GNUNET_OK != 980 if (GNUNET_OK !=
964 GNUNET_CRYPTO_ecc_ecdh ((const struct GNUNET_CRYPTO_EcdhePrivateKey *) &transfer_privs[i+off][j], 981 GNUNET_CRYPTO_ecc_ecdh ((const struct GNUNET_CRYPTO_EcdhePrivateKey *) &transfer_privs[i+off][j],
965 (const struct GNUNET_CRYPTO_EcdhePublicKey *) &coin_pub, 982 (const struct GNUNET_CRYPTO_EcdhePublicKey *) &melt.coin.coin_pub,
966 &transfer_secret.key)) 983 &transfer_secret.key))
967 { 984 {
968 GNUNET_break (0); 985 GNUNET_break (0);