implementing /deposit for test

This commit is contained in:
Christian Grothoff 2016-04-04 15:58:40 +02:00
parent 6eb2e73ee0
commit 13f1c1c195

View File

@ -375,6 +375,9 @@ do_deposit (struct Command *cmd)
int ret; int ret;
memset (&deposit, 0, sizeof (deposit)); memset (&deposit, 0, sizeof (deposit));
/* we derive the merchant's private key from the
name, to ensure that the same name always
results in the same key pair. */
GNUNET_CRYPTO_kdf (&merchant_priv, GNUNET_CRYPTO_kdf (&merchant_priv,
sizeof (struct TALER_MerchantPrivateKeyP), sizeof (struct TALER_MerchantPrivateKeyP),
"merchant-priv", "merchant-priv",
@ -384,6 +387,8 @@ do_deposit (struct Command *cmd)
NULL, 0); NULL, 0);
GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv.eddsa_priv, GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv.eddsa_priv,
&deposit.merchant_pub.eddsa_pub); &deposit.merchant_pub.eddsa_pub);
/* contract is just picked at random;
note: we may want to write this back to 'cmd' in the future. */
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
&deposit.h_contract); &deposit.h_contract);
if ( (GNUNET_OK != if ( (GNUNET_OK !=
@ -396,6 +401,9 @@ do_deposit (struct Command *cmd)
GNUNET_break (0); GNUNET_break (0);
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
/* Build JSON for wire details;
note that this simple method may fail in the future if we implement
and enforce signature checking on test-wire account details */
deposit.wire = json_pack ("{s:s, s:s, s:I}", deposit.wire = json_pack ("{s:s, s:s, s:I}",
"type", "test", "type", "test",
"bank_uri", "http://localhost:8082/", "bank_uri", "http://localhost:8082/",
@ -407,9 +415,20 @@ do_deposit (struct Command *cmd)
deposit.timestamp = GNUNET_TIME_absolute_get (); deposit.timestamp = GNUNET_TIME_absolute_get ();
deposit.wire_deadline = GNUNET_TIME_relative_to_absolute (cmd->details.deposit.wire_deadline); deposit.wire_deadline = GNUNET_TIME_relative_to_absolute (cmd->details.deposit.wire_deadline);
ret = plugin->insert_deposit (plugin->cls, /* finally, actually perform the DB operation */
if ( (GNUNET_OK !=
plugin->start (plugin->cls,
session)) ||
(GNUNET_OK !=
plugin->insert_deposit (plugin->cls,
session, session,
&deposit); &deposit)) ||
(GNUNET_OK !=
plugin->commit (plugin->cls,
session)) )
ret = GNUNET_SYSERR;
else
ret = GNUNET_OK;
json_decref (deposit.wire); json_decref (deposit.wire);
return ret; return ret;
} }