diff options
| author | Christian Grothoff <christian@grothoff.org> | 2022-07-05 12:56:55 +0200 | 
|---|---|---|
| committer | Christian Grothoff <christian@grothoff.org> | 2022-07-05 12:56:55 +0200 | 
| commit | 7201ce3166127e45f924c3119c3037917d32e594 (patch) | |
| tree | 040aa858fbf78611081fb73239c71ee1ea735ec8 /src/exchangedb | |
| parent | 82cff16eea29fda6636b48d5980b48b1bc01236f (diff) | |
-handle withdraw CS nonce reuse more nicely
Diffstat (limited to 'src/exchangedb')
| -rw-r--r-- | src/exchangedb/exchange-0001-part.sql | 10 | ||||
| -rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 5 | 
2 files changed, 13 insertions, 2 deletions
| diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql index e2412995..d002fed8 100644 --- a/src/exchangedb/exchange-0001-part.sql +++ b/src/exchangedb/exchange-0001-part.sql @@ -1422,6 +1422,7 @@ CREATE OR REPLACE FUNCTION exchange_do_withdraw(    IN min_reserve_gc INT8,    OUT reserve_found BOOLEAN,    OUT balance_ok BOOLEAN, +  OUT nonce_ok BOOLEAN,    OUT kycok BOOLEAN,    OUT account_uuid INT8,    OUT ruuid INT8) @@ -1478,6 +1479,7 @@ THEN    -- reserve unknown    reserve_found=FALSE;    balance_ok=FALSE; +  nonce_ok=TRUE;    kycok=FALSE;    account_uuid=0;    ruuid=2; @@ -1511,6 +1513,7 @@ THEN    -- idempotent query, all constraints must be satisfied    reserve_found=TRUE;    balance_ok=TRUE; +  nonce_ok=TRUE;    kycok=TRUE;    account_uuid=0;    RETURN; @@ -1534,6 +1537,7 @@ ELSE      reserve_frac=reserve_frac - amount_frac;    ELSE      reserve_found=TRUE; +    nonce_ok=TRUE; -- we do not really know      balance_ok=FALSE;      kycok=FALSE; -- we do not really know or care      account_uuid=0; @@ -1585,10 +1589,12 @@ THEN        balance_ok=FALSE;        kycok=FALSE;        account_uuid=0; -      ruuid=1; -- FIXME: return error message more nicely! -      ASSERT false, 'nonce reuse attempted by client'; +      nonce_ok=FALSE; +      RETURN;      END IF;    END IF; +ELSE +  nonce_ok=TRUE; -- no nonce, hence OK!  END IF; diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 53be0364..63f07521 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -827,6 +827,7 @@ prepare_statements (struct PostgresClosure *pg)        "SELECT "        " reserve_found"        ",balance_ok" +      ",nonce_ok"        ",kycok AS kyc_ok"        ",account_uuid AS payment_target_uuid"        ",ruuid" @@ -5906,6 +5907,7 @@ postgres_get_withdraw_info (   * @param now current time (rounded)   * @param[out] found set to true if the reserve was found   * @param[out] balance_ok set to true if the balance was sufficient + * @param[out] nonce_ok set to false if the nonce was reused   * @param[out] kyc set to true if the kyc status of the reserve is satisfied   * @param[out] ruuid set to the reserve's UUID (reserves table row)   * @return query execution status @@ -5918,6 +5920,7 @@ postgres_do_withdraw (    struct GNUNET_TIME_Timestamp now,    bool *found,    bool *balance_ok, +  bool *nonce_ok,    struct TALER_EXCHANGEDB_KycStatus *kyc,    uint64_t *ruuid)  { @@ -5944,6 +5947,8 @@ postgres_do_withdraw (                                  balance_ok),      GNUNET_PQ_result_spec_bool ("kyc_ok",                                  &kyc->ok), +    GNUNET_PQ_result_spec_bool ("nonce_ok", +                                nonce_ok),      GNUNET_PQ_result_spec_uint64 ("payment_target_uuid",                                    &kyc->payment_target_uuid),      GNUNET_PQ_result_spec_uint64 ("ruuid", | 
