summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backend-lib/merchant_db.c2
-rw-r--r--src/backend/taler-merchant-httpd.c21
-rw-r--r--src/backend/taler-merchant-httpd_pay.c24
-rw-r--r--src/frontend/checkout.php6
-rw-r--r--src/frontend/generate_taler_contract.php14
-rw-r--r--src/frontend/index.html7
-rw-r--r--src/include/merchant.h9
7 files changed, 54 insertions, 29 deletions
diff --git a/src/backend-lib/merchant_db.c b/src/backend-lib/merchant_db.c
index 415ff223..6f3b5682 100644
--- a/src/backend-lib/merchant_db.c
+++ b/src/backend-lib/merchant_db.c
@@ -107,7 +107,7 @@ MERCHANT_DB_initialize (PGconn *conn, int tmp)
"coin_sig BYTEA NOT NULL);"
"CREATE %1$s TABLE IF NOT EXISTS deposits ("
"dep_perm TEXT NOT NULL,"
- "transaction_id INT8 PRIMARY KEY,"
+ "transaction_id INT8,"
"pending INT4 NOT NULL,"
"mint_url TEXT NOT NULL);",
tmp_str);
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c
index ae9a4613..9914d157 100644
--- a/src/backend/taler-merchant-httpd.c
+++ b/src/backend/taler-merchant-httpd.c
@@ -91,7 +91,7 @@ static struct GNUNET_SCHEDULER_Task *shutdown_task;
/**
* Context "poller" identifier
*/
-static struct GNUNET_SCHEDULER_Task *poller_task;
+struct GNUNET_SCHEDULER_Task *poller_task;
/**
* Our wireformat
@@ -330,12 +330,12 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
}
/**
- * Task that runs the context's event loop with the GNUnet scheduler.
+ * Task that runs the context's event loop using the GNUnet scheduler.
*
* @param cls unused
* @param tc scheduler context (unused)
*/
-static void
+void
context_task (void *cls,
const struct GNUNET_SCHEDULER_TaskContext *tc)
{
@@ -347,15 +347,17 @@ context_task (void *cls,
struct GNUNET_NETWORK_FDSet *rs;
struct GNUNET_NETWORK_FDSet *ws;
struct GNUNET_TIME_Relative delay;
+ struct TALER_MINT_Context *ctx;
+ ctx = (struct TALER_MINT_Context *) cls;
poller_task = NULL;
- TALER_MINT_perform (mctx);
+ TALER_MINT_perform (ctx);
max_fd = -1;
timeout = -1;
FD_ZERO (&read_fd_set);
FD_ZERO (&write_fd_set);
FD_ZERO (&except_fd_set);
- TALER_MINT_get_select_info (mctx,
+ TALER_MINT_get_select_info (ctx,
&read_fd_set,
&write_fd_set,
&except_fd_set,
@@ -485,26 +487,25 @@ run (void *cls, char *const *args, const char *cfgfile,
salt = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE,
UINT64_MAX);
- EXITIF (NULL == (mctx = TALER_MINT_init ()));
for (cnt = 0; cnt < nmints; cnt++)
{
+ EXITIF (NULL == (mints[cnt].ctx = TALER_MINT_init ()));
mints[cnt].pending = 1;
- mints[cnt].conn = TALER_MINT_connect (mctx,
+ mints[cnt].conn = TALER_MINT_connect (mints[cnt].ctx,
mints[cnt].hostname,
&keys_mgmt_cb,
&mints[cnt]);
EXITIF (NULL == mints[cnt].conn);
poller_task =
- GNUNET_SCHEDULER_add_now (&context_task, mctx);
+ GNUNET_SCHEDULER_add_now (&context_task, mints[cnt].ctx);
}
- mhd = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY,
+ mhd = MHD_start_daemon (MHD_USE_SELECT_INTERNALLY | MHD_USE_SUSPEND_RESUME,
port,
NULL, NULL,
&url_handler, NULL,
MHD_OPTION_NOTIFY_COMPLETED,
&handle_mhd_completion_callback, NULL,
-
MHD_OPTION_END);
EXITIF (NULL == mhd);
diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c
index 638b386a..8dc7f761 100644
--- a/src/backend/taler-merchant-httpd_pay.c
+++ b/src/backend/taler-merchant-httpd_pay.c
@@ -44,6 +44,9 @@ extern long long salt;
extern unsigned int nmints;
extern struct GNUNET_TIME_Relative edate_delay;
extern struct GNUNET_CRYPTO_EddsaPrivateKey privkey;
+extern struct GNUNET_SCHEDULER_Task *poller_task;
+extern void context_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* Fetch the deposit fee related to the given coin aggregate.
@@ -104,8 +107,7 @@ deposit_fee_from_coin_aggregate (struct MHD_Connection *connection,
/**
- * Callback to handle a deposit permission's response. How does this behave if the mint
- * goes offline during a call?
+ * Callback to handle a deposit permission's response.
* @param cls see `struct MERCHANT_DepositConfirmationCls` (i.e. a poinetr to the global
* array of confirmations and an index for this call in that array). That way, the last
* executed callback can detect that no other confirmations are on the way, and can pack
@@ -128,7 +130,9 @@ deposit_cb (void *cls, unsigned int http_status, json_t *proof)
MERCHANT_DB_update_deposit_permission (db_conn,
dccls->transaction_id,
0))
- /* TODO */;
+ /* TODO */
+ printf ("db error\n");
+ printf ("/deposit ack'd\n");
dccls->dc[dccls->index].ackd = 1;
dccls->dc[dccls->index].exit_status = http_status;
dccls->dc[dccls->index].proof = proof;
@@ -142,7 +146,13 @@ deposit_cb (void *cls, unsigned int http_status, json_t *proof)
return;
}
- /* at this point, any coin has been confirmed by the mint. So
+ printf ("All /deposit(s) ack'd\n");
+ MHD_resume_connection (dccls->connection);
+ TMH_RESPONSE_reply_json_pack (dccls->connection,
+ MHD_HTTP_OK,
+ "{s:s}",
+ "result", "all conins ack'd (and connection resumed)");
+ /* TODO at this point, any coin has been confirmed by the mint. So
check for errors .. */
/* Finally */
@@ -381,7 +391,8 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
dccls->dc = dc;
dccls->coins_cnt = coins_cnt;
dccls->transaction_id = transaction_id;
-
+ dccls->connection = connection;
+
dh = TALER_MINT_deposit (mints[mint_index].conn,
&amount,
edate,
@@ -408,6 +419,9 @@ MH_handler_pay (struct TMH_RequestHandler *rh,
}
}
+ printf ("poller task: %p\n", poller_task);
+ GNUNET_SCHEDULER_cancel (poller_task);
+ GNUNET_SCHEDULER_add_now (context_task, NULL);
return MHD_YES;
/* 4 Return response code: success, or whatever data the
diff --git a/src/frontend/checkout.php b/src/frontend/checkout.php
index 15f0e356..abb0a6e3 100644
--- a/src/frontend/checkout.php
+++ b/src/frontend/checkout.php
@@ -49,10 +49,14 @@
$donation_amount = $_POST['donation_amount'];
$donation_currency = $_POST['donation_currency'];
+ // get frational part
+ list ($donation_value, $donation_fraction) = split ("\.", $donation_amount, 2);
// create PHP session and store donation information in session
+ $donation_fraction = (float) ("0." . $donation_fraction);
session_start();
$_SESSION['receiver'] = $donation_receiver;
- $_SESSION['amount'] = $donation_amount;
+ $_SESSION['amount_value'] = (int) $donation_amount;
+ $_SESSION['amount_fraction'] = (int) ($donation_fraction * 1000000);
$_SESSION['currency'] = $donation_currency;
?>
diff --git a/src/frontend/generate_taler_contract.php b/src/frontend/generate_taler_contract.php
index 9849dc82..f3bdc4ae 100644
--- a/src/frontend/generate_taler_contract.php
+++ b/src/frontend/generate_taler_contract.php
@@ -46,8 +46,7 @@ if ($_GET['backend_test'] == 'no')
// 1) recover the session information
session_start();
-if (!$cli_debug && ((! isset($_SESSION['receiver'])) ||
- (! isset($_SESSION['amount']))) )
+if (!$cli_debug && (! isset($_SESSION['receiver'])))
{
http_response_code (404);
echo "Please select a contract before getting to this page...";
@@ -59,7 +58,8 @@ if (!$cli_debug && ((! isset($_SESSION['receiver'])) ||
if (!$cli_debug)
{
$receiver = $_SESSION['receiver'];
- $amount = intval ($_SESSION['amount']);
+ $amount_value = intval ($_SESSION['amount_value']);
+ $amount_fraction = intval ($_SESSION['amount_fraction']);
$currency = $_SESSION['currency'];
}
else
@@ -81,10 +81,6 @@ $p_id = rand(0,1001);
$transaction_id = rand(0, 1001);
// Human-readable description of this deal
$desc = "Donation to " . $receiver;
-// Add the value
-$value = $amount;
-// We don't have a fraction.
-$fraction = 0;
// The tax for this deal
$teatax = array ('value' => 1,
'fraction' => 0,
@@ -95,8 +91,8 @@ $now = new DateTime('now');
// pack the JSON for the contract
// --- FIXME: exact format needs review!
-$json = json_encode (array ('amount' => array ('value' => $value,
- 'fraction' => $fraction,
+$json = json_encode (array ('amount' => array ('value' => $amount_value,
+ 'fraction' => $amount_fraction,
'currency' => $currency),
'max_fee' => array ('value' => 3,
'fraction' => 01010,
diff --git a/src/frontend/index.html b/src/frontend/index.html
index 4f22750b..78b6906a 100644
--- a/src/frontend/index.html
+++ b/src/frontend/index.html
@@ -91,9 +91,10 @@
<input type="radio" name="donation_receiver" value="GNUnet">GNUnet</input>
<br>
<select id="taler-donation" name="donation_amount">
- <option value="1">1 KUDOS</option>
- <option value="6">5 KUDOS (*)</option>
- <option value="10">10 KUDOS</option>
+ <option value="0.1">0.01 KUDOS</option>
+ <option value="1.0">1 KUDOS</option>
+ <option value="6.0">5 KUDOS (*)</option>
+ <option value="10.0">10 KUDOS</option>
</select>
<input type="hidden" name="donation_currency" value="KUDOS"/>
<input type="submit" name="keyName" value="Donate!"/>
diff --git a/src/include/merchant.h b/src/include/merchant.h
index 7e9cc4aa..339b1355 100644
--- a/src/include/merchant.h
+++ b/src/include/merchant.h
@@ -88,6 +88,10 @@ struct MERCHANT_DepositConfirmationCls
*/
uint64_t transaction_id;
+ /**
+ * MHD connection to return to
+ */
+ struct MHD_Connection *connection;
};
/**
@@ -111,6 +115,11 @@ struct MERCHANT_Mint
*/
struct TALER_MINT_Handle *conn;
+ /**
+ * This mint's context (useful to the event loop)
+ */
+ struct TALER_MINT_Context *ctx;
+
};
struct MERCHANT_Auditor