diff options
Diffstat (limited to 'src/exchangedb')
| -rw-r--r-- | src/exchangedb/0003-age_withdraw_commitments.sql | 35 | ||||
| -rw-r--r-- | src/exchangedb/0003-age_withdraw_reveals.sql | 37 | ||||
| -rw-r--r-- | src/exchangedb/exchange_do_batch_withdraw.sql | 6 | ||||
| -rw-r--r-- | src/exchangedb/exchange_do_batch_withdraw_insert.sql | 2 | ||||
| -rw-r--r-- | src/exchangedb/pg_do_batch_withdraw.c | 2 | 
5 files changed, 38 insertions, 44 deletions
| diff --git a/src/exchangedb/0003-age_withdraw_commitments.sql b/src/exchangedb/0003-age_withdraw_commitments.sql index d74a697c..3106a07a 100644 --- a/src/exchangedb/0003-age_withdraw_commitments.sql +++ b/src/exchangedb/0003-age_withdraw_commitments.sql @@ -26,20 +26,21 @@ BEGIN    PERFORM create_partitioned_table(      'CREATE TABLE %I'        '(age_withdraw_commitment_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -      ',h_commitment BYTEA CHECK (LENGTH(h_commitment)=64)' -      ',amount_with_fee_val INT8 NOT NULL' -      ',amount_with_fee_frac INT4 NOT NULL' -      ',max_age INT2 NOT NULL' -      ',reserve_pub BYTEA CHECK (LENGTH(reserve_pub)=32)' -      ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)' -      ',noreveal_index INT4 NOT NULL' +      ',h_commitment BYTEA NOT NULL CONSTRAINT h_commitment_length CHECK(LENGTH(h_commitment)=64)' +      ',max_age SMALLINT NOT NULL CONSTRAINT max_age_positive CHECK(max_age>=0)' +      ',reserve_pub BYTEA NOT NULL CONSTRAINT reserve_pub_length CHECK(LENGTH(reserve_pub)=32)' +      ',reserve_sig BYTEA NOT NULL CONSTRAINT reserve_sig_length CHECK(LENGTH(reserve_sig)=64)' +      ',noreveal_index SMALLINT NOT NULL CONSTRAINT noreveal_index_positive CHECK(noreveal_index>=0)' +      ',denominations_serials INT8[] NOT NULL CONSTRAINT denominations_serial_array_length CHECK(cardinality(denominations_serials)=cardinality(denom_sigs))' +      ',denom_sigs BYTEA[] NOT NULL CONSTRAINT denom_sigs_array_length CHECK(cardinality(denom_sigs)=cardinality(denominations_serials))'      ') %s ;'      ,table_name      ,'PARTITION BY HASH (reserve_pub)'      ,partition_suffix    );    PERFORM comment_partitioned_table( -     'Commitments made when withdrawing coins with age restriction and the gamma value chosen by the exchange.' +     'Commitments made when withdrawing coins with age restriction and the gamma value chosen by the exchange. ' +     'It also contains the blindly signed coins and related denominations.'      ,table_name      ,partition_suffix    ); @@ -68,11 +69,23 @@ BEGIN      ,partition_suffix    );    PERFORM comment_partitioned_column( -     'Signature of the reserve''s private key over the withdraw-age request' +     'Signature of the reserve''s private key over the age-withdraw request'      ,'reserve_sig'      ,table_name      ,partition_suffix    ); +  PERFORM comment_partitioned_column( +     'Array of references to the denominations' +    ,'denominations_serials' +    ,table_name +    ,partition_suffix +  ); +  PERFORM comment_partitioned_column( +     'Array of signatures over the blinded envelopes' +    ,'denom_sigs' +    ,table_name +    ,partition_suffix +  );  END  $$; @@ -122,13 +135,13 @@ END  $$; -INSERT INTO exchange_tables  +INSERT INTO exchange_tables    (name    ,version    ,action    ,partitioned    ,by_range) -VALUES  +VALUES    ('age_withdraw_commitments', 'exchange-0003', 'create',   TRUE ,FALSE),    ('age_withdraw_commitments', 'exchange-0003', 'constrain',TRUE ,FALSE),    ('age_withdraw_commitments', 'exchange-0003', 'foreign',  TRUE ,FALSE); diff --git a/src/exchangedb/0003-age_withdraw_reveals.sql b/src/exchangedb/0003-age_withdraw_reveals.sql index 1c55fb19..2ab73f4b 100644 --- a/src/exchangedb/0003-age_withdraw_reveals.sql +++ b/src/exchangedb/0003-age_withdraw_reveals.sql @@ -27,14 +27,11 @@ BEGIN      'CREATE TABLE %I'        '(age_withdraw_revealed_coins_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE        ',h_commitment BYTEA NOT NULL CHECK (LENGTH(h_commitment)=64)' -      ',freshcoin_index INT4 NOT NULL' -      ',denominations_serial INT8 NOT NULL' -      ',coin_ev BYTEA NOT NULL' +      ',coin_index INT4 NOT NULL'        ',h_coin_ev BYTEA CHECK (LENGTH(h_coin_ev)=64)' -      ',ev_sig BYTEA NOT NULL'      ') %s ;'      ,table_name -    ,'PARTITION BY HASH (h_commitment)' +    ,'PARTITION BY HASH (h_coin_ev)'      ,partition_suffix    );    PERFORM comment_partitioned_table( @@ -49,35 +46,17 @@ BEGIN      ,partition_suffix    );    PERFORM comment_partitioned_column( -     'Index of the coin in the withdraw-age request, which is implicitly a batch request' -    ,'freshcoin_index' +     'Index of the coin in the age-withdraw request, which is implicitly a batch request' +    ,'coin_index'      ,table_name      ,partition_suffix    );    PERFORM comment_partitioned_column( -     'Foreign key reference to the denominations' -    ,'denominations_serial' -    ,table_name -    ,partition_suffix -  ); -  PERFORM comment_partitioned_column( -     'Envelope of the new coin to be signed' -    ,'coin_ev' -    ,table_name -    ,partition_suffix -  ); -  PERFORM comment_partitioned_column( -     'Hash of the envelope of the new coin to be signed (for lookups)' +     'Hash of the envelope of the new coin to be signed (for lookups).  The corresponding signatures are stores in age_withdraw_commitments.denom_sigs.'      ,'h_coin_ev'      ,table_name      ,partition_suffix    ); -  PERFORM comment_partitioned_column( -     'Exchange signature over the envelope' -    ,'ev_sig' -    ,table_name -    ,partition_suffix -  );  END  $$; @@ -118,12 +97,6 @@ BEGIN      ' FOREIGN KEY (h_commitment)'      ' REFERENCES age_withdraw_commitments (h_commitment) ON DELETE CASCADE;'    ); -  EXECUTE FORMAT ( -    'ALTER TABLE ' || table_name || -    ' ADD CONSTRAINT ' || table_name || '_foreign_denominations_serial' -    ' FOREIGN KEY (denominations_serial) ' -    ' REFERENCES denominations (denominations_serial) ON DELETE CASCADE;' -  );  END  $$; diff --git a/src/exchangedb/exchange_do_batch_withdraw.sql b/src/exchangedb/exchange_do_batch_withdraw.sql index fedb7e91..64777bb3 100644 --- a/src/exchangedb/exchange_do_batch_withdraw.sql +++ b/src/exchangedb/exchange_do_batch_withdraw.sql @@ -20,6 +20,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw(    IN rpub BYTEA,    IN now INT8,    IN min_reserve_gc INT8, +-- TODO[oec]: add [IN] parameter for maximum age and [OUT] parameter for required age    OUT reserve_found BOOLEAN,    OUT balance_ok BOOLEAN,    OUT ruuid INT8) @@ -38,11 +39,13 @@ BEGIN  --         reserves_in by reserve_pub (SELECT)  --         wire_targets by wire_target_h_payto +  SELECT     current_balance_val    ,current_balance_frac    ,gc_date    ,reserve_uuid +-- TODO[oec]: get age requirements   INTO     reserve_val    ,reserve_frac @@ -60,6 +63,8 @@ THEN    RETURN;  END IF; +-- TODO[oec]: check age requirements +  -- Check reserve balance is sufficient.  IF (reserve_val > amount_val)  THEN @@ -99,6 +104,7 @@ balance_ok=TRUE;  END $$; +-- TODO[oec]: Update comment re: age requirements are implemented  COMMENT ON FUNCTION exchange_do_batch_withdraw(INT8, INT4, BYTEA, INT8, INT8)    IS 'Checks whether the reserve has sufficient balance for a withdraw operation (or the request is repeated and was previously approved) and if so updates the database with the result. Excludes storing the planchets.'; diff --git a/src/exchangedb/exchange_do_batch_withdraw_insert.sql b/src/exchangedb/exchange_do_batch_withdraw_insert.sql index 98db840f..27378674 100644 --- a/src/exchangedb/exchange_do_batch_withdraw_insert.sql +++ b/src/exchangedb/exchange_do_batch_withdraw_insert.sql @@ -15,7 +15,7 @@  -- - +-- TODO[oec]: add min. age requirements handling  CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw_insert(    IN cs_nonce BYTEA, diff --git a/src/exchangedb/pg_do_batch_withdraw.c b/src/exchangedb/pg_do_batch_withdraw.c index 3dee20d2..d93caa15 100644 --- a/src/exchangedb/pg_do_batch_withdraw.c +++ b/src/exchangedb/pg_do_batch_withdraw.c @@ -31,6 +31,7 @@ TEH_PG_do_batch_withdraw (    void *cls,    struct GNUNET_TIME_Timestamp now,    const struct TALER_ReservePublicKeyP *reserve_pub, +  /* TODO[oec]: add parameter for maximum age and [out]parameter for required age */    const struct TALER_Amount *amount,    bool *found,    bool *balance_ok, @@ -68,6 +69,7 @@ TEH_PG_do_batch_withdraw (             " reserve_found"             ",balance_ok"             ",ruuid" +           /* TODO[oec]: add parameter for maximum age and [out] parameter for required age */             " FROM exchange_do_batch_withdraw"             " ($1,$2,$3,$4,$5);");    return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, | 
