pass purse_fee to determine how purse creation is paid for
This commit is contained in:
parent
6b8e732bf8
commit
d3a6388199
@ -55,7 +55,7 @@ struct Coin
|
|||||||
struct TALER_Amount amount;
|
struct TALER_Amount amount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deposit fee applicable for this coin.
|
* Deposit fee applicable to this coin.
|
||||||
*/
|
*/
|
||||||
struct TALER_Amount deposit_fee;
|
struct TALER_Amount deposit_fee;
|
||||||
|
|
||||||
@ -220,8 +220,11 @@ create_transaction (void *cls,
|
|||||||
{
|
{
|
||||||
struct PurseCreateContext *pcc = cls;
|
struct PurseCreateContext *pcc = cls;
|
||||||
enum GNUNET_DB_QueryStatus qs;
|
enum GNUNET_DB_QueryStatus qs;
|
||||||
|
struct TALER_Amount purse_fee;
|
||||||
bool in_conflict = true;
|
bool in_conflict = true;
|
||||||
|
|
||||||
|
TALER_amount_set_zero (pcc->amount.currency,
|
||||||
|
&purse_fee);
|
||||||
/* 1) create purse */
|
/* 1) create purse */
|
||||||
qs = TEH_plugin->insert_purse_request (TEH_plugin->cls,
|
qs = TEH_plugin->insert_purse_request (TEH_plugin->cls,
|
||||||
pcc->purse_pub,
|
pcc->purse_pub,
|
||||||
@ -229,7 +232,9 @@ create_transaction (void *cls,
|
|||||||
pcc->purse_expiration,
|
pcc->purse_expiration,
|
||||||
&pcc->h_contract_terms,
|
&pcc->h_contract_terms,
|
||||||
pcc->min_age,
|
pcc->min_age,
|
||||||
|
TALER_WAMF_MODE_MERGE_FULLY_PAID_PURSE,
|
||||||
&pcc->amount,
|
&pcc->amount,
|
||||||
|
&purse_fee,
|
||||||
&pcc->purse_sig,
|
&pcc->purse_sig,
|
||||||
&in_conflict);
|
&in_conflict);
|
||||||
if (qs < 0)
|
if (qs < 0)
|
||||||
|
@ -497,6 +497,11 @@ TEH_handler_purses_merge (
|
|||||||
TALER_EC_EXCHANGE_PURSE_MERGE_INVALID_MERGE_SIGNATURE,
|
TALER_EC_EXCHANGE_PURSE_MERGE_INVALID_MERGE_SIGNATURE,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
struct TALER_Amount zero_purse_fee;
|
||||||
|
|
||||||
|
TALER_amount_set_zero (pcc.target_amount.currency,
|
||||||
|
&zero_purse_fee);
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_wallet_account_merge_verify (
|
TALER_wallet_account_merge_verify (
|
||||||
pcc.merge_timestamp,
|
pcc.merge_timestamp,
|
||||||
@ -504,7 +509,9 @@ TEH_handler_purses_merge (
|
|||||||
pcc.purse_expiration,
|
pcc.purse_expiration,
|
||||||
&pcc.h_contract_terms,
|
&pcc.h_contract_terms,
|
||||||
&pcc.target_amount,
|
&pcc.target_amount,
|
||||||
|
&zero_purse_fee,
|
||||||
pcc.min_age,
|
pcc.min_age,
|
||||||
|
TALER_WAMF_MODE_MERGE_FULLY_PAID_PURSE,
|
||||||
&pcc.reserve_pub,
|
&pcc.reserve_pub,
|
||||||
&pcc.reserve_sig))
|
&pcc.reserve_sig))
|
||||||
{
|
{
|
||||||
@ -516,6 +523,7 @@ TEH_handler_purses_merge (
|
|||||||
TALER_EC_EXCHANGE_PURSE_MERGE_INVALID_RESERVE_SIGNATURE,
|
TALER_EC_EXCHANGE_PURSE_MERGE_INVALID_RESERVE_SIGNATURE,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* execute transaction */
|
/* execute transaction */
|
||||||
{
|
{
|
||||||
|
@ -60,6 +60,11 @@ struct ReservePurseContext
|
|||||||
*/
|
*/
|
||||||
struct TALER_Amount amount;
|
struct TALER_Amount amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purse fee the client is willing to pay.
|
||||||
|
*/
|
||||||
|
struct TALER_Amount purse_fee;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Total amount already put into the purse.
|
* Total amount already put into the purse.
|
||||||
*/
|
*/
|
||||||
@ -129,6 +134,11 @@ struct ReservePurseContext
|
|||||||
* Minimum age for deposits into this purse.
|
* Minimum age for deposits into this purse.
|
||||||
*/
|
*/
|
||||||
uint32_t min_age;
|
uint32_t min_age;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flags for the operation.
|
||||||
|
*/
|
||||||
|
enum TALER_WalletAccountMergeFlags flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -209,6 +219,8 @@ purse_transaction (void *cls,
|
|||||||
rpc->purse_expiration,
|
rpc->purse_expiration,
|
||||||
&rpc->h_contract_terms,
|
&rpc->h_contract_terms,
|
||||||
rpc->min_age,
|
rpc->min_age,
|
||||||
|
rpc->flags,
|
||||||
|
&rpc->purse_fee,
|
||||||
&rpc->amount,
|
&rpc->amount,
|
||||||
&rpc->purse_sig,
|
&rpc->purse_sig,
|
||||||
&in_conflict);
|
&in_conflict);
|
||||||
@ -449,12 +461,18 @@ TEH_handler_reserves_purse (
|
|||||||
.reserve_pub = reserve_pub,
|
.reserve_pub = reserve_pub,
|
||||||
.exchange_timestamp = GNUNET_TIME_timestamp_get ()
|
.exchange_timestamp = GNUNET_TIME_timestamp_get ()
|
||||||
};
|
};
|
||||||
|
bool no_purse_fee = true;
|
||||||
struct GNUNET_JSON_Specification spec[] = {
|
struct GNUNET_JSON_Specification spec[] = {
|
||||||
TALER_JSON_spec_amount ("purse_value",
|
TALER_JSON_spec_amount ("purse_value",
|
||||||
TEH_currency,
|
TEH_currency,
|
||||||
&rpc.amount),
|
&rpc.amount),
|
||||||
GNUNET_JSON_spec_uint32 ("min_age",
|
GNUNET_JSON_spec_uint32 ("min_age",
|
||||||
&rpc.min_age),
|
&rpc.min_age),
|
||||||
|
GNUNET_JSON_spec_mark_optional (
|
||||||
|
TALER_JSON_spec_amount ("purse_fee",
|
||||||
|
TEH_currency,
|
||||||
|
&rpc.purse_fee),
|
||||||
|
&no_purse_fee),
|
||||||
GNUNET_JSON_spec_mark_optional (
|
GNUNET_JSON_spec_mark_optional (
|
||||||
GNUNET_JSON_spec_varsize ("econtract",
|
GNUNET_JSON_spec_varsize ("econtract",
|
||||||
&rpc.econtract,
|
&rpc.econtract,
|
||||||
@ -538,7 +556,17 @@ TEH_handler_reserves_purse (
|
|||||||
TALER_EC_EXCHANGE_GENERIC_GLOBAL_FEES_MISSING,
|
TALER_EC_EXCHANGE_GENERIC_GLOBAL_FEES_MISSING,
|
||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
if (no_purse_fee)
|
||||||
|
{
|
||||||
|
rpc.flags = TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA;
|
||||||
|
TALER_amount_set_zero (TEH_currency,
|
||||||
|
&rpc.purse_fee);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rpc.flags = TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE;
|
||||||
|
// FIXME: check rpc.purse_fee is at or above gf.fees.purse!
|
||||||
|
}
|
||||||
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
|
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
|
||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
TALER_wallet_purse_create_verify (rpc.purse_expiration,
|
TALER_wallet_purse_create_verify (rpc.purse_expiration,
|
||||||
@ -578,7 +606,9 @@ TEH_handler_reserves_purse (
|
|||||||
rpc.purse_expiration,
|
rpc.purse_expiration,
|
||||||
&rpc.h_contract_terms,
|
&rpc.h_contract_terms,
|
||||||
&rpc.amount,
|
&rpc.amount,
|
||||||
|
&rpc.purse_fee,
|
||||||
rpc.min_age,
|
rpc.min_age,
|
||||||
|
rpc.flags,
|
||||||
rpc.reserve_pub,
|
rpc.reserve_pub,
|
||||||
&rpc.reserve_sig))
|
&rpc.reserve_sig))
|
||||||
{
|
{
|
||||||
|
@ -1165,6 +1165,7 @@ BEGIN
|
|||||||
',purse_expiration INT8 NOT NULL'
|
',purse_expiration INT8 NOT NULL'
|
||||||
',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
|
',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
|
||||||
',age_limit INT4 NOT NULL'
|
',age_limit INT4 NOT NULL'
|
||||||
|
',flags INT4 NOT NULL'
|
||||||
',refunded BOOLEAN NOT NULL DEFAULT(FALSE)'
|
',refunded BOOLEAN NOT NULL DEFAULT(FALSE)'
|
||||||
',finished BOOLEAN NOT NULL DEFAULT(FALSE)'
|
',finished BOOLEAN NOT NULL DEFAULT(FALSE)'
|
||||||
',in_reserve_quota BOOLEAN NOT NULL DEFAULT(FALSE)'
|
',in_reserve_quota BOOLEAN NOT NULL DEFAULT(FALSE)'
|
||||||
|
@ -1016,8 +1016,8 @@ COMMENT ON COLUMN purse_requests.purse_expiration
|
|||||||
IS 'When the purse is set to expire';
|
IS 'When the purse is set to expire';
|
||||||
COMMENT ON COLUMN purse_requests.h_contract_terms
|
COMMENT ON COLUMN purse_requests.h_contract_terms
|
||||||
IS 'Hash of the contract the parties are to agree to';
|
IS 'Hash of the contract the parties are to agree to';
|
||||||
COMMENT ON COLUMN purse_requests.shard
|
COMMENT ON COLUMN purse_requests.flags
|
||||||
IS 'for load distribution among router processes';
|
IS 'see the enum TALER_WalletAccountMergeFlags';
|
||||||
COMMENT ON COLUMN purse_requests.finished
|
COMMENT ON COLUMN purse_requests.finished
|
||||||
IS 'set to TRUE once the purse has been merged (into reserve or wad) or the coins were refunded (transfer aborted)';
|
IS 'set to TRUE once the purse has been merged (into reserve or wad) or the coins were refunded (transfer aborted)';
|
||||||
COMMENT ON COLUMN purse_requests.refunded
|
COMMENT ON COLUMN purse_requests.refunded
|
||||||
@ -1312,9 +1312,9 @@ COMMENT ON TABLE purse_actions
|
|||||||
IS 'purses awaiting some action by the router';
|
IS 'purses awaiting some action by the router';
|
||||||
COMMENT ON COLUMN purse_actions.purse_pub
|
COMMENT ON COLUMN purse_actions.purse_pub
|
||||||
IS 'public (contract) key of the purse';
|
IS 'public (contract) key of the purse';
|
||||||
COMMENT ON COLUMN purse_action.action_date
|
COMMENT ON COLUMN purse_actions.action_date
|
||||||
IS 'when is the purse ready for action';
|
IS 'when is the purse ready for action';
|
||||||
COMMENT ON COLUMN purse_action.partner_serial_id
|
COMMENT ON COLUMN purse_actions.partner_serial_id
|
||||||
IS 'wad target of an outgoing wire transfer, 0 for local, NULL if the purse is unmerged and thus the target is still unknown';
|
IS 'wad target of an outgoing wire transfer, 0 for local, NULL if the purse is unmerged and thus the target is still unknown';
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS purse_action_by_target
|
CREATE INDEX IF NOT EXISTS purse_action_by_target
|
||||||
@ -1344,6 +1344,7 @@ CREATE TRIGGER purse_requests_on_insert
|
|||||||
ON purse_requests
|
ON purse_requests
|
||||||
FOR EACH ROW EXECUTE FUNCTION purse_requests_insert_trigger();
|
FOR EACH ROW EXECUTE FUNCTION purse_requests_insert_trigger();
|
||||||
COMMENT ON TRIGGER purse_requests_on_insert
|
COMMENT ON TRIGGER purse_requests_on_insert
|
||||||
|
ON purse_requests
|
||||||
IS 'Here we install an entry for the purse expiration.';
|
IS 'Here we install an entry for the purse expiration.';
|
||||||
|
|
||||||
|
|
||||||
@ -1392,6 +1393,7 @@ CREATE TRIGGER purse_merges_on_insert
|
|||||||
ON purse_merges
|
ON purse_merges
|
||||||
FOR EACH ROW EXECUTE FUNCTION purse_merge_insert_trigger();
|
FOR EACH ROW EXECUTE FUNCTION purse_merge_insert_trigger();
|
||||||
COMMENT ON TRIGGER purse_merges_on_insert
|
COMMENT ON TRIGGER purse_merges_on_insert
|
||||||
|
ON purse_merges
|
||||||
IS 'Here we install an entry that triggers the merge (if the purse is already full).';
|
IS 'Here we install an entry that triggers the merge (if the purse is already full).';
|
||||||
|
|
||||||
|
|
||||||
@ -1440,6 +1442,10 @@ BEGIN
|
|||||||
(NEW.balance_frac >= NEW.amount_with_fee_frac) );
|
(NEW.balance_frac >= NEW.amount_with_fee_frac) );
|
||||||
IF (was_merged AND was_paid)
|
IF (was_merged AND was_paid)
|
||||||
THEN
|
THEN
|
||||||
|
-- FIXME: If 0==psi, why not simply DO the merge here?
|
||||||
|
-- Adding up reserve balance + setting finished
|
||||||
|
-- is hardly doing much, and could be combined
|
||||||
|
-- with the reserve update above!
|
||||||
UPDATE purse_actions
|
UPDATE purse_actions
|
||||||
SET action_date=0 --- "immediately"
|
SET action_date=0 --- "immediately"
|
||||||
,partner_serial_id=psi
|
,partner_serial_id=psi
|
||||||
@ -1448,14 +1454,15 @@ BEGIN
|
|||||||
RETURN NEW;
|
RETURN NEW;
|
||||||
END $$;
|
END $$;
|
||||||
|
|
||||||
COMMENT ON FUNCTION purse_requests_on_update_trigger
|
COMMENT ON FUNCTION purse_requests_on_update_trigger()
|
||||||
IS 'Trigger the router if the purse is ready. Also removes the entry from the router watchlist once the purse is fnished.';
|
IS 'Trigger the router if the purse is ready. Also removes the entry from the router watchlist once the purse is finished.';
|
||||||
|
|
||||||
CREATE TRIGGER purse_requests_on_update
|
CREATE TRIGGER purse_requests_on_update
|
||||||
BEFORE UPDATE
|
BEFORE UPDATE
|
||||||
ON purse_requests
|
ON purse_requests
|
||||||
FOR EACH ROW EXECUTE FUNCTION purse_requests_update_trigger();
|
FOR EACH ROW EXECUTE FUNCTION purse_requests_on_update_trigger();
|
||||||
COMMENT ON TRIGGER purse_requests_on_update
|
COMMENT ON TRIGGER purse_requests_on_update
|
||||||
|
ON purse_requests
|
||||||
IS 'This covers the case where a deposit is made into a purse, which inherently then changes the purse balance via an UPDATE. If the merge is already present and the balance matches the total, we trigger the router. Once the router sets the purse to finished, the trigger will remove the purse from the watchlist of the router.';
|
IS 'This covers the case where a deposit is made into a purse, which inherently then changes the purse balance via an UPDATE. If the merge is already present and the balance matches the total, we trigger the router. Once the router sets the purse to finished, the trigger will remove the purse from the watchlist of the router.';
|
||||||
|
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
@ -3541,13 +3541,17 @@ prepare_statements (struct PostgresClosure *pg)
|
|||||||
" ,purse_expiration"
|
" ,purse_expiration"
|
||||||
" ,h_contract_terms"
|
" ,h_contract_terms"
|
||||||
" ,age_limit"
|
" ,age_limit"
|
||||||
|
" ,flags"
|
||||||
|
" ,in_reserve_quota"
|
||||||
" ,amount_with_fee_val"
|
" ,amount_with_fee_val"
|
||||||
" ,amount_with_fee_frac"
|
" ,amount_with_fee_frac"
|
||||||
|
" ,purse_fee_val"
|
||||||
|
" ,purse_fee_frac"
|
||||||
" ,purse_sig"
|
" ,purse_sig"
|
||||||
" ) VALUES "
|
" ) VALUES "
|
||||||
" ($1, $2, $3, $4, $5, $6, $7, $8)"
|
" ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)"
|
||||||
" ON CONFLICT DO NOTHING;",
|
" ON CONFLICT DO NOTHING;",
|
||||||
8),
|
12),
|
||||||
/* Used in #postgres_select_purse */
|
/* Used in #postgres_select_purse */
|
||||||
GNUNET_PQ_make_prepare (
|
GNUNET_PQ_make_prepare (
|
||||||
"select_purse",
|
"select_purse",
|
||||||
@ -13481,6 +13485,8 @@ postgres_select_purse_request (
|
|||||||
* @param purse_expiration time when the purse will expire
|
* @param purse_expiration time when the purse will expire
|
||||||
* @param h_contract_terms hash of the contract for the purse
|
* @param h_contract_terms hash of the contract for the purse
|
||||||
* @param age_limit age limit to enforce for payments into the purse
|
* @param age_limit age limit to enforce for payments into the purse
|
||||||
|
* @param flags flags for the operation
|
||||||
|
* @param purse_fee fee we are allowed to charge to the reserve (depending on @a flags)
|
||||||
* @param amount target amount (with fees) to be put into the purse
|
* @param amount target amount (with fees) to be put into the purse
|
||||||
* @param purse_sig signature with @a purse_pub's private key affirming the above
|
* @param purse_sig signature with @a purse_pub's private key affirming the above
|
||||||
* @param[out] in_conflict set to true if the meta data
|
* @param[out] in_conflict set to true if the meta data
|
||||||
@ -13497,19 +13503,27 @@ postgres_insert_purse_request (
|
|||||||
struct GNUNET_TIME_Timestamp purse_expiration,
|
struct GNUNET_TIME_Timestamp purse_expiration,
|
||||||
const struct TALER_PrivateContractHashP *h_contract_terms,
|
const struct TALER_PrivateContractHashP *h_contract_terms,
|
||||||
uint32_t age_limit,
|
uint32_t age_limit,
|
||||||
|
enum TALER_WalletAccountMergeFlags flags,
|
||||||
|
const struct TALER_Amount *purse_fee,
|
||||||
const struct TALER_Amount *amount,
|
const struct TALER_Amount *amount,
|
||||||
const struct TALER_PurseContractSignatureP *purse_sig,
|
const struct TALER_PurseContractSignatureP *purse_sig,
|
||||||
bool *in_conflict)
|
bool *in_conflict)
|
||||||
{
|
{
|
||||||
struct PostgresClosure *pg = cls;
|
struct PostgresClosure *pg = cls;
|
||||||
enum GNUNET_DB_QueryStatus qs;
|
enum GNUNET_DB_QueryStatus qs;
|
||||||
|
uint32_t flags32 = (uint32_t) flags;
|
||||||
|
bool in_reserve_quota = (TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE
|
||||||
|
== (flags & TALER_WAMF_MERGE_MODE_MASK));
|
||||||
struct GNUNET_PQ_QueryParam params[] = {
|
struct GNUNET_PQ_QueryParam params[] = {
|
||||||
GNUNET_PQ_query_param_auto_from_type (purse_pub),
|
GNUNET_PQ_query_param_auto_from_type (purse_pub),
|
||||||
GNUNET_PQ_query_param_auto_from_type (merge_pub),
|
GNUNET_PQ_query_param_auto_from_type (merge_pub),
|
||||||
GNUNET_PQ_query_param_timestamp (&purse_expiration),
|
GNUNET_PQ_query_param_timestamp (&purse_expiration),
|
||||||
GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
|
GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
|
||||||
GNUNET_PQ_query_param_uint32 (&age_limit),
|
GNUNET_PQ_query_param_uint32 (&age_limit),
|
||||||
|
GNUNET_PQ_query_param_uint32 (&flags32),
|
||||||
|
GNUNET_PQ_query_param_bool (in_reserve_quota),
|
||||||
TALER_PQ_query_param_amount (amount),
|
TALER_PQ_query_param_amount (amount),
|
||||||
|
TALER_PQ_query_param_amount (purse_fee),
|
||||||
GNUNET_PQ_query_param_auto_from_type (purse_sig),
|
GNUNET_PQ_query_param_auto_from_type (purse_sig),
|
||||||
GNUNET_PQ_query_param_end
|
GNUNET_PQ_query_param_end
|
||||||
};
|
};
|
||||||
|
@ -2862,8 +2862,7 @@ TALER_wallet_purse_deposit_verify (
|
|||||||
/**
|
/**
|
||||||
* Sign a request by a purse to merge it into an account.
|
* Sign a request by a purse to merge it into an account.
|
||||||
*
|
*
|
||||||
* @param reserve_url identifies the location of the reserve,
|
* @param reserve_url identifies the location of the reserve
|
||||||
* included public key must match @e reserve_priv
|
|
||||||
* @param merge_timestamp time when the merge happened
|
* @param merge_timestamp time when the merge happened
|
||||||
* @param purse_pub key identifying the purse
|
* @param purse_pub key identifying the purse
|
||||||
* @param merge_priv key identifying the merge capability
|
* @param merge_priv key identifying the merge capability
|
||||||
@ -2881,8 +2880,7 @@ TALER_wallet_purse_merge_sign (
|
|||||||
/**
|
/**
|
||||||
* Verify a purse merge request.
|
* Verify a purse merge request.
|
||||||
*
|
*
|
||||||
* @param reserve_url identifies the location of the reserve,
|
* @param reserve_url identifies the location of the reserve
|
||||||
* included public key must match @e reserve_priv
|
|
||||||
* @param merge_timestamp time when the merge happened
|
* @param merge_timestamp time when the merge happened
|
||||||
* @param purse_pub public key of the purse to merge
|
* @param purse_pub public key of the purse to merge
|
||||||
* @param merge_pub public key of the merge capability
|
* @param merge_pub public key of the merge capability
|
||||||
@ -2898,6 +2896,42 @@ TALER_wallet_purse_merge_verify (
|
|||||||
const struct TALER_PurseMergeSignatureP *merge_sig);
|
const struct TALER_PurseMergeSignatureP *merge_sig);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flags for a merge signature.
|
||||||
|
*/
|
||||||
|
enum TALER_WalletAccountMergeFlags
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A mode must be set. None is not a legal mode!
|
||||||
|
*/
|
||||||
|
TALER_WAMF_MODE_NONE = 0,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We are merging a fully paid-up purse into a reserve.
|
||||||
|
*/
|
||||||
|
TALER_WAMF_MODE_MERGE_FULLY_PAID_PURSE = 1,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We are creating a fresh purse, from the contingent
|
||||||
|
* of free purses that our account brings.
|
||||||
|
*/
|
||||||
|
TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA = 2,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The account owner is willing to pay the purse_fee for the purse to be
|
||||||
|
* created from the account balance.
|
||||||
|
*/
|
||||||
|
TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE = 3,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bitmask to AND the full flags with to get the mode.
|
||||||
|
*/
|
||||||
|
TALER_WAMF_MERGE_MODE_MASK = 3
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign a request by an account to merge a purse.
|
* Sign a request by an account to merge a purse.
|
||||||
*
|
*
|
||||||
@ -2906,7 +2940,10 @@ TALER_wallet_purse_merge_verify (
|
|||||||
* @param purse_expiration when should the purse expire
|
* @param purse_expiration when should the purse expire
|
||||||
* @param h_contract_terms contract the two parties agree on
|
* @param h_contract_terms contract the two parties agree on
|
||||||
* @param amount total amount in the purse (including fees)
|
* @param amount total amount in the purse (including fees)
|
||||||
|
* @param purse_fee purse fee the reserve will pay,
|
||||||
|
* only used if @a flags is #TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE
|
||||||
* @param min_age age restriction to apply for deposits into the purse
|
* @param min_age age restriction to apply for deposits into the purse
|
||||||
|
* @param flags flags for the operation
|
||||||
* @param reserve_priv key identifying the reserve
|
* @param reserve_priv key identifying the reserve
|
||||||
* @param[out] reserve_sig resulting signature
|
* @param[out] reserve_sig resulting signature
|
||||||
*/
|
*/
|
||||||
@ -2917,7 +2954,9 @@ TALER_wallet_account_merge_sign (
|
|||||||
struct GNUNET_TIME_Timestamp purse_expiration,
|
struct GNUNET_TIME_Timestamp purse_expiration,
|
||||||
const struct TALER_PrivateContractHashP *h_contract_terms,
|
const struct TALER_PrivateContractHashP *h_contract_terms,
|
||||||
const struct TALER_Amount *amount,
|
const struct TALER_Amount *amount,
|
||||||
|
const struct TALER_Amount *purse_fee,
|
||||||
uint32_t min_age,
|
uint32_t min_age,
|
||||||
|
enum TALER_WalletAccountMergeFlags flags,
|
||||||
const struct TALER_ReservePrivateKeyP *reserve_priv,
|
const struct TALER_ReservePrivateKeyP *reserve_priv,
|
||||||
struct TALER_ReserveSignatureP *reserve_sig);
|
struct TALER_ReserveSignatureP *reserve_sig);
|
||||||
|
|
||||||
@ -2930,7 +2969,10 @@ TALER_wallet_account_merge_sign (
|
|||||||
* @param purse_expiration when should the purse expire
|
* @param purse_expiration when should the purse expire
|
||||||
* @param h_contract_terms contract the two parties agree on
|
* @param h_contract_terms contract the two parties agree on
|
||||||
* @param amount total amount in the purse (including fees)
|
* @param amount total amount in the purse (including fees)
|
||||||
|
* @param purse_fee purse fee the reserve will pay,
|
||||||
|
* only used if @a flags is #TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE
|
||||||
* @param min_age age restriction to apply for deposits into the purse
|
* @param min_age age restriction to apply for deposits into the purse
|
||||||
|
* @param flags flags for the operation
|
||||||
* @param reserve_pub account’s public key
|
* @param reserve_pub account’s public key
|
||||||
* @param reserve_sig the signature made with purpose #TALER_SIGNATURE_WALLET_ACCOUNT_MERGE
|
* @param reserve_sig the signature made with purpose #TALER_SIGNATURE_WALLET_ACCOUNT_MERGE
|
||||||
* @return #GNUNET_OK if the signature is valid
|
* @return #GNUNET_OK if the signature is valid
|
||||||
@ -2942,7 +2984,9 @@ TALER_wallet_account_merge_verify (
|
|||||||
struct GNUNET_TIME_Timestamp purse_expiration,
|
struct GNUNET_TIME_Timestamp purse_expiration,
|
||||||
const struct TALER_PrivateContractHashP *h_contract_terms,
|
const struct TALER_PrivateContractHashP *h_contract_terms,
|
||||||
const struct TALER_Amount *amount,
|
const struct TALER_Amount *amount,
|
||||||
|
const struct TALER_Amount *purse_fee,
|
||||||
uint32_t min_age,
|
uint32_t min_age,
|
||||||
|
enum TALER_WalletAccountMergeFlags flags,
|
||||||
const struct TALER_ReservePublicKeyP *reserve_pub,
|
const struct TALER_ReservePublicKeyP *reserve_pub,
|
||||||
const struct TALER_ReserveSignatureP *reserve_sig);
|
const struct TALER_ReserveSignatureP *reserve_sig);
|
||||||
|
|
||||||
|
@ -4441,6 +4441,7 @@ struct TALER_EXCHANGE_PurseCreateMergeHandle;
|
|||||||
* @param contract_priv private key to get the contract
|
* @param contract_priv private key to get the contract
|
||||||
* @param contract_terms contract the purse is about
|
* @param contract_terms contract the purse is about
|
||||||
* @param upload_contract true to upload the contract
|
* @param upload_contract true to upload the contract
|
||||||
|
* @param pay_for_purse true to pay for purse creation
|
||||||
* @paran merge_timestamp when should the merge happen (use current time)
|
* @paran merge_timestamp when should the merge happen (use current time)
|
||||||
* @param cb function to call with the exchange's result
|
* @param cb function to call with the exchange's result
|
||||||
* @param cb_cls closure for @a cb
|
* @param cb_cls closure for @a cb
|
||||||
@ -4455,6 +4456,7 @@ TALER_EXCHANGE_purse_create_with_merge (
|
|||||||
const struct TALER_ContractDiffiePrivateP *contract_priv,
|
const struct TALER_ContractDiffiePrivateP *contract_priv,
|
||||||
const json_t *contract_terms,
|
const json_t *contract_terms,
|
||||||
bool upload_contract,
|
bool upload_contract,
|
||||||
|
bool pay_for_purse,
|
||||||
struct GNUNET_TIME_Timestamp merge_timestamp,
|
struct GNUNET_TIME_Timestamp merge_timestamp,
|
||||||
TALER_EXCHANGE_PurseCreateMergeCallback cb,
|
TALER_EXCHANGE_PurseCreateMergeCallback cb,
|
||||||
void *cb_cls);
|
void *cb_cls);
|
||||||
|
@ -4578,6 +4578,8 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
* @param purse_expiration time when the purse will expire
|
* @param purse_expiration time when the purse will expire
|
||||||
* @param h_contract_terms hash of the contract for the purse
|
* @param h_contract_terms hash of the contract for the purse
|
||||||
* @param age_limit age limit to enforce for payments into the purse
|
* @param age_limit age limit to enforce for payments into the purse
|
||||||
|
* @param flags flags for the operation
|
||||||
|
* @param purse_fee fee we are allowed to charge to the reserve (depending on @a flags)
|
||||||
* @param amount target amount (with fees) to be put into the purse
|
* @param amount target amount (with fees) to be put into the purse
|
||||||
* @param purse_sig signature with @a purse_pub's private key affirming the above
|
* @param purse_sig signature with @a purse_pub's private key affirming the above
|
||||||
* @param[out] in_conflict set to true if the meta data
|
* @param[out] in_conflict set to true if the meta data
|
||||||
@ -4594,6 +4596,8 @@ struct TALER_EXCHANGEDB_Plugin
|
|||||||
struct GNUNET_TIME_Timestamp purse_expiration,
|
struct GNUNET_TIME_Timestamp purse_expiration,
|
||||||
const struct TALER_PrivateContractHashP *h_contract_terms,
|
const struct TALER_PrivateContractHashP *h_contract_terms,
|
||||||
uint32_t age_limit,
|
uint32_t age_limit,
|
||||||
|
enum TALER_WalletAccountMergeFlags flags,
|
||||||
|
const struct TALER_Amount *purse_fee,
|
||||||
const struct TALER_Amount *amount,
|
const struct TALER_Amount *amount,
|
||||||
const struct TALER_PurseContractSignatureP *purse_sig,
|
const struct TALER_PurseContractSignatureP *purse_sig,
|
||||||
bool *in_conflict);
|
bool *in_conflict);
|
||||||
|
@ -250,6 +250,7 @@ TALER_EXCHANGE_purse_create_with_merge (
|
|||||||
const struct TALER_ContractDiffiePrivateP *contract_priv,
|
const struct TALER_ContractDiffiePrivateP *contract_priv,
|
||||||
const json_t *contract_terms,
|
const json_t *contract_terms,
|
||||||
bool upload_contract,
|
bool upload_contract,
|
||||||
|
bool pay_for_purse,
|
||||||
struct GNUNET_TIME_Timestamp merge_timestamp,
|
struct GNUNET_TIME_Timestamp merge_timestamp,
|
||||||
TALER_EXCHANGE_PurseCreateMergeCallback cb,
|
TALER_EXCHANGE_PurseCreateMergeCallback cb,
|
||||||
void *cb_cls)
|
void *cb_cls)
|
||||||
@ -268,6 +269,8 @@ TALER_EXCHANGE_purse_create_with_merge (
|
|||||||
struct TALER_PurseContractSignatureP purse_sig;
|
struct TALER_PurseContractSignatureP purse_sig;
|
||||||
void *econtract = NULL;
|
void *econtract = NULL;
|
||||||
size_t econtract_size = 0;
|
size_t econtract_size = 0;
|
||||||
|
struct TALER_Amount purse_fee;
|
||||||
|
enum TALER_WalletAccountMergeFlags flags;
|
||||||
|
|
||||||
pcm = GNUNET_new (struct TALER_EXCHANGE_PurseCreateMergeHandle);
|
pcm = GNUNET_new (struct TALER_EXCHANGE_PurseCreateMergeHandle);
|
||||||
pcm->exchange = exchange;
|
pcm->exchange = exchange;
|
||||||
@ -315,7 +318,22 @@ TALER_EXCHANGE_purse_create_with_merge (
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (pay_for_purse)
|
||||||
|
{
|
||||||
|
const struct TALER_EXCHANGE_GlobalFee *gf;
|
||||||
|
|
||||||
|
gf = TALER_EXCHANGE_get_global_fee (
|
||||||
|
TALER_EXCHANGE_get_keys (exchange),
|
||||||
|
GNUNET_TIME_timestamp_get ());
|
||||||
|
purse_fee = gf->fees.purse;
|
||||||
|
flags = TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TALER_amount_set_zero (pcm->purse_value_after_fees.currency,
|
||||||
|
&purse_fee);
|
||||||
|
flags = TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA;
|
||||||
|
}
|
||||||
|
|
||||||
GNUNET_assert (GNUNET_YES ==
|
GNUNET_assert (GNUNET_YES ==
|
||||||
TEAH_handle_is_ready (exchange));
|
TEAH_handle_is_ready (exchange));
|
||||||
@ -359,7 +377,9 @@ TALER_EXCHANGE_purse_create_with_merge (
|
|||||||
pcm->purse_expiration,
|
pcm->purse_expiration,
|
||||||
&pcm->h_contract_terms,
|
&pcm->h_contract_terms,
|
||||||
&pcm->purse_value_after_fees,
|
&pcm->purse_value_after_fees,
|
||||||
|
&purse_fee,
|
||||||
min_age,
|
min_age,
|
||||||
|
flags,
|
||||||
reserve_priv,
|
reserve_priv,
|
||||||
&reserve_sig);
|
&reserve_sig);
|
||||||
if (upload_contract)
|
if (upload_contract)
|
||||||
@ -398,6 +418,12 @@ TALER_EXCHANGE_purse_create_with_merge (
|
|||||||
&contract_pub)
|
&contract_pub)
|
||||||
: GNUNET_JSON_pack_string ("dummy",
|
: GNUNET_JSON_pack_string ("dummy",
|
||||||
NULL)),
|
NULL)),
|
||||||
|
GNUNET_JSON_pack_allow_null (
|
||||||
|
pay_for_purse
|
||||||
|
? TALER_JSON_pack_amount ("purse_fee",
|
||||||
|
&purse_fee)
|
||||||
|
: GNUNET_JSON_pack_string ("dummy2",
|
||||||
|
NULL)),
|
||||||
GNUNET_JSON_pack_data_auto ("merge_pub",
|
GNUNET_JSON_pack_data_auto ("merge_pub",
|
||||||
&merge_pub),
|
&merge_pub),
|
||||||
GNUNET_JSON_pack_data_auto ("merge_sig",
|
GNUNET_JSON_pack_data_auto ("merge_sig",
|
||||||
|
@ -349,14 +349,22 @@ TALER_EXCHANGE_account_merge (
|
|||||||
purse_pub,
|
purse_pub,
|
||||||
merge_priv,
|
merge_priv,
|
||||||
&merge_sig);
|
&merge_sig);
|
||||||
|
{
|
||||||
|
struct TALER_Amount zero_purse_fee;
|
||||||
|
|
||||||
|
TALER_amount_set_zero (purse_value_after_fees->currency,
|
||||||
|
&zero_purse_fee);
|
||||||
TALER_wallet_account_merge_sign (merge_timestamp,
|
TALER_wallet_account_merge_sign (merge_timestamp,
|
||||||
purse_pub,
|
purse_pub,
|
||||||
purse_expiration,
|
purse_expiration,
|
||||||
h_contract_terms,
|
h_contract_terms,
|
||||||
purse_value_after_fees,
|
purse_value_after_fees,
|
||||||
|
&zero_purse_fee,
|
||||||
min_age,
|
min_age,
|
||||||
|
TALER_WAMF_MODE_MERGE_FULLY_PAID_PURSE,
|
||||||
reserve_priv,
|
reserve_priv,
|
||||||
&reserve_sig);
|
&reserve_sig);
|
||||||
|
}
|
||||||
merge_obj = GNUNET_JSON_PACK (
|
merge_obj = GNUNET_JSON_PACK (
|
||||||
GNUNET_JSON_pack_string ("payto_uri",
|
GNUNET_JSON_pack_string ("payto_uri",
|
||||||
reserve_url),
|
reserve_url),
|
||||||
|
@ -187,6 +187,7 @@ purse_run (void *cls,
|
|||||||
&ds->contract_priv,
|
&ds->contract_priv,
|
||||||
ds->contract_terms,
|
ds->contract_terms,
|
||||||
true /* upload contract */,
|
true /* upload contract */,
|
||||||
|
false /* do not pay purse fee -- FIXME: make this a choice to test this case! */,
|
||||||
ds->merge_timestamp,
|
ds->merge_timestamp,
|
||||||
&purse_cb,
|
&purse_cb,
|
||||||
ds);
|
ds);
|
||||||
|
@ -1062,6 +1062,12 @@ struct TALER_AccountMergePS
|
|||||||
*/
|
*/
|
||||||
struct TALER_AmountNBO purse_amount;
|
struct TALER_AmountNBO purse_amount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purse creation fee to be paid by the reserve for
|
||||||
|
* this operation.
|
||||||
|
*/
|
||||||
|
struct TALER_AmountNBO purse_fee;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contract this purse pays for.
|
* Contract this purse pays for.
|
||||||
*/
|
*/
|
||||||
@ -1078,9 +1084,16 @@ struct TALER_AccountMergePS
|
|||||||
struct GNUNET_TIME_TimestampNBO merge_timestamp;
|
struct GNUNET_TIME_TimestampNBO merge_timestamp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minimum age required for payments into this purse.
|
* Minimum age required for payments into this purse,
|
||||||
|
* in NBO.
|
||||||
*/
|
*/
|
||||||
uint32_t min_age GNUNET_PACKED;
|
uint32_t min_age GNUNET_PACKED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flags for the operation, in NBO. See
|
||||||
|
* `enum TALER_WalletAccountMergeFlags`.
|
||||||
|
*/
|
||||||
|
uint32_t flags GNUNET_PACKED;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -1091,7 +1104,9 @@ TALER_wallet_account_merge_sign (
|
|||||||
struct GNUNET_TIME_Timestamp purse_expiration,
|
struct GNUNET_TIME_Timestamp purse_expiration,
|
||||||
const struct TALER_PrivateContractHashP *h_contract_terms,
|
const struct TALER_PrivateContractHashP *h_contract_terms,
|
||||||
const struct TALER_Amount *amount,
|
const struct TALER_Amount *amount,
|
||||||
|
const struct TALER_Amount *purse_fee,
|
||||||
uint32_t min_age,
|
uint32_t min_age,
|
||||||
|
enum TALER_WalletAccountMergeFlags flags,
|
||||||
const struct TALER_ReservePrivateKeyP *reserve_priv,
|
const struct TALER_ReservePrivateKeyP *reserve_priv,
|
||||||
struct TALER_ReserveSignatureP *reserve_sig)
|
struct TALER_ReserveSignatureP *reserve_sig)
|
||||||
{
|
{
|
||||||
@ -1102,11 +1117,14 @@ TALER_wallet_account_merge_sign (
|
|||||||
.purse_pub = *purse_pub,
|
.purse_pub = *purse_pub,
|
||||||
.purse_expiration = GNUNET_TIME_timestamp_hton (purse_expiration),
|
.purse_expiration = GNUNET_TIME_timestamp_hton (purse_expiration),
|
||||||
.h_contract_terms = *h_contract_terms,
|
.h_contract_terms = *h_contract_terms,
|
||||||
.min_age = htonl (min_age)
|
.min_age = htonl (min_age),
|
||||||
|
.flags = htonl ((uint32_t) flags)
|
||||||
};
|
};
|
||||||
|
|
||||||
TALER_amount_hton (&pm.purse_amount,
|
TALER_amount_hton (&pm.purse_amount,
|
||||||
amount);
|
amount);
|
||||||
|
TALER_amount_hton (&pm.purse_fee,
|
||||||
|
purse_fee);
|
||||||
GNUNET_CRYPTO_eddsa_sign (&reserve_priv->eddsa_priv,
|
GNUNET_CRYPTO_eddsa_sign (&reserve_priv->eddsa_priv,
|
||||||
&pm,
|
&pm,
|
||||||
&reserve_sig->eddsa_signature);
|
&reserve_sig->eddsa_signature);
|
||||||
@ -1120,7 +1138,9 @@ TALER_wallet_account_merge_verify (
|
|||||||
struct GNUNET_TIME_Timestamp purse_expiration,
|
struct GNUNET_TIME_Timestamp purse_expiration,
|
||||||
const struct TALER_PrivateContractHashP *h_contract_terms,
|
const struct TALER_PrivateContractHashP *h_contract_terms,
|
||||||
const struct TALER_Amount *amount,
|
const struct TALER_Amount *amount,
|
||||||
|
const struct TALER_Amount *purse_fee,
|
||||||
uint32_t min_age,
|
uint32_t min_age,
|
||||||
|
enum TALER_WalletAccountMergeFlags flags,
|
||||||
const struct TALER_ReservePublicKeyP *reserve_pub,
|
const struct TALER_ReservePublicKeyP *reserve_pub,
|
||||||
const struct TALER_ReserveSignatureP *reserve_sig)
|
const struct TALER_ReserveSignatureP *reserve_sig)
|
||||||
{
|
{
|
||||||
@ -1131,11 +1151,14 @@ TALER_wallet_account_merge_verify (
|
|||||||
.purse_pub = *purse_pub,
|
.purse_pub = *purse_pub,
|
||||||
.purse_expiration = GNUNET_TIME_timestamp_hton (purse_expiration),
|
.purse_expiration = GNUNET_TIME_timestamp_hton (purse_expiration),
|
||||||
.h_contract_terms = *h_contract_terms,
|
.h_contract_terms = *h_contract_terms,
|
||||||
.min_age = htonl (min_age)
|
.min_age = htonl (min_age),
|
||||||
|
.flags = htonl ((uint32_t) flags)
|
||||||
};
|
};
|
||||||
|
|
||||||
TALER_amount_hton (&pm.purse_amount,
|
TALER_amount_hton (&pm.purse_amount,
|
||||||
amount);
|
amount);
|
||||||
|
TALER_amount_hton (&pm.purse_fee,
|
||||||
|
purse_fee);
|
||||||
return GNUNET_CRYPTO_eddsa_verify (
|
return GNUNET_CRYPTO_eddsa_verify (
|
||||||
TALER_SIGNATURE_WALLET_ACCOUNT_MERGE,
|
TALER_SIGNATURE_WALLET_ACCOUNT_MERGE,
|
||||||
&pm,
|
&pm,
|
||||||
|
Loading…
Reference in New Issue
Block a user