make use of GNUNET_JSON_from_data_auto where possible

This commit is contained in:
Christian Grothoff 2016-05-21 18:36:12 +02:00
parent 922175d308
commit 9160245167
12 changed files with 146 additions and 152 deletions

View File

@ -190,8 +190,7 @@ TALER_BANK_admin_add_incoming (struct GNUNET_CURL_Context *ctx,
admin_obj = json_pack ("{s:o, s:o," admin_obj = json_pack ("{s:o, s:o,"
" s:I, s:I}", " s:I, s:I}",
"wtid", GNUNET_JSON_from_data (wtid, "wtid", GNUNET_JSON_from_data_auto (wtid), /* #4340 */
sizeof (*wtid)), /* #4340 */
"amount", TALER_JSON_from_amount (amount), "amount", TALER_JSON_from_amount (amount),
"debit_account", (json_int_t) debit_account_no, "debit_account", (json_int_t) debit_account_no,
"credit_account", (json_int_t) credit_account_no); "credit_account", (json_int_t) credit_account_no);

View File

@ -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 */ admin_obj = json_pack ("{s:o, s:o," /* reserve_pub/amount */
" s:o, s:O}", /* execution_Date/wire */ " s:o, s:O}", /* execution_Date/wire */
"reserve_pub", GNUNET_JSON_from_data (reserve_pub, "reserve_pub", GNUNET_JSON_from_data_auto (reserve_pub),
sizeof (*reserve_pub)),
"amount", TALER_JSON_from_amount (amount), "amount", TALER_JSON_from_amount (amount),
"execution_date", GNUNET_JSON_from_time_abs (execution_date), "execution_date", GNUNET_JSON_from_time_abs (execution_date),
"wire", wire); "wire", wire);

View File

@ -469,22 +469,17 @@ TALER_EXCHANGE_deposit (struct TALER_EXCHANGE_Handle *exchange,
" s:o}", /* coin_sig */ " s:o}", /* coin_sig */
"f", TALER_JSON_from_amount (amount), "f", TALER_JSON_from_amount (amount),
"wire", wire_details, "wire", wire_details,
"H_wire", GNUNET_JSON_from_data (&h_wire, "H_wire", GNUNET_JSON_from_data_auto (&h_wire),
sizeof (h_wire)), "H_contract", GNUNET_JSON_from_data_auto (h_contract),
"H_contract", GNUNET_JSON_from_data (h_contract, "coin_pub", GNUNET_JSON_from_data_auto (coin_pub),
sizeof (struct GNUNET_HashCode)),
"coin_pub", GNUNET_JSON_from_data (coin_pub,
sizeof (*coin_pub)),
"denom_pub", GNUNET_JSON_from_rsa_public_key (denom_pub->rsa_public_key), "denom_pub", GNUNET_JSON_from_rsa_public_key (denom_pub->rsa_public_key),
"ub_sig", GNUNET_JSON_from_rsa_signature (denom_sig->rsa_signature), "ub_sig", GNUNET_JSON_from_rsa_signature (denom_sig->rsa_signature),
"timestamp", GNUNET_JSON_from_time_abs (timestamp), "timestamp", GNUNET_JSON_from_time_abs (timestamp),
"transaction_id", (json_int_t) transaction_id, "transaction_id", (json_int_t) transaction_id,
"merchant_pub", GNUNET_JSON_from_data (merchant_pub, "merchant_pub", GNUNET_JSON_from_data_auto (merchant_pub),
sizeof (*merchant_pub)),
"refund_deadline", GNUNET_JSON_from_time_abs (refund_deadline), "refund_deadline", GNUNET_JSON_from_time_abs (refund_deadline),
"edate", GNUNET_JSON_from_time_abs (wire_deadline), "edate", GNUNET_JSON_from_time_abs (wire_deadline),
"coin_sig", GNUNET_JSON_from_data (coin_sig, "coin_sig", GNUNET_JSON_from_data_auto (coin_sig)
sizeof (*coin_sig))
); );
dh = GNUNET_new (struct TALER_EXCHANGE_DepositHandle); dh = GNUNET_new (struct TALER_EXCHANGE_DepositHandle);

View File

@ -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 */ deposit_wtid_obj = json_pack ("{s:o, s:o," /* H_wire, H_contract */
" s:o, s:I," /* coin_pub, transaction_id */ " s:o, s:I," /* coin_pub, transaction_id */
" s:o, s:o}", /* merchant_pub, merchant_sig */ " s:o, s:o}", /* merchant_pub, merchant_sig */
"H_wire", GNUNET_JSON_from_data (h_wire, "H_wire", GNUNET_JSON_from_data_auto (h_wire),
sizeof (struct GNUNET_HashCode)), "H_contract", GNUNET_JSON_from_data_auto (h_contract),
"H_contract", GNUNET_JSON_from_data (h_contract, "coin_pub", GNUNET_JSON_from_data_auto (coin_pub),
sizeof (struct GNUNET_HashCode)),
"coin_pub", GNUNET_JSON_from_data (coin_pub,
sizeof (*coin_pub)),
"transaction_id", (json_int_t) transaction_id, "transaction_id", (json_int_t) transaction_id,
"merchant_pub", GNUNET_JSON_from_data (&dtp.merchant, "merchant_pub", GNUNET_JSON_from_data_auto (&dtp.merchant),
sizeof (struct TALER_MerchantPublicKeyP)), "merchant_sig", GNUNET_JSON_from_data_auto (&merchant_sig));
"merchant_sig", GNUNET_JSON_from_data (&merchant_sig,
sizeof (merchant_sig)));
dwh = GNUNET_new (struct TALER_EXCHANGE_DepositWtidHandle); dwh = GNUNET_new (struct TALER_EXCHANGE_DepositWtidHandle);
dwh->exchange = exchange; dwh->exchange = exchange;

View File

@ -1310,15 +1310,13 @@ melted_coin_to_json (const struct GNUNET_HashCode *melt_session_hash,
&confirm_sig.eddsa_signature); &confirm_sig.eddsa_signature);
return json_pack ("{s:o, s:o, s:o, s:o, s:o}", return json_pack ("{s:o, s:o, s:o, s:o, s:o}",
"coin_pub", "coin_pub",
GNUNET_JSON_from_data (&melt.coin_pub, GNUNET_JSON_from_data_auto (&melt.coin_pub),
sizeof (melt.coin_pub)),
"denom_pub", "denom_pub",
GNUNET_JSON_from_rsa_public_key (mc->pub_key.rsa_public_key), GNUNET_JSON_from_rsa_public_key (mc->pub_key.rsa_public_key),
"denom_sig", "denom_sig",
GNUNET_JSON_from_rsa_signature (mc->sig.rsa_signature), GNUNET_JSON_from_rsa_signature (mc->sig.rsa_signature),
"confirm_sig", "confirm_sig",
GNUNET_JSON_from_data (&confirm_sig, GNUNET_JSON_from_data_auto (&confirm_sig),
sizeof (confirm_sig)),
"value_with_fee", "value_with_fee",
TALER_JSON_from_amount (&mc->melt_amount_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, GNUNET_CRYPTO_ecdhe_key_get_public (&mc->transfer_priv[j].ecdhe_priv,
&transfer_pub.ecdhe_pub); &transfer_pub.ecdhe_pub);
json_array_append (transfer_pubs, json_array_append (transfer_pubs,
GNUNET_JSON_from_data (&transfer_pub, GNUNET_JSON_from_data_auto (&transfer_pub));
sizeof (transfer_pub)));
} }
/* now secret_encs */ /* now secret_encs */
@ -1417,8 +1414,7 @@ TALER_EXCHANGE_refresh_melt (struct TALER_EXCHANGE_Handle *exchange,
&trans_sec, &trans_sec,
&els)); &els));
json_array_append (secret_encs, json_array_append (secret_encs,
GNUNET_JSON_from_data (&els, GNUNET_JSON_from_data_auto (&els));
sizeof (els)));
} }
/* now new_denoms */ /* now new_denoms */
@ -1869,15 +1865,13 @@ TALER_EXCHANGE_refresh_reveal (struct TALER_EXCHANGE_Handle *exchange,
continue; continue;
} }
json_array_append (transfer_privs, json_array_append (transfer_privs,
GNUNET_JSON_from_data (&md->melted_coin.transfer_priv[j], GNUNET_JSON_from_data_auto (&md->melted_coin.transfer_priv[j]));
sizeof (struct TALER_TransferPrivateKeyP)));
} }
/* build main JSON request */ /* build main JSON request */
reveal_obj = json_pack ("{s:o, s:o}", reveal_obj = json_pack ("{s:o, s:o}",
"session_hash", "session_hash",
GNUNET_JSON_from_data (&md->melt_session_hash, GNUNET_JSON_from_data_auto (&md->melt_session_hash),
sizeof (struct GNUNET_HashCode)),
"transfer_privs", "transfer_privs",
transfer_privs); transfer_privs);

View File

@ -265,18 +265,14 @@ TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange,
" s:o, s:o," /* H_contract, coin_pub */ " s:o, s:o," /* H_contract, coin_pub */
" s:I, s:I," /* transaction id, rtransaction id */ " s:I, s:I," /* transaction id, rtransaction id */
" s:o, s:o}", /* merchant_pub, merchant_sig */ " s:o, s:o}", /* merchant_pub, merchant_sig */
"amount", TALER_JSON_from_amount (amount), "refund_amount", TALER_JSON_from_amount (amount),
"fee", TALER_JSON_from_amount (amount), "refund_fee", TALER_JSON_from_amount (amount),
"H_contract", GNUNET_JSON_from_data (h_contract, "H_contract", GNUNET_JSON_from_data_auto (h_contract),
sizeof (struct GNUNET_HashCode)), "coin_pub", GNUNET_JSON_from_data_auto (coin_pub),
"coin_pub", GNUNET_JSON_from_data (coin_pub,
sizeof (*coin_pub)),
"transaction_id", (json_int_t) transaction_id, "transaction_id", (json_int_t) transaction_id,
"rtransaction_id", (json_int_t) rtransaction_id, "rtransaction_id", (json_int_t) rtransaction_id,
"merchant_pub", GNUNET_JSON_from_data (&rr.merchant, "merchant_pub", GNUNET_JSON_from_data_auto (&rr.merchant),
sizeof (struct TALER_MerchantPublicKeyP)), "merchant_sig", GNUNET_JSON_from_data_auto (&merchant_sig)
"merchant_sig", GNUNET_JSON_from_data (&merchant_sig,
sizeof (merchant_sig))
); );
rh = GNUNET_new (struct TALER_EXCHANGE_RefundHandle); rh = GNUNET_new (struct TALER_EXCHANGE_RefundHandle);

View File

@ -841,10 +841,8 @@ TALER_EXCHANGE_reserve_withdraw (struct TALER_EXCHANGE_Handle *exchange,
"denom_pub", GNUNET_JSON_from_rsa_public_key (pk->key.rsa_public_key), "denom_pub", GNUNET_JSON_from_rsa_public_key (pk->key.rsa_public_key),
"coin_ev", GNUNET_JSON_from_data (coin_ev, "coin_ev", GNUNET_JSON_from_data (coin_ev,
coin_ev_size), coin_ev_size),
"reserve_pub", GNUNET_JSON_from_data (&wsh->reserve_pub, "reserve_pub", GNUNET_JSON_from_data_auto (&wsh->reserve_pub),
sizeof (struct TALER_ReservePublicKeyP)), "reserve_sig", GNUNET_JSON_from_data_auto (&reserve_sig));
"reserve_sig", GNUNET_JSON_from_data (&reserve_sig,
sizeof (reserve_sig)));
GNUNET_free (coin_ev); GNUNET_free (coin_ev);
wsh->blinding_key = blinding_key; wsh->blinding_key = blinding_key;

View File

@ -1906,17 +1906,20 @@ interpreter_run (void *cls)
if (0 != cmd->details.deposit.refund_deadline.rel_value_us) if (0 != cmd->details.deposit.refund_deadline.rel_value_us)
{ {
refund_deadline = GNUNET_TIME_relative_to_absolute (cmd->details.deposit.refund_deadline); 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 else
{ {
refund_deadline = GNUNET_TIME_UNIT_ZERO_ABS; 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, GNUNET_CRYPTO_eddsa_key_get_public (&cmd->details.deposit.merchant_priv.eddsa_priv,
&merchant_pub.eddsa_pub); &merchant_pub.eddsa_pub);
wire_deadline = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_ZERO);
timestamp = GNUNET_TIME_absolute_get (); timestamp = GNUNET_TIME_absolute_get ();
GNUNET_TIME_round_abs (&timestamp); GNUNET_TIME_round_abs (&timestamp);
GNUNET_TIME_round_abs (&refund_deadline);
GNUNET_TIME_round_abs (&wire_deadline);
{ {
struct TALER_DepositRequestPS dr; struct TALER_DepositRequestPS dr;
@ -2275,7 +2278,7 @@ interpreter_run (void *cls)
ref = find_command (is, ref = find_command (is,
cmd->details.refund.deposit_ref); cmd->details.refund.deposit_ref);
GNUNET_assert (NULL != ref); GNUNET_assert (NULL != ref);
contract = json_loads (cmd->details.deposit.contract, contract = json_loads (ref->details.deposit.contract,
JSON_REJECT_DUPLICATES, JSON_REJECT_DUPLICATES,
NULL); NULL);
GNUNET_assert (NULL != contract); GNUNET_assert (NULL != contract);
@ -2670,7 +2673,7 @@ run (void *cls)
{ .oc = OC_ADMIN_ADD_INCOMING, { .oc = OC_ADMIN_ADD_INCOMING,
.label = "create-reserve-1", .label = "create-reserve-1",
.expected_response_code = MHD_HTTP_OK, .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" }, .details.admin_add_incoming.amount = "EUR:5.01" },
/* Withdraw a 5 EUR coin, at fee of 1 ct */ /* Withdraw a 5 EUR coin, at fee of 1 ct */
{ .oc = OC_WITHDRAW_SIGN, { .oc = OC_WITHDRAW_SIGN,
@ -2892,12 +2895,70 @@ run (void *cls)
.details.wire_deposits.wtid_ref = "deposit-wtid-ok", .details.wire_deposits.wtid_ref = "deposit-wtid-ok",
.details.wire_deposits.total_amount_expected = "EUR:4.99" }, .details.wire_deposits.total_amount_expected = "EUR:4.99" },
/* TODO: trigger aggregation logic and then check the
cases where tracking succeeds! */
/* ************** End of tracking API testing************* */ /* ************** End of tracking API testing************* */
/* ************** Test /refund API ************* */
/* 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 #endif

View File

@ -148,8 +148,7 @@ denom_key_issue_to_json (const struct TALER_DenominationPublicKey *pk,
return return
json_pack ("{s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o}", json_pack ("{s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o, s:o}",
"master_sig", "master_sig",
GNUNET_JSON_from_data (&dki->signature, GNUNET_JSON_from_data_auto (&dki->signature),
sizeof (struct GNUNET_CRYPTO_EddsaSignature)),
"stamp_start", "stamp_start",
GNUNET_JSON_from_time_abs (GNUNET_TIME_absolute_ntoh (dki->properties.start)), GNUNET_JSON_from_time_abs (GNUNET_TIME_absolute_ntoh (dki->properties.start)),
"stamp_expire_withdraw", "stamp_expire_withdraw",
@ -365,11 +364,9 @@ sign_key_issue_to_json (const struct TALER_ExchangeSigningKeyValidityPS *ski)
"stamp_end", "stamp_end",
GNUNET_JSON_from_time_abs (GNUNET_TIME_absolute_ntoh (ski->end)), GNUNET_JSON_from_time_abs (GNUNET_TIME_absolute_ntoh (ski->end)),
"master_sig", "master_sig",
GNUNET_JSON_from_data (&ski->signature, GNUNET_JSON_from_data_auto (&ski->signature),
sizeof (struct TALER_MasterSignatureP)),
"key", "key",
GNUNET_JSON_from_data (&ski->signkey_pub, GNUNET_JSON_from_data_auto (&ski->signkey_pub));
sizeof (struct TALER_ExchangePublicKeyP)));
} }
@ -463,18 +460,15 @@ auditor_to_json (const struct TALER_AuditorPublicKeyP *apub,
json_array_append_new (ja, json_array_append_new (ja,
json_pack ("{s:o, s:o}", json_pack ("{s:o, s:o}",
"denom_pub_h", "denom_pub_h",
GNUNET_JSON_from_data (&dki[i]->denom_hash, GNUNET_JSON_from_data_auto (&dki[i]->denom_hash),
sizeof (struct GNUNET_HashCode)),
"auditor_sig", "auditor_sig",
GNUNET_JSON_from_data (asigs[i], GNUNET_JSON_from_data_auto (asigs[i])));
sizeof (struct TALER_AuditorSignatureP))));
return return
json_pack ("{s:o, s:s, s:o}", json_pack ("{s:o, s:s, s:o}",
"denomination_keys", ja, "denomination_keys", ja,
"auditor_url", auditor_url, "auditor_url", auditor_url,
"auditor_pub", "auditor_pub",
GNUNET_JSON_from_data (apub, GNUNET_JSON_from_data_auto (apub));
sizeof (struct TALER_AuditorPublicKeyP)));
} }
@ -704,16 +698,13 @@ TMH_KS_acquire_ (const char *location)
keys = json_pack ("{s:o, s:o, s:o, s:o, s:o, s:o, s:o}", keys = json_pack ("{s:o, s:o, s:o, s:o, s:o, s:o, s:o}",
"master_public_key", "master_public_key",
GNUNET_JSON_from_data (&TMH_master_public_key, GNUNET_JSON_from_data_auto (&TMH_master_public_key),
sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)),
"signkeys", key_state->sign_keys_array, "signkeys", key_state->sign_keys_array,
"denoms", key_state->denom_keys_array, "denoms", key_state->denom_keys_array,
"auditors", key_state->auditors_array, "auditors", key_state->auditors_array,
"list_issue_date", GNUNET_JSON_from_time_abs (key_state->reload_time), "list_issue_date", GNUNET_JSON_from_time_abs (key_state->reload_time),
"eddsa_pub", GNUNET_JSON_from_data (&key_state->current_sign_key_issue.issue.signkey_pub, "eddsa_pub", GNUNET_JSON_from_data_auto (&key_state->current_sign_key_issue.issue.signkey_pub),
sizeof (struct TALER_ExchangePublicKeyP)), "eddsa_sig", GNUNET_JSON_from_data_auto (&sig));
"eddsa_sig", GNUNET_JSON_from_data (&sig,
sizeof (struct TALER_ExchangeSignatureP)));
GNUNET_assert (NULL != keys); GNUNET_assert (NULL != keys);
key_state->auditors_array = NULL; key_state->auditors_array = NULL;
key_state->sign_keys_array = NULL; key_state->sign_keys_array = NULL;

View File

@ -56,13 +56,13 @@ verify_and_execute_refund (struct MHD_Connection *connection,
dr.purpose.size = htonl (sizeof (struct TALER_RefundRequestPS)); dr.purpose.size = htonl (sizeof (struct TALER_RefundRequestPS));
dr.h_contract = refund->h_contract; dr.h_contract = refund->h_contract;
dr.transaction_id = GNUNET_htonll (refund->transaction_id); dr.transaction_id = GNUNET_htonll (refund->transaction_id);
dr.coin_pub = refund->coin.coin_pub;
dr.merchant = refund->merchant_pub;
dr.rtransaction_id = GNUNET_htonll (refund->rtransaction_id); dr.rtransaction_id = GNUNET_htonll (refund->rtransaction_id);
TALER_amount_hton (&dr.refund_amount, TALER_amount_hton (&dr.refund_amount,
&refund->refund_amount); &refund->refund_amount);
TALER_amount_hton (&dr.refund_fee, TALER_amount_hton (&dr.refund_fee,
&refund->refund_fee); &refund->refund_fee);
dr.merchant = refund->merchant_pub;
dr.coin_pub = refund->coin.coin_pub;
if (GNUNET_YES != if (GNUNET_YES !=
TALER_amount_cmp_currency (&refund->refund_amount, TALER_amount_cmp_currency (&refund->refund_amount,
&refund->refund_fee) ) &refund->refund_fee) )

View File

@ -388,10 +388,8 @@ TMH_RESPONSE_reply_deposit_success (struct MHD_Connection *connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:s, s:o, s:o}", "{s:s, s:o, s:o}",
"status", "DEPOSIT_OK", "status", "DEPOSIT_OK",
"sig", GNUNET_JSON_from_data (&sig, "sig", GNUNET_JSON_from_data_auto (&sig),
sizeof (sig)), "pub", GNUNET_JSON_from_data_auto (&pub));
"pub", GNUNET_JSON_from_data (&pub,
sizeof (pub)));
} }
@ -449,8 +447,7 @@ compile_transaction_history (const struct TALER_EXCHANGEDB_TransactionList *tl)
return NULL; return NULL;
} }
details = GNUNET_JSON_from_data (&dr.purpose, details = GNUNET_JSON_from_data_auto (&dr);
sizeof (struct TALER_DepositRequestPS));
break; break;
} }
case TALER_EXCHANGEDB_TT_REFRESH_MELT: case TALER_EXCHANGEDB_TT_REFRESH_MELT:
@ -481,8 +478,7 @@ compile_transaction_history (const struct TALER_EXCHANGEDB_TransactionList *tl)
return NULL; return NULL;
} }
details = GNUNET_JSON_from_data (&ms.purpose, details = GNUNET_JSON_from_data_auto (&ms);
sizeof (struct TALER_RefreshMeltCoinAffirmationPS));
} }
break; break;
case TALER_EXCHANGEDB_TT_REFUND: case TALER_EXCHANGEDB_TT_REFUND:
@ -523,8 +519,7 @@ compile_transaction_history (const struct TALER_EXCHANGEDB_TransactionList *tl)
json_decref (history); json_decref (history);
return NULL; return NULL;
} }
details = GNUNET_JSON_from_data (&rr.purpose, details = GNUNET_JSON_from_data_auto (&rr);
sizeof (struct TALER_RefundRequestPS));
} }
break; break;
default: default:
@ -534,8 +529,7 @@ compile_transaction_history (const struct TALER_EXCHANGEDB_TransactionList *tl)
json_pack ("{s:s, s:o, s:o, s:o}", json_pack ("{s:s, s:o, s:o, s:o}",
"type", type, "type", type,
"amount", TALER_JSON_from_amount (&value), "amount", TALER_JSON_from_amount (&value),
"signature", GNUNET_JSON_from_data (sig, "signature", GNUNET_JSON_from_data_auto (sig),
sizeof (struct GNUNET_CRYPTO_EddsaSignature)),
"details", details)); "details", details));
} }
return history; return history;
@ -656,10 +650,8 @@ compile_reserve_history (const struct TALER_EXCHANGEDB_ReserveHistory *rh,
json_array_append_new (json_history, json_array_append_new (json_history,
json_pack ("{s:s, s:o, s:o, s:o}", json_pack ("{s:s, s:o, s:o, s:o}",
"type", "WITHDRAW", "type", "WITHDRAW",
"signature", GNUNET_JSON_from_data (&pos->details.withdraw->reserve_sig, "signature", GNUNET_JSON_from_data_auto (&pos->details.withdraw->reserve_sig),
sizeof (struct TALER_ReserveSignatureP)), "details", GNUNET_JSON_from_data_auto (&wr),
"details", GNUNET_JSON_from_data (&wr,
sizeof (wr)),
"amount", TALER_JSON_from_amount (&value))); "amount", TALER_JSON_from_amount (&value)));
break; break;
} }
@ -757,10 +749,8 @@ TMH_RESPONSE_reply_refund_success (struct MHD_Connection *connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:s, s:o, s:o}", "{s:s, s:o, s:o}",
"status", "REFUND_OK", "status", "REFUND_OK",
"sig", GNUNET_JSON_from_data (&sig, "sig", GNUNET_JSON_from_data_auto (&sig),
sizeof (sig)), "pub", GNUNET_JSON_from_data_auto (&pub));
"pub", GNUNET_JSON_from_data (&pub,
sizeof (pub)));
} }
@ -880,8 +870,7 @@ TMH_RESPONSE_reply_refresh_melt_insufficient_funds (struct MHD_Connection *conne
"error", "error",
"insufficient funds", "insufficient funds",
"coin_pub", "coin_pub",
GNUNET_JSON_from_data (coin_pub, GNUNET_JSON_from_data_auto (coin_pub),
sizeof (struct TALER_CoinSpendPublicKeyP)),
"original_value", "original_value",
TALER_JSON_from_amount (&coin_value), TALER_JSON_from_amount (&coin_value),
"residual_value", "residual_value",
@ -919,16 +908,14 @@ TMH_RESPONSE_reply_refresh_melt_success (struct MHD_Connection *connection,
TMH_KS_sign (&body.purpose, TMH_KS_sign (&body.purpose,
&pub, &pub,
&sig); &sig);
sig_json = GNUNET_JSON_from_data (&sig, sig_json = GNUNET_JSON_from_data_auto (&sig);
sizeof (sig));
GNUNET_assert (NULL != sig_json); GNUNET_assert (NULL != sig_json);
return TMH_RESPONSE_reply_json_pack (connection, return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:i, s:o, s:o}", "{s:i, s:o, s:o}",
"noreveal_index", (int) noreveal_index, "noreveal_index", (int) noreveal_index,
"exchange_sig", sig_json, "exchange_sig", sig_json,
"exchange_pub", GNUNET_JSON_from_data (&pub, "exchange_pub", GNUNET_JSON_from_data_auto (&pub));
sizeof (pub)));
} }
@ -1006,12 +993,10 @@ TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection,
rm_json = json_object (); rm_json = json_object ();
json_object_set_new (rm_json, json_object_set_new (rm_json,
"coin_sig", "coin_sig",
GNUNET_JSON_from_data (&rm->coin_sig, GNUNET_JSON_from_data_auto (&rm->coin_sig));
sizeof (struct TALER_CoinSpendSignatureP)));
json_object_set_new (rm_json, json_object_set_new (rm_json,
"coin_pub", "coin_pub",
GNUNET_JSON_from_data (&rm->coin.coin_pub, GNUNET_JSON_from_data_auto (&rm->coin.coin_pub));
sizeof (struct TALER_CoinSpendPublicKeyP)));
json_object_set_new (rm_json, json_object_set_new (rm_json,
"melt_amount_with_fee", "melt_amount_with_fee",
TALER_JSON_from_amount (&rm->amount_with_fee)); TALER_JSON_from_amount (&rm->amount_with_fee));
@ -1051,8 +1036,7 @@ TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection,
cc->coin_ev_size)); cc->coin_ev_size));
json_object_set_new (cc_json, json_object_set_new (cc_json,
"coin_priv_enc", "coin_priv_enc",
GNUNET_JSON_from_data (cc->refresh_link->coin_priv_enc, GNUNET_JSON_from_data_auto (cc->refresh_link->coin_priv_enc));
sizeof (struct TALER_CoinSpendPrivateKeyP)));
json_object_set_new (cc_json, json_object_set_new (cc_json,
"blinding_key_enc", "blinding_key_enc",
GNUNET_JSON_from_data (cc->refresh_link->blinding_key_enc, GNUNET_JSON_from_data (cc->refresh_link->blinding_key_enc,
@ -1068,12 +1052,10 @@ TMH_RESPONSE_reply_refresh_reveal_missmatch (struct MHD_Connection *connection,
cl = &mc->commit_links[k]; cl = &mc->commit_links[k];
json_object_set_new (info_link_k, json_object_set_new (info_link_k,
"transfer_pub", "transfer_pub",
GNUNET_JSON_from_data (&cl->transfer_pub, GNUNET_JSON_from_data_auto (&cl->transfer_pub));
sizeof (struct TALER_TransferPublicKeyP)));
json_object_set_new (info_link_k, json_object_set_new (info_link_k,
"shared_secret_enc", "shared_secret_enc",
GNUNET_JSON_from_data (&cl->shared_secret_enc, GNUNET_JSON_from_data_auto (&cl->shared_secret_enc));
sizeof (struct TALER_EncryptedLinkSecretP)));
json_array_append_new (info_links, json_array_append_new (info_links,
info_link_k); info_link_k);
} }
@ -1141,12 +1123,10 @@ TMH_RESPONSE_reply_refresh_link_success (struct MHD_Connection *connection,
list); list);
json_object_set_new (root, json_object_set_new (root,
"transfer_pub", "transfer_pub",
GNUNET_JSON_from_data (&sessions[i].transfer_pub, GNUNET_JSON_from_data_auto (&sessions[i].transfer_pub));
sizeof (struct TALER_TransferPublicKeyP)));
json_object_set_new (root, json_object_set_new (root,
"secret_enc", "secret_enc",
GNUNET_JSON_from_data (&sessions[i].shared_secret_enc, GNUNET_JSON_from_data_auto (&sessions[i].shared_secret_enc));
sizeof (struct TALER_EncryptedLinkSecretP)));
json_array_append_new (mlist, json_array_append_new (mlist,
root); root);
} }
@ -1240,14 +1220,11 @@ TMH_RESPONSE_reply_deposit_wtid (struct MHD_Connection *connection,
return TMH_RESPONSE_reply_json_pack (connection, return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:o, s:o, s:o, s:o, s:o}", "{s:o, s:o, s:o, s:o, s:o}",
"wtid", GNUNET_JSON_from_data (wtid, "wtid", GNUNET_JSON_from_data_auto (wtid),
sizeof (*wtid)),
"execution_time", GNUNET_JSON_from_time_abs (exec_time), "execution_time", GNUNET_JSON_from_time_abs (exec_time),
"coin_contribution", TALER_JSON_from_amount (coin_contribution), "coin_contribution", TALER_JSON_from_amount (coin_contribution),
"exchange_sig", GNUNET_JSON_from_data (&sig, "exchange_sig", GNUNET_JSON_from_data_auto (&sig),
sizeof (sig)), "exchange_pub", GNUNET_JSON_from_data_auto (&pub));
"exchange_pub", GNUNET_JSON_from_data (&pub,
sizeof (pub)));
} }
@ -1293,11 +1270,9 @@ TMH_RESPONSE_reply_wire_deposit_details (struct MHD_Connection *connection,
sizeof (struct TALER_WireDepositDetailP)); sizeof (struct TALER_WireDepositDetailP));
json_array_append (deposits, json_array_append (deposits,
json_pack ("{s:o, s:I, s:o, s:o, s:o}", json_pack ("{s:o, s:I, s:o, s:o, s:o}",
"H_contract", GNUNET_JSON_from_data (&wdd_pos->h_contract, "H_contract", GNUNET_JSON_from_data_auto (&wdd_pos->h_contract),
sizeof (struct GNUNET_HashCode)),
"transaction_id", (json_int_t) wdd_pos->transaction_id, "transaction_id", (json_int_t) wdd_pos->transaction_id,
"coin_pub", GNUNET_JSON_from_data (&wdd_pos->coin_pub, "coin_pub", GNUNET_JSON_from_data_auto (&wdd_pos->coin_pub),
sizeof (struct TALER_CoinSpendPublicKeyP)),
"deposit_value", TALER_JSON_from_amount (&wdd_pos->deposit_value), "deposit_value", TALER_JSON_from_amount (&wdd_pos->deposit_value),
"deposit_fee", TALER_JSON_from_amount (&wdd_pos->deposit_fee))); "deposit_fee", TALER_JSON_from_amount (&wdd_pos->deposit_fee)));
} }
@ -1316,15 +1291,11 @@ TMH_RESPONSE_reply_wire_deposit_details (struct MHD_Connection *connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:o, s:o, s:o, s:o, s:o, s:o}", "{s:o, s:o, s:o, s:o, s:o, s:o}",
"total", TALER_JSON_from_amount (total), "total", TALER_JSON_from_amount (total),
"merchant_pub", GNUNET_JSON_from_data (merchant_pub, "merchant_pub", GNUNET_JSON_from_data_auto (merchant_pub),
sizeof (struct TALER_MerchantPublicKeyP)), "H_wire", GNUNET_JSON_from_data_auto (h_wire),
"H_wire", GNUNET_JSON_from_data (h_wire,
sizeof (struct GNUNET_HashCode)),
"deposits", deposits, "deposits", deposits,
"exchange_sig", GNUNET_JSON_from_data (&sig, "exchange_sig", GNUNET_JSON_from_data_auto (&sig),
sizeof (sig)), "exchange_pub", GNUNET_JSON_from_data_auto (&pub));
"exchange_pub", GNUNET_JSON_from_data (&pub,
sizeof (pub)));
} }

View File

@ -91,7 +91,7 @@ TMH_TEST_handler_test_base32 (struct TMH_RequestHandler *rh,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:o}", "{s:o}",
"output", "output",
GNUNET_JSON_from_data (&hc, sizeof (struct GNUNET_HashCode))); GNUNET_JSON_from_data_auto (&hc));
} }
@ -232,8 +232,7 @@ TMH_TEST_handler_test_hkdf (struct TMH_RequestHandler *rh,
in_ptr_size, in_ptr_size,
NULL, 0); NULL, 0);
GNUNET_JSON_parse_free (spec); GNUNET_JSON_parse_free (spec);
json = GNUNET_JSON_from_data (&hc, json = GNUNET_JSON_from_data_auto (&hc);
sizeof (struct GNUNET_HashCode));
return TMH_RESPONSE_reply_json_pack (connection, return TMH_RESPONSE_reply_json_pack (connection,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:o}", "{s:o}",
@ -303,8 +302,7 @@ TMH_TEST_handler_test_ecdhe (struct TMH_RequestHandler *rh,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:o}", "{s:o}",
"ecdh_hash", "ecdh_hash",
GNUNET_JSON_from_data (&hc, GNUNET_JSON_from_data_auto (&hc));
sizeof (hc)));
} }
@ -388,11 +386,9 @@ TMH_TEST_handler_test_eddsa (struct TMH_RequestHandler *rh,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:o, s:o}", "{s:o, s:o}",
"eddsa_pub", "eddsa_pub",
GNUNET_JSON_from_data (&pub, GNUNET_JSON_from_data_auto (&pub),
sizeof (pub)),
"eddsa_sig", "eddsa_sig",
GNUNET_JSON_from_data (&sig, GNUNET_JSON_from_data_auto (&sig));
sizeof (sig)));
} }
@ -579,8 +575,7 @@ TMH_TEST_handler_test_transfer (struct TMH_RequestHandler *rh,
MHD_HTTP_OK, MHD_HTTP_OK,
"{s:o}", "{s:o}",
"secret", "secret",
GNUNET_JSON_from_data (&secret, GNUNET_JSON_from_data_auto (&secret));
sizeof (secret)));
} }