diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-05-21 18:36:12 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-05-21 18:36:12 +0200 |
commit | 9160245167ded9b2b7c11716dfa1a1e8887187f4 (patch) | |
tree | 64720ebc3b69f84055f25d8a7f309b19b0ebd52a /src/exchange-lib | |
parent | 922175d3082b138f4973fe11d81327806e68021d (diff) |
make use of GNUNET_JSON_from_data_auto where possible
Diffstat (limited to 'src/exchange-lib')
-rw-r--r-- | src/exchange-lib/exchange_api_admin.c | 3 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_deposit.c | 15 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_deposit_wtid.c | 15 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_refresh.c | 22 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_refund.c | 16 | ||||
-rw-r--r-- | src/exchange-lib/exchange_api_reserve.c | 8 | ||||
-rw-r--r-- | src/exchange-lib/test_exchange_api.c | 73 |
7 files changed, 95 insertions, 57 deletions
diff --git a/src/exchange-lib/exchange_api_admin.c b/src/exchange-lib/exchange_api_admin.c index 068a11e02..3c87be5a3 100644 --- a/src/exchange-lib/exchange_api_admin.c +++ b/src/exchange-lib/exchange_api_admin.c @@ -175,8 +175,7 @@ TALER_EXCHANGE_admin_add_incoming (struct TALER_EXCHANGE_Handle *exchange, } admin_obj = json_pack ("{s:o, s:o," /* reserve_pub/amount */ " s:o, s:O}", /* execution_Date/wire */ - "reserve_pub", GNUNET_JSON_from_data (reserve_pub, - sizeof (*reserve_pub)), + "reserve_pub", GNUNET_JSON_from_data_auto (reserve_pub), "amount", TALER_JSON_from_amount (amount), "execution_date", GNUNET_JSON_from_time_abs (execution_date), "wire", wire); diff --git a/src/exchange-lib/exchange_api_deposit.c b/src/exchange-lib/exchange_api_deposit.c index 0a5fc0eda..6ddfe6f65 100644 --- a/src/exchange-lib/exchange_api_deposit.c +++ b/src/exchange-lib/exchange_api_deposit.c @@ -469,22 +469,17 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle *exchange, " s:o}", /* coin_sig */ "f", TALER_JSON_from_amount (amount), "wire", wire_details, - "H_wire", GNUNET_JSON_from_data (&h_wire, - sizeof (h_wire)), - "H_contract", GNUNET_JSON_from_data (h_contract, - sizeof (struct GNUNET_HashCode)), - "coin_pub", GNUNET_JSON_from_data (coin_pub, - sizeof (*coin_pub)), + "H_wire", GNUNET_JSON_from_data_auto (&h_wire), + "H_contract", GNUNET_JSON_from_data_auto (h_contract), + "coin_pub", GNUNET_JSON_from_data_auto (coin_pub), "denom_pub", GNUNET_JSON_from_rsa_public_key (denom_pub->rsa_public_key), "ub_sig", GNUNET_JSON_from_rsa_signature (denom_sig->rsa_signature), "timestamp", GNUNET_JSON_from_time_abs (timestamp), "transaction_id", (json_int_t) transaction_id, - "merchant_pub", GNUNET_JSON_from_data (merchant_pub, - sizeof (*merchant_pub)), + "merchant_pub", GNUNET_JSON_from_data_auto (merchant_pub), "refund_deadline", GNUNET_JSON_from_time_abs (refund_deadline), "edate", GNUNET_JSON_from_time_abs (wire_deadline), - "coin_sig", GNUNET_JSON_from_data (coin_sig, - sizeof (*coin_sig)) + "coin_sig", GNUNET_JSON_from_data_auto (coin_sig) ); dh = GNUNET_new (struct TALER_EXCHANGE_DepositHandle); diff --git a/src/exchange-lib/exchange_api_deposit_wtid.c b/src/exchange-lib/exchange_api_deposit_wtid.c index b3c5b3282..073ce2b35 100644 --- a/src/exchange-lib/exchange_api_deposit_wtid.c +++ b/src/exchange-lib/exchange_api_deposit_wtid.c @@ -291,17 +291,12 @@ TALER_EXCHANGE_deposit_wtid (struct TALER_EXCHANGE_Handle *exchange, deposit_wtid_obj = json_pack ("{s:o, s:o," /* H_wire, H_contract */ " s:o, s:I," /* coin_pub, transaction_id */ " s:o, s:o}", /* merchant_pub, merchant_sig */ - "H_wire", GNUNET_JSON_from_data (h_wire, - sizeof (struct GNUNET_HashCode)), - "H_contract", GNUNET_JSON_from_data (h_contract, - sizeof (struct GNUNET_HashCode)), - "coin_pub", GNUNET_JSON_from_data (coin_pub, - sizeof (*coin_pub)), + "H_wire", GNUNET_JSON_from_data_auto (h_wire), + "H_contract", GNUNET_JSON_from_data_auto (h_contract), + "coin_pub", GNUNET_JSON_from_data_auto (coin_pub), "transaction_id", (json_int_t) transaction_id, - "merchant_pub", GNUNET_JSON_from_data (&dtp.merchant, - sizeof (struct TALER_MerchantPublicKeyP)), - "merchant_sig", GNUNET_JSON_from_data (&merchant_sig, - sizeof (merchant_sig))); + "merchant_pub", GNUNET_JSON_from_data_auto (&dtp.merchant), + "merchant_sig", GNUNET_JSON_from_data_auto (&merchant_sig)); dwh = GNUNET_new (struct TALER_EXCHANGE_DepositWtidHandle); dwh->exchange = exchange; diff --git a/src/exchange-lib/exchange_api_refresh.c b/src/exchange-lib/exchange_api_refresh.c index ad2195689..e98b3c782 100644 --- a/src/exchange-lib/exchange_api_refresh.c +++ b/src/exchange-lib/exchange_api_refresh.c @@ -1310,15 +1310,13 @@ melted_coin_to_json (const struct GNUNET_HashCode *melt_session_hash, &confirm_sig.eddsa_signature); return json_pack ("{s:o, s:o, s:o, s:o, s:o}", "coin_pub", - GNUNET_JSON_from_data (&melt.coin_pub, - sizeof (melt.coin_pub)), + GNUNET_JSON_from_data_auto (&melt.coin_pub), "denom_pub", GNUNET_JSON_from_rsa_public_key (mc->pub_key.rsa_public_key), "denom_sig", GNUNET_JSON_from_rsa_signature (mc->sig.rsa_signature), "confirm_sig", - GNUNET_JSON_from_data (&confirm_sig, - sizeof (confirm_sig)), + GNUNET_JSON_from_data_auto (&confirm_sig), "value_with_fee", TALER_JSON_from_amount (&mc->melt_amount_with_fee)); } @@ -1398,8 +1396,7 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange, GNUNET_CRYPTO_ecdhe_key_get_public (&mc->transfer_priv[j].ecdhe_priv, &transfer_pub.ecdhe_pub); json_array_append (transfer_pubs, - GNUNET_JSON_from_data (&transfer_pub, - sizeof (transfer_pub))); + GNUNET_JSON_from_data_auto (&transfer_pub)); } /* now secret_encs */ @@ -1417,8 +1414,7 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange, &trans_sec, &els)); json_array_append (secret_encs, - GNUNET_JSON_from_data (&els, - sizeof (els))); + GNUNET_JSON_from_data_auto (&els)); } /* now new_denoms */ @@ -1451,7 +1447,7 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange, GNUNET_assert (NULL != buf); json_array_append (tmp, GNUNET_JSON_from_data (buf, - buf_len)); + buf_len)); GNUNET_free (buf); GNUNET_free (rle); } @@ -1482,7 +1478,7 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange, &coin_ev); json_array_append (tmp, GNUNET_JSON_from_data (coin_ev, - coin_ev_size)); + coin_ev_size)); GNUNET_free (coin_ev); } json_array_append (coin_evs, @@ -1869,15 +1865,13 @@ TALER_EXCHANGE_refresh_reveal (struct TALER_EXCHANGE_Handle *exchange, continue; } json_array_append (transfer_privs, - GNUNET_JSON_from_data (&md->melted_coin.transfer_priv[j], - sizeof (struct TALER_TransferPrivateKeyP))); + GNUNET_JSON_from_data_auto (&md->melted_coin.transfer_priv[j])); } /* build main JSON request */ reveal_obj = json_pack ("{s:o, s:o}", "session_hash", - GNUNET_JSON_from_data (&md->melt_session_hash, - sizeof (struct GNUNET_HashCode)), + GNUNET_JSON_from_data_auto (&md->melt_session_hash), "transfer_privs", transfer_privs); diff --git a/src/exchange-lib/exchange_api_refund.c b/src/exchange-lib/exchange_api_refund.c index a6069f0b4..82ae5e8ab 100644 --- a/src/exchange-lib/exchange_api_refund.c +++ b/src/exchange-lib/exchange_api_refund.c @@ -265,18 +265,14 @@ TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange, " s:o, s:o," /* H_contract, coin_pub */ " s:I, s:I," /* transaction id, rtransaction id */ " s:o, s:o}", /* merchant_pub, merchant_sig */ - "amount", TALER_JSON_from_amount (amount), - "fee", TALER_JSON_from_amount (amount), - "H_contract", GNUNET_JSON_from_data (h_contract, - sizeof (struct GNUNET_HashCode)), - "coin_pub", GNUNET_JSON_from_data (coin_pub, - sizeof (*coin_pub)), + "refund_amount", TALER_JSON_from_amount (amount), + "refund_fee", TALER_JSON_from_amount (amount), + "H_contract", GNUNET_JSON_from_data_auto (h_contract), + "coin_pub", GNUNET_JSON_from_data_auto (coin_pub), "transaction_id", (json_int_t) transaction_id, "rtransaction_id", (json_int_t) rtransaction_id, - "merchant_pub", GNUNET_JSON_from_data (&rr.merchant, - sizeof (struct TALER_MerchantPublicKeyP)), - "merchant_sig", GNUNET_JSON_from_data (&merchant_sig, - sizeof (merchant_sig)) + "merchant_pub", GNUNET_JSON_from_data_auto (&rr.merchant), + "merchant_sig", GNUNET_JSON_from_data_auto (&merchant_sig) ); rh = GNUNET_new (struct TALER_EXCHANGE_RefundHandle); diff --git a/src/exchange-lib/exchange_api_reserve.c b/src/exchange-lib/exchange_api_reserve.c index 056d2f085..56cc3dc54 100644 --- a/src/exchange-lib/exchange_api_reserve.c +++ b/src/exchange-lib/exchange_api_reserve.c @@ -840,11 +840,9 @@ TALER_EXCHANGE_reserve_withdraw (struct TALER_EXCHANGE_Handle *exchange, " s:o, s:o}",/* reserve_pub and reserve_sig */ "denom_pub", GNUNET_JSON_from_rsa_public_key (pk->key.rsa_public_key), "coin_ev", GNUNET_JSON_from_data (coin_ev, - coin_ev_size), - "reserve_pub", GNUNET_JSON_from_data (&wsh->reserve_pub, - sizeof (struct TALER_ReservePublicKeyP)), - "reserve_sig", GNUNET_JSON_from_data (&reserve_sig, - sizeof (reserve_sig))); + coin_ev_size), + "reserve_pub", GNUNET_JSON_from_data_auto (&wsh->reserve_pub), + "reserve_sig", GNUNET_JSON_from_data_auto (&reserve_sig)); GNUNET_free (coin_ev); wsh->blinding_key = blinding_key; diff --git a/src/exchange-lib/test_exchange_api.c b/src/exchange-lib/test_exchange_api.c index 8e0d9d2aa..169d68f39 100644 --- a/src/exchange-lib/test_exchange_api.c +++ b/src/exchange-lib/test_exchange_api.c @@ -1906,17 +1906,20 @@ interpreter_run (void *cls) if (0 != cmd->details.deposit.refund_deadline.rel_value_us) { refund_deadline = GNUNET_TIME_relative_to_absolute (cmd->details.deposit.refund_deadline); + wire_deadline = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (cmd->details.deposit.refund_deadline, 2)); } else { refund_deadline = GNUNET_TIME_UNIT_ZERO_ABS; + wire_deadline = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_ZERO); } GNUNET_CRYPTO_eddsa_key_get_public (&cmd->details.deposit.merchant_priv.eddsa_priv, &merchant_pub.eddsa_pub); - wire_deadline = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_ZERO); timestamp = GNUNET_TIME_absolute_get (); GNUNET_TIME_round_abs (×tamp); + GNUNET_TIME_round_abs (&refund_deadline); + GNUNET_TIME_round_abs (&wire_deadline); { struct TALER_DepositRequestPS dr; @@ -2275,7 +2278,7 @@ interpreter_run (void *cls) ref = find_command (is, cmd->details.refund.deposit_ref); GNUNET_assert (NULL != ref); - contract = json_loads (cmd->details.deposit.contract, + contract = json_loads (ref->details.deposit.contract, JSON_REJECT_DUPLICATES, NULL); GNUNET_assert (NULL != contract); @@ -2670,7 +2673,7 @@ run (void *cls) { .oc = OC_ADMIN_ADD_INCOMING, .label = "create-reserve-1", .expected_response_code = MHD_HTTP_OK, - .details.admin_add_incoming.wire = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42 }", + .details.admin_add_incoming.wire = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42, \"uuid\":1 }", .details.admin_add_incoming.amount = "EUR:5.01" }, /* Withdraw a 5 EUR coin, at fee of 1 ct */ { .oc = OC_WITHDRAW_SIGN, @@ -2892,12 +2895,70 @@ run (void *cls) .details.wire_deposits.wtid_ref = "deposit-wtid-ok", .details.wire_deposits.total_amount_expected = "EUR:4.99" }, + /* ************** End of tracking API testing************* */ - /* TODO: trigger aggregation logic and then check the - cases where tracking succeeds! */ + /* ************** Test /refund API ************* */ - /* ************** End of tracking API testing************* */ + /* Fill reserve with EUR:5.01, as withdraw fee is 1 ct per config */ + { .oc = OC_ADMIN_ADD_INCOMING, + .label = "create-reserve-r1", + .expected_response_code = MHD_HTTP_OK, + .details.admin_add_incoming.wire = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42, \"uuid\":2 }", + .details.admin_add_incoming.amount = "EUR:5.01" }, + /* Withdraw a 5 EUR coin, at fee of 1 ct */ + { .oc = OC_WITHDRAW_SIGN, + .label = "withdraw-coin-r1", + .expected_response_code = MHD_HTTP_OK, + .details.reserve_withdraw.reserve_reference = "create-reserve-r1", + .details.reserve_withdraw.amount = "EUR:5" }, + /* Spend 5 EUR of the 5 EUR coin (in full) + (merchant would receive EUR:4.99 due to 1 ct deposit fee) */ + { .oc = OC_DEPOSIT, + .label = "deposit-refund-1", + .expected_response_code = MHD_HTTP_OK, + .details.deposit.amount = "EUR:5", + .details.deposit.coin_ref = "withdraw-coin-r1", + .details.deposit.wire_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42 }", + .details.deposit.contract = "{ \"items\" : [ { \"name\":\"ice cream\", \"value\":\"EUR:5\" } ] }", + .details.deposit.transaction_id = 424210, + .details.deposit.refund_deadline = { 60LL * 1000 * 1000 } /* 60 s */, + }, + /* Run transfers. Should do nothing as refund deadline blocks it */ + { .oc = OC_RUN_AGGREGATOR, + .label = "run-aggregator" }, + /* Trigger refund */ + { .oc = OC_REFUND, + .label = "refund-ok", + .expected_response_code = MHD_HTTP_OK, + .details.refund.amount = "EUR:5", + .details.refund.fee = "EUR:0.01", + .details.refund.deposit_ref = "deposit-refund-1", + .details.refund.rtransaction_id = 1 + }, + /* Spend 4.99 EUR of the refunded 4.99 EUR coin (1ct gone due to refund) + (merchant would receive EUR:4.98 due to 1 ct deposit fee) */ + { .oc = OC_DEPOSIT, + .label = "deposit-refund-2", + .expected_response_code = MHD_HTTP_OK, + .details.deposit.amount = "EUR:4.99", + .details.deposit.coin_ref = "withdraw-coin-r1", + .details.deposit.wire_details = "{ \"type\":\"test\", \"bank_uri\":\"http://localhost:8082/\", \"account_number\":42 }", + .details.deposit.contract = "{ \"items\" : [ { \"name\":\"more ice cream\", \"value\":\"EUR:5\" } ] }", + .details.deposit.transaction_id = 424211, + }, + /* Run transfers. This will do the transfer as refund deadline was 0 */ + { .oc = OC_RUN_AGGREGATOR, + .label = "run-aggregator" }, + /* Run failing refund, as past deadline & aggregation */ + { .oc = OC_REFUND, + .label = "refund-fail", + .expected_response_code = MHD_HTTP_OK, + .details.refund.amount = "EUR:4.99", + .details.refund.fee = "EUR:0.01", + .details.refund.deposit_ref = "deposit-refund-2", + .details.refund.rtransaction_id = 2 + }, #endif |