diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/exchange/taler-exchange-aggregator.c | 11 | ||||
| -rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-check.c | 30 | ||||
| -rw-r--r-- | src/exchange/taler-exchange-httpd_kyc-proof.c | 21 | ||||
| -rw-r--r-- | src/exchangedb/exchange-0001.sql | 52 | ||||
| -rw-r--r-- | src/exchangedb/irbt_callbacks.c | 13 | ||||
| -rw-r--r-- | src/exchangedb/lrbt_callbacks.c | 24 | ||||
| -rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 152 | ||||
| -rw-r--r-- | src/exchangedb/test_exchangedb.c | 14 | ||||
| -rw-r--r-- | src/include/taler_crypto_lib.h | 2 | ||||
| -rw-r--r-- | src/include/taler_exchange_service.h | 16 | ||||
| -rw-r--r-- | src/include/taler_exchangedb_plugin.h | 26 | ||||
| -rw-r--r-- | src/lib/exchange_api_kyc_proof.c | 22 | ||||
| -rw-r--r-- | src/lib/exchange_api_reserves_get.c | 2 | ||||
| -rw-r--r-- | src/testing/testing_api_cmd_kyc_proof.c | 17 | ||||
| -rw-r--r-- | src/util/payto.c | 9 | 
15 files changed, 224 insertions, 187 deletions
| diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c index 58bf2073..40653f9b 100644 --- a/src/exchange/taler-exchange-aggregator.c +++ b/src/exchange/taler-exchange-aggregator.c @@ -81,6 +81,11 @@ struct AggregationUnit    /**     * Selected wire target for the aggregation.     */ +  struct TALER_PaytoHashP h_payto; + +  /** +   * Serial number of the wire target. +   */    uint64_t wire_target;    /** @@ -426,6 +431,8 @@ deposit_cb (void *cls,    GNUNET_assert (NULL == au->payto_uri);    au->payto_uri = GNUNET_strdup (payto_uri); +  TALER_payto_hash (payto_uri, +                    &au->h_payto);    au->wire_target = wire_target;    GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,                                &au->wtid, @@ -775,7 +782,7 @@ run_aggregation (void *cls)                TALER_B2S (&au_active.merchant_pub),                (unsigned long long) au_active.wire_target);    qs = db_plugin->iterate_matching_deposits (db_plugin->cls, -                                             au_active.wire_target, +                                             &au_active.h_payto,                                               &au_active.merchant_pub,                                               &aggregate_cb,                                               &au_active, @@ -918,7 +925,7 @@ run_aggregation (void *cls)      qs = db_plugin->store_wire_transfer_out (db_plugin->cls,                                               au_active.execution_time,                                               &au_active.wtid, -                                             au_active.wire_target, +                                             &au_active.h_payto,                                               au_active.wa->section_name,                                               &au_active.final_amount);    cleanup_au (&au_active); diff --git a/src/exchange/taler-exchange-httpd_kyc-check.c b/src/exchange/taler-exchange-httpd_kyc-check.c index 1e7f4da1..ba918686 100644 --- a/src/exchange/taler-exchange-httpd_kyc-check.c +++ b/src/exchange/taler-exchange-httpd_kyc-check.c @@ -60,11 +60,16 @@ struct KycPoller    struct GNUNET_DB_EventHandler *eh;    /** -   * UUID being checked. +   * UUID found based on @e h_payto.     */    uint64_t payment_target_uuid;    /** +   * UUID being checked. +   */ +  uint64_t auth_payment_target_uuid; + +  /**     * Current KYC status.     */    struct TALER_EXCHANGEDB_KycStatus kyc; @@ -76,11 +81,6 @@ struct KycPoller    struct TALER_PaytoHashP h_payto;    /** -   * Hash of the payto:// URI that was given to us for auth. -   */ -  struct TALER_PaytoHashP auth_h_payto; - -  /**     * When will this request time out?     */    struct GNUNET_TIME_Absolute timeout; @@ -170,7 +170,6 @@ kyc_check (void *cls,    enum GNUNET_DB_QueryStatus qs;    qs = TEH_plugin->select_kyc_status (TEH_plugin->cls, -                                      kyp->payment_target_uuid,                                        &kyp->h_payto,                                        &kyp->kyc);    if (qs < 0) @@ -184,6 +183,9 @@ kyc_check (void *cls,                                             "inselect_wallet_status");      return qs;    } +  // FIXME: avoid duplicating this... +  kyp->payment_target_uuid = kyp->kyc.payment_target_uuid; +    return qs;  } @@ -261,7 +263,7 @@ TEH_handler_kyc_check (                                             TALER_EC_GENERIC_PARAMETER_MALFORMED,                                             "payment_target_uuid");        } -      kyp->payment_target_uuid = (uint64_t) payment_target_uuid; +      kyp->auth_payment_target_uuid = (uint64_t) payment_target_uuid;      }      {        const char *ts; @@ -308,8 +310,8 @@ TEH_handler_kyc_check (        if (GNUNET_OK !=            GNUNET_STRINGS_string_to_data (hps,                                           strlen (hps), -                                         &kyp->auth_h_payto, -                                         sizeof (kyp->auth_h_payto))) +                                         &kyp->h_payto, +                                         sizeof (kyp->h_payto)))        {          GNUNET_break_op (0);          return TALER_MHD_reply_with_error (rc->connection, @@ -334,7 +336,7 @@ TEH_handler_kyc_check (      struct TALER_KycCompletedEventP rep = {        .header.size = htons (sizeof (rep)),        .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED), -      .h_payto = kyp->auth_h_payto +      .h_payto = kyp->h_payto      };      GNUNET_log (GNUNET_ERROR_TYPE_INFO, @@ -356,9 +358,9 @@ TEH_handler_kyc_check (                                  kyp);    if (GNUNET_SYSERR == ret)      return res; -  if (0 != -      GNUNET_memcmp (&kyp->h_payto, -                     &kyp->auth_h_payto)) + +  if (kyp->auth_payment_target_uuid != +      kyp->payment_target_uuid)    {      GNUNET_break_op (0);      return TALER_MHD_reply_with_error (rc->connection, diff --git a/src/exchange/taler-exchange-httpd_kyc-proof.c b/src/exchange/taler-exchange-httpd_kyc-proof.c index 24ddfc74..333bd733 100644 --- a/src/exchange/taler-exchange-httpd_kyc-proof.c +++ b/src/exchange/taler-exchange-httpd_kyc-proof.c @@ -78,9 +78,9 @@ struct KycProofContext    char *id;    /** -   * Payment target this is about. +   * Hash of payment target URI this is about.     */ -  unsigned long long payment_target_uuid; +  struct TALER_PaytoHashP h_payto;    /**     * HTTP response to return. @@ -171,7 +171,7 @@ persist_kyc_ok (void *cls,    enum GNUNET_DB_QueryStatus qs;    qs = TEH_plugin->set_kyc_ok (TEH_plugin->cls, -                               kpc->payment_target_uuid, +                               &kpc->h_payto,                                 kpc->id);    if (GNUNET_DB_STATUS_HARD_ERROR == qs)    { @@ -530,24 +530,21 @@ TEH_handler_kyc_proof (    if (NULL == kpc)    { /* first time */ -    char dummy; -      kpc = GNUNET_new (struct KycProofContext);      kpc->rc = rc;      rc->rh_ctx = kpc;      rc->rh_cleaner = &clean_kpc; - -    if (1 != -        sscanf (args[0], -                "%llu%c", -                &kpc->payment_target_uuid, -                &dummy)) +    if (GNUNET_OK != +        GNUNET_STRINGS_string_to_data (args[0], +                                       strlen (args[0]), +                                       &kpc->h_payto, +                                       sizeof (kpc->h_payto)))      {        GNUNET_break_op (0);        return TALER_MHD_reply_with_error (rc->connection,                                           MHD_HTTP_BAD_REQUEST,                                           TALER_EC_GENERIC_PARAMETER_MALFORMED, -                                         "payment_target_uuid"); +                                         "h_payto");      }      kpc->authorization_code        = MHD_lookup_connection_value (rc->connection, diff --git a/src/exchangedb/exchange-0001.sql b/src/exchangedb/exchange-0001.sql index 1d86d5d9..3331eada 100644 --- a/src/exchangedb/exchange-0001.sql +++ b/src/exchangedb/exchange-0001.sql @@ -68,17 +68,17 @@ COMMENT ON TABLE denomination_revocations  CREATE TABLE IF NOT EXISTS wire_targets    (wire_target_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY -- UNIQUE -  ,h_payto BYTEA PRIMARY KEY CHECK (LENGTH(h_payto)=64) +  ,wire_target_h_payto BYTEA PRIMARY KEY CHECK (LENGTH(wire_target_h_payto)=32)    ,payto_uri VARCHAR NOT NULL    ,kyc_ok BOOLEAN NOT NULL DEFAULT (FALSE)    ,external_id VARCHAR    ) -  PARTITION BY HASH (h_payto); +  PARTITION BY HASH (wire_target_h_payto);  COMMENT ON TABLE wire_targets    IS 'All senders and recipients of money via the exchange';  COMMENT ON COLUMN wire_targets.payto_uri    IS 'Can be a regular bank account, or also be a URI identifying a reserve-account (for P2P payments)'; -COMMENT ON COLUMN wire_targets.h_payto +COMMENT ON COLUMN wire_targets.wire_target_h_payto    IS 'Unsalted hash of payto_uri';  COMMENT ON COLUMN wire_targets.kyc_ok    IS 'true if the KYC check was passed successfully'; @@ -106,7 +106,7 @@ $$;  SELECT add_constraints_to_wire_targets_partition('default'); --- FIXME partition by serial_id rather than h_payto,  +-- FIXME partition by serial_id rather than h_payto,  -- it is used more in join conditions - crucial for sharding to select this.  -- Author: (Boss Marco)  CREATE INDEX IF NOT EXISTS wire_targets_serial_id_index @@ -160,14 +160,14 @@ CREATE TABLE IF NOT EXISTS reserves_in    ,wire_reference INT8 NOT NULL    ,credit_val INT8 NOT NULL    ,credit_frac INT4 NOT NULL -  ,wire_source_serial_id INT8 NOT NULL -- REFERENCES wire_targets (wire_target_serial_id) +  ,wire_source_h_payto BYTEA CHECK (LENGTH(wire_source_h_payto)=32)    ,exchange_account_section TEXT NOT NULL    ,execution_date INT8 NOT NULL    )    PARTITION BY HASH (reserve_pub);  COMMENT ON TABLE reserves_in    IS 'list of transfers of funds into the reserves, one per incoming wire transfer'; -COMMENT ON COLUMN reserves_in.wire_source_serial_id +COMMENT ON COLUMN reserves_in.wire_source_h_payto    IS 'Identifies the debited bank account and KYC status';  COMMENT ON COLUMN reserves_in.reserve_pub    IS 'Public key of the reserve. Private key signifies ownership of the remaining balance.'; @@ -215,7 +215,7 @@ CREATE TABLE IF NOT EXISTS reserves_close    ,reserve_pub BYTEA NOT NULL REFERENCES reserves (reserve_pub) ON DELETE CASCADE    ,execution_date INT8 NOT NULL    ,wtid BYTEA NOT NULL CHECK (LENGTH(wtid)=32) -  ,wire_target_serial_id INT8 NOT NULL -- REFERENCES wire_targets (wire_target_serial_id) +  ,wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)    ,amount_val INT8 NOT NULL    ,amount_frac INT4 NOT NULL    ,closing_fee_val INT8 NOT NULL @@ -223,7 +223,7 @@ CREATE TABLE IF NOT EXISTS reserves_close    PARTITION BY HASH (reserve_pub);  COMMENT ON TABLE reserves_close    IS 'wire transfers executed by the reserve to close reserves'; -COMMENT ON COLUMN reserves_close.wire_target_serial_id +COMMENT ON COLUMN reserves_close.wire_target_h_payto    IS 'Identifies the credited bank account (and KYC status). Note that closing does not depend on KYC.';  CREATE TABLE IF NOT EXISTS reserves_close_default @@ -277,7 +277,7 @@ COMMENT ON COLUMN reserves_out.denominations_serial  CREATE TABLE IF NOT EXISTS reserves_out_default    PARTITION OF reserves_out    FOR VALUES WITH (MODULUS 1, REMAINDER 0); -   +  CREATE OR REPLACE FUNCTION add_constraints_to_reserves_out_partition(    IN partition_suffix VARCHAR  ) @@ -618,7 +618,7 @@ CREATE TABLE IF NOT EXISTS deposits    ,h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)    ,coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)    ,wire_salt BYTEA NOT NULL CHECK (LENGTH(wire_salt)=16) -  ,wire_target_serial_id INT8 NOT NULL -- REFERENCES wire_targets (wire_target_serial_id) +  ,wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)    ,tiny BOOLEAN NOT NULL DEFAULT FALSE    ,done BOOLEAN NOT NULL DEFAULT FALSE    ,extension_blocked BOOLEAN NOT NULL DEFAULT FALSE @@ -652,7 +652,7 @@ COMMENT ON TABLE deposits    IS 'Deposits we have received and for which we need to make (aggregate) wire transfers (and manage refunds).';  COMMENT ON COLUMN deposits.shard    IS 'Used for load sharding. Should be set based on h_payto and merchant_pub. 64-bit value because we need an *unsigned* 32-bit value.'; -COMMENT ON COLUMN deposits.wire_target_serial_id +COMMENT ON COLUMN deposits.wire_target_h_payto    IS 'Identifies the target bank account and KYC status';  COMMENT ON COLUMN deposits.wire_salt    IS 'Salt used when hashing the payto://-URI to get the h_wire'; @@ -685,7 +685,7 @@ COMMENT ON INDEX deposits_for_get_ready_index  CREATE INDEX IF NOT EXISTS deposits_for_iterate_matching_index    ON deposits    (merchant_pub -  ,wire_target_serial_id +  ,wire_target_h_payto    ,done    ,extension_blocked    ,refund_deadline ASC @@ -742,7 +742,7 @@ CREATE TABLE IF NOT EXISTS wire_out    (wireout_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY -- PRIMARY KEY    ,execution_date INT8 NOT NULL    ,wtid_raw BYTEA UNIQUE NOT NULL CHECK (LENGTH(wtid_raw)=32) -  ,wire_target_serial_id INT8 NOT NULL -- REFERENCES wire_targets (wire_target_serial_id) +  ,wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)    ,exchange_account_section TEXT NOT NULL    ,amount_val INT8 NOT NULL    ,amount_frac INT4 NOT NULL @@ -752,7 +752,7 @@ COMMENT ON TABLE wire_out    IS 'wire transfers the exchange has executed';  COMMENT ON COLUMN wire_out.exchange_account_section    IS 'identifies the configuration section with the debit account of this payment'; -COMMENT ON COLUMN wire_out.wire_target_serial_id +COMMENT ON COLUMN wire_out.wire_target_h_payto    IS 'Identifies the credited bank account and KYC status';  CREATE TABLE IF NOT EXISTS wire_out_default @@ -779,9 +779,9 @@ SELECT add_constraints_to_wire_out_partition('default');  CREATE INDEX IF NOT EXISTS wire_out_by_wireout_uuid_index    ON wire_out    (wireout_uuid); -CREATE INDEX IF NOT EXISTS wire_out_by_wire_target_serial_id_index +CREATE INDEX IF NOT EXISTS wire_out_by_wire_target_h_payto_index    ON wire_out -  (wire_target_serial_id); +  (wire_target_h_payto);  CREATE TABLE IF NOT EXISTS aggregation_tracking @@ -1143,7 +1143,7 @@ BEGIN  --         reserves_out (INSERT, with CONFLICT detection) by wih  --         reserves by reserve_pub (UPDATE)  --         reserves_in by reserve_pub (SELECT) ---         wire_targets by wire_target_serial_id +--         wire_targets by wire_target_h_payto  SELECT denominations_serial    INTO denom_serial @@ -1300,12 +1300,12 @@ END IF;  -- this reserve. FIXME: likely not adequate for reserves that got P2P transfers!  SELECT     kyc_ok -  ,wire_source_serial_id +  ,wire_target_serial_id    INTO     kycok    ,account_uuid    FROM reserves_in -  JOIN wire_targets ON (wire_source_serial_id = wire_target_serial_id) +  JOIN wire_targets ON (wire_source_h_payto = wire_target_h_payto)   WHERE reserve_pub=rpub   LIMIT 1; -- limit 1 should not be required (without p2p transfers) @@ -1370,8 +1370,8 @@ IF EXISTS (    SELECT 1      FROM information_Schema.constraint_column_usage     WHERE table_name='wire_out' -     AND constraint_name='wire_out_ref')  -THEN  +     AND constraint_name='wire_out_ref') +THEN    SET CONSTRAINTS wire_out_ref DEFERRED;  END IF; @@ -1424,12 +1424,12 @@ END IF;  INSERT INTO wire_targets -  (h_payto +  (wire_target_h_payto    ,payto_uri)    VALUES    (in_h_payto    ,in_receiver_wire_account) -ON CONFLICT DO NOTHING -- for CONFLICT ON (h_payto) +ON CONFLICT DO NOTHING -- for CONFLICT ON (wire_target_h_payto)    RETURNING wire_target_serial_id INTO wtsi;  IF NOT FOUND @@ -1437,7 +1437,7 @@ THEN    SELECT wire_target_serial_id    INTO wtsi    FROM wire_targets -  WHERE h_payto=in_h_payto; +  WHERE wire_target_h_payto=in_h_payto;  END IF; @@ -1454,7 +1454,7 @@ INSERT INTO deposits    ,h_contract_terms    ,coin_sig    ,wire_salt -  ,wire_target_serial_id +  ,wire_target_h_payto    ,extension_blocked    ,extension_details_serial_id    ) @@ -1471,7 +1471,7 @@ INSERT INTO deposits    ,in_h_contract_terms    ,in_coin_sig    ,in_wire_salt -  ,wtsi +  ,in_h_payto    ,in_extension_blocked    ,xdi)    ON CONFLICT DO NOTHING; diff --git a/src/exchangedb/irbt_callbacks.c b/src/exchangedb/irbt_callbacks.c index 97ce2c09..012f8df2 100644 --- a/src/exchangedb/irbt_callbacks.c +++ b/src/exchangedb/irbt_callbacks.c @@ -176,7 +176,8 @@ irbt_cb_table_reserves_in (struct PostgresClosure *pg,      GNUNET_PQ_query_param_uint64 (&td->serial),      GNUNET_PQ_query_param_uint64 (&td->details.reserves_in.wire_reference),      TALER_PQ_query_param_amount (&td->details.reserves_in.credit), -    GNUNET_PQ_query_param_uint64 (&td->details.reserves_in.sender_account), +    GNUNET_PQ_query_param_auto_from_type ( +      &td->details.reserves_in.sender_account_h_payto),      GNUNET_PQ_query_param_string (        td->details.reserves_in.exchange_account_section),      GNUNET_PQ_query_param_timestamp ( @@ -207,8 +208,8 @@ irbt_cb_table_reserves_close (struct PostgresClosure *pg,        &td->details.reserves_close.execution_date),      GNUNET_PQ_query_param_auto_from_type (        &td->details.reserves_close.wtid), -    GNUNET_PQ_query_param_uint64 ( -      &td->details.reserves_close.wire_target_serial_id), +    GNUNET_PQ_query_param_auto_from_type ( +      &td->details.reserves_close.sender_account_h_payto),      TALER_PQ_query_param_amount (&td->details.reserves_close.amount),      TALER_PQ_query_param_amount (&td->details.reserves_close.closing_fee),      GNUNET_PQ_query_param_auto_from_type ( @@ -523,7 +524,8 @@ irbt_cb_table_deposits (struct PostgresClosure *pg,        &td->details.deposits.h_contract_terms),      GNUNET_PQ_query_param_auto_from_type (&td->details.deposits.coin_sig),      GNUNET_PQ_query_param_auto_from_type (&td->details.deposits.wire_salt), -    GNUNET_PQ_query_param_uint64 (&td->details.deposits.wire_target_serial_id), +    GNUNET_PQ_query_param_auto_from_type ( +      &td->details.deposits.wire_target_h_payto),      GNUNET_PQ_query_param_bool (td->details.deposits.tiny),      GNUNET_PQ_query_param_bool (td->details.deposits.done),      GNUNET_PQ_query_param_bool (td->details.deposits.extension_blocked), @@ -579,7 +581,8 @@ irbt_cb_table_wire_out (struct PostgresClosure *pg,      GNUNET_PQ_query_param_uint64 (&td->serial),      GNUNET_PQ_query_param_timestamp (&td->details.wire_out.execution_date),      GNUNET_PQ_query_param_auto_from_type (&td->details.wire_out.wtid_raw), -    GNUNET_PQ_query_param_uint64 (&td->details.wire_out.wire_target_serial_id), +    GNUNET_PQ_query_param_auto_from_type ( +      &td->details.wire_out.wire_target_h_payto),      GNUNET_PQ_query_param_string (        td->details.wire_out.exchange_account_section),      TALER_PQ_query_param_amount (&td->details.wire_out.amount), diff --git a/src/exchangedb/lrbt_callbacks.c b/src/exchangedb/lrbt_callbacks.c index 01eddc5a..f7b0e28d 100644 --- a/src/exchangedb/lrbt_callbacks.c +++ b/src/exchangedb/lrbt_callbacks.c @@ -289,9 +289,9 @@ lrbt_cb_table_reserves_in (void *cls,        TALER_PQ_RESULT_SPEC_AMOUNT (          "credit",          &td.details.reserves_in.credit), -      GNUNET_PQ_result_spec_uint64 ( -        "wire_source_serial_id", -        &td.details.reserves_in.sender_account), +      GNUNET_PQ_result_spec_auto_from_type ( +        "wire_source_h_payto", +        &td.details.reserves_in.sender_account_h_payto),        GNUNET_PQ_result_spec_string (          "exchange_account_section",          &td.details.reserves_in.exchange_account_section), @@ -350,9 +350,9 @@ lrbt_cb_table_reserves_close (void *cls,        GNUNET_PQ_result_spec_auto_from_type (          "wtid",          &td.details.reserves_close.wtid), -      GNUNET_PQ_result_spec_uint64 ( -        "wire_target_serial_id", -        &td.details.reserves_close.wire_target_serial_id), +      GNUNET_PQ_result_spec_auto_from_type ( +        "wire_target_h_payto", +        &td.details.reserves_close.sender_account_h_payto),        TALER_PQ_RESULT_SPEC_AMOUNT (          "amount",          &td.details.reserves_close.amount), @@ -947,9 +947,9 @@ lrbt_cb_table_deposits (void *cls,        GNUNET_PQ_result_spec_auto_from_type (          "wire_salt",          &td.details.deposits.wire_salt), -      GNUNET_PQ_result_spec_uint64 ( -        "wire_target_serial_id", -        &td.details.deposits.wire_target_serial_id), +      GNUNET_PQ_result_spec_auto_from_type ( +        "wire_target_h_payto", +        &td.details.deposits.wire_target_h_payto),        GNUNET_PQ_result_spec_bool (          "tiny",          &td.details.deposits.tiny), @@ -1067,9 +1067,9 @@ lrbt_cb_table_wire_out (void *cls,        GNUNET_PQ_result_spec_auto_from_type (          "wtid_raw",          &td.details.wire_out.wtid_raw), -      GNUNET_PQ_result_spec_uint64 ( -        "wire_target_serial_id", -        &td.details.wire_out.wire_target_serial_id), +      GNUNET_PQ_result_spec_auto_from_type ( +        "wire_target_h_payto", +        &td.details.wire_out.wire_target_h_payto),        GNUNET_PQ_result_spec_string (          "exchange_account_section",          &td.details.wire_out.exchange_account_section), diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 86480f29..53fd10e3 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -429,7 +429,7 @@ prepare_statements (struct PostgresClosure *pg)        " FROM reserves"        " JOIN reserves_in ri USING (reserve_pub)"        " JOIN wire_targets wt " -      "  ON (ri.wire_source_serial_id = wt.wire_target_serial_id)" +      "  ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"        " WHERE reserve_pub=$1"        " LIMIT 1;",        1), @@ -439,31 +439,21 @@ prepare_statements (struct PostgresClosure *pg)        "UPDATE wire_targets"        " SET kyc_ok=TRUE"        ",external_id=$2" -      " WHERE wire_target_serial_id=$1", +      " WHERE wire_target_h_payto=$1",        2),      GNUNET_PQ_make_prepare (        "get_kyc_h_payto",        "SELECT" -      " h_payto" +      " wire_target_h_payto"        " FROM wire_targets" -      " WHERE wire_target_serial_id=$1" +      " WHERE wire_target_h_payto=$1"        " LIMIT 1;",        1), -    /* Used in #postgres_select_kyc_status() */ -    GNUNET_PQ_make_prepare ( -      "select_kyc_status", -      "SELECT" -      " kyc_ok" -      ",h_payto" -      " FROM wire_targets" -      " WHERE" -      " wire_target_serial_id=$1", -      1),      /* Used in #postgres_inselect_wallet_kyc_status() */      GNUNET_PQ_make_prepare (        "insert_kyc_status",        "INSERT INTO wire_targets" -      "  (h_payto" +      "  (wire_target_h_payto"        "  ,payto_uri"        "  ) VALUES "        "  ($1, $2)" @@ -475,7 +465,7 @@ prepare_statements (struct PostgresClosure *pg)        " kyc_ok"        ",wire_target_serial_id"        " FROM wire_targets" -      " WHERE h_payto=$1;", +      " WHERE wire_target_h_payto=$1;",        1),      /* Used in #reserves_get() */      GNUNET_PQ_make_prepare ( @@ -509,7 +499,7 @@ prepare_statements (struct PostgresClosure *pg)        "(reserve_pub"        ",execution_date"        ",wtid" -      ",wire_target_serial_id" +      ",wire_target_h_payto"        ",amount_val"        ",amount_frac"        ",closing_fee_val" @@ -536,11 +526,12 @@ prepare_statements (struct PostgresClosure *pg)        ",credit_val"        ",credit_frac"        ",exchange_account_section" -      ",wire_source_serial_id" +      ",wire_source_h_payto"        ",execution_date"        ") VALUES ($1, $2, $3, $4, $5, $6, $7)"        " ON CONFLICT DO NOTHING;",        7), +#if FIXME_DEAD      /* Used in #postgres_reserves_in_insert() to store transaction details */      GNUNET_PQ_make_prepare (        "reserves_in_add_by_pub", @@ -550,11 +541,12 @@ prepare_statements (struct PostgresClosure *pg)        ",credit_val"        ",credit_frac"        ",exchange_account_section" -      ",wire_source_serial_id" +      ",wire_source_h_payto"        ",execution_date"        ") VALUES ($1, $2, $3, $4, $5, $6, $7)"        " ON CONFLICT DO NOTHING;",        7), +#endif      /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound         transactions for reserves with serial id '\geq' the given parameter */      GNUNET_PQ_make_prepare ( @@ -571,7 +563,7 @@ prepare_statements (struct PostgresClosure *pg)        " JOIN reserves"        "   USING (reserve_pub)"        " JOIN wire_targets" -      "   ON (wire_source_serial_id = wire_target_serial_id)" +      "   ON (wire_source_h_payto = wire_target_h_payto)"        " WHERE reserve_in_serial_id>=$1"        " ORDER BY reserve_in_serial_id;",        1), @@ -591,7 +583,7 @@ prepare_statements (struct PostgresClosure *pg)        " JOIN reserves "        "   USING (reserve_pub)"        " JOIN wire_targets" -      "   ON (wire_source_serial_id = wire_target_serial_id)" +      "   ON (wire_source_h_payto = wire_target_h_payto)"        " WHERE reserve_in_serial_id>=$1 AND exchange_account_section=$2"        " ORDER BY reserve_in_serial_id;",        2), @@ -607,7 +599,7 @@ prepare_statements (struct PostgresClosure *pg)        ",payto_uri AS sender_account_details"        " FROM reserves_in"        " JOIN wire_targets" -      "   ON (wire_source_serial_id = wire_target_serial_id)" +      "   ON (wire_source_h_payto = wire_target_h_payto)"        " WHERE reserve_pub=$1;",        1),      /* Used in #postgres_do_withdraw() to store @@ -1067,7 +1059,7 @@ prepare_statements (struct PostgresClosure *pg)        ",merchant_pub"        ",h_contract_terms"        ",wire_salt" -      ",wire_target_serial_id" +      ",wire_target_h_payto"        ",coin_sig"        ",exchange_timestamp"        ",shard" @@ -1096,7 +1088,7 @@ prepare_statements (struct PostgresClosure *pg)        " FROM deposits"        " JOIN known_coins USING (known_coin_id)"        " JOIN denominations USING (denominations_serial)" -      " JOIN wire_targets USING (wire_target_serial_id)" +      " JOIN wire_targets USING (wire_target_h_payto)"        " WHERE ((coin_pub=$1)"        "    AND (merchant_pub=$3)"        "    AND (h_contract_terms=$2));", @@ -1122,7 +1114,7 @@ prepare_statements (struct PostgresClosure *pg)        ",done"        ",deposit_serial_id"        " FROM deposits" -      "    JOIN wire_targets USING (wire_target_serial_id)" +      "    JOIN wire_targets USING (wire_target_h_payto)"        "    JOIN known_coins kc USING (known_coin_id)"        "    JOIN denominations denom USING (denominations_serial)"        " WHERE (" @@ -1145,7 +1137,7 @@ prepare_statements (struct PostgresClosure *pg)        ",denom.fee_deposit_frac"        ",wire_deadline"        " FROM deposits" -      "    JOIN wire_targets USING (wire_target_serial_id)" +      "    JOIN wire_targets USING (wire_target_h_payto)"        "    JOIN known_coins USING (known_coin_id)"        "    JOIN denominations denom USING (denominations_serial)"        " WHERE ((coin_pub=$1)" @@ -1169,7 +1161,7 @@ prepare_statements (struct PostgresClosure *pg)        ",kc.coin_pub"        " FROM deposits"        "  JOIN wire_targets " -      "    USING (wire_target_serial_id)" +      "    USING (wire_target_h_payto)"        "  JOIN known_coins kc"        "    USING (known_coin_id)"        "  JOIN denominations denom" @@ -1203,7 +1195,7 @@ prepare_statements (struct PostgresClosure *pg)        "    JOIN denominations denom USING (denominations_serial)"        " WHERE"        "      merchant_pub=$1" -      "  AND wire_target_serial_id=$2" +      "  AND wire_target_h_payto=$2"        "  AND done=FALSE"        "  AND extension_blocked=FALSE"        "  AND refund_deadline<$3" @@ -1251,7 +1243,7 @@ prepare_statements (struct PostgresClosure *pg)        ",done"        " FROM deposits"        "    JOIN wire_targets" -      "      USING (wire_target_serial_id)" +      "      USING (wire_target_h_payto)"        "    JOIN known_coins kc"        "      USING (known_coin_id)"        "    JOIN denominations denoms" @@ -1287,7 +1279,7 @@ prepare_statements (struct PostgresClosure *pg)        " aggregation_serial_id"        ",deposits.h_contract_terms"        ",payto_uri" -      ",h_payto" +      ",wire_targets.wire_target_h_payto"        ",kc.coin_pub"        ",deposits.merchant_pub"        ",wire_out.execution_date" @@ -1300,7 +1292,7 @@ prepare_statements (struct PostgresClosure *pg)        "    JOIN deposits"        "      USING (deposit_serial_id)"        "    JOIN wire_targets" -      "      USING (wire_target_serial_id)" +      "      USING (wire_target_h_payto)"        "    JOIN known_coins kc"        "      USING (known_coin_id)"        "    JOIN denominations denom" @@ -1323,7 +1315,7 @@ prepare_statements (struct PostgresClosure *pg)        ",denom.fee_deposit_frac"        " FROM deposits"        "    JOIN wire_targets" -      "      USING (wire_target_serial_id)" +      "      USING (wire_target_h_payto)"        "    JOIN aggregation_tracking"        "      USING (deposit_serial_id)"        "    JOIN known_coins" @@ -1382,7 +1374,7 @@ prepare_statements (struct PostgresClosure *pg)        "INSERT INTO wire_out "        "(execution_date"        ",wtid_raw" -      ",wire_target_serial_id" +      ",wire_target_h_payto"        ",exchange_account_section"        ",amount_val"        ",amount_frac" @@ -1395,7 +1387,7 @@ prepare_statements (struct PostgresClosure *pg)        "(wireout_uuid"        ",execution_date"        ",wtid_raw" -      ",wire_target_serial_id" +      ",wire_target_h_payto"        ",exchange_account_section"        ",amount_val"        ",amount_frac" @@ -1456,7 +1448,7 @@ prepare_statements (struct PostgresClosure *pg)        "   JOIN known_coins"        "     USING (known_coin_id)"        "   JOIN wire_targets" -      "     USING (wire_target_serial_id)" +      "     USING (wire_target_h_payto)"        " WHERE wire_deadline >= $1"        " AND wire_deadline < $2"        " AND NOT (EXISTS (SELECT 1" @@ -1480,7 +1472,7 @@ prepare_statements (struct PostgresClosure *pg)        ",amount_frac"        " FROM wire_out"        "   JOIN wire_targets" -      "     USING (wire_target_serial_id)" +      "     USING (wire_target_h_payto)"        " WHERE wireout_uuid>=$1"        " ORDER BY wireout_uuid ASC;",        1), @@ -1496,7 +1488,7 @@ prepare_statements (struct PostgresClosure *pg)        ",amount_frac"        " FROM wire_out"        "   JOIN wire_targets" -      "     USING (wire_target_serial_id)" +      "     USING (wire_target_h_payto)"        " WHERE "        "      wireout_uuid>=$1 "        "  AND exchange_account_section=$2" @@ -1580,7 +1572,7 @@ prepare_statements (struct PostgresClosure *pg)        ",closing_fee_frac"        " FROM reserves_close"        "   JOIN wire_targets" -      "     USING (wire_target_serial_id)" +      "     USING (wire_target_h_payto)"        "   JOIN reserves"        "     USING (reserve_pub)"        " WHERE close_uuid>=$1" @@ -1649,7 +1641,7 @@ prepare_statements (struct PostgresClosure *pg)        ",wtid"        " FROM reserves_close"        "   JOIN wire_targets" -      "     USING (wire_target_serial_id)" +      "     USING (wire_target_h_payto)"        " WHERE reserve_pub=$1;",        1),      /* Used in #postgres_get_expired_reserves() */ @@ -1665,7 +1657,7 @@ prepare_statements (struct PostgresClosure *pg)        "   JOIN reserves_in ri"        "     USING (reserve_pub)"        "   JOIN wire_targets wt" -      "     ON (ri.wire_source_serial_id = wt.wire_target_serial_id)" +      "     ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"        " WHERE expiration_date<=$1"        "   AND (current_balance_val != 0 "        "        OR current_balance_frac != 0)" @@ -2198,7 +2190,7 @@ prepare_statements (struct PostgresClosure *pg)        ",wire_reference"        ",credit_val"        ",credit_frac" -      ",wire_source_serial_id" +      ",wire_source_h_payto"        ",exchange_account_section"        ",execution_date"        " FROM reserves_in" @@ -2212,7 +2204,7 @@ prepare_statements (struct PostgresClosure *pg)        ",reserve_pub"        ",execution_date"        ",wtid" -      ",wire_target_serial_id" +      ",wire_target_h_payto"        ",amount_val"        ",amount_frac"        ",closing_fee_val" @@ -2354,7 +2346,7 @@ prepare_statements (struct PostgresClosure *pg)        ",h_contract_terms"        ",coin_sig"        ",wire_salt" -      ",wire_target_serial_id" +      ",wire_target_h_payto"        ",tiny"        ",done"        ",extension_blocked" @@ -2382,7 +2374,7 @@ prepare_statements (struct PostgresClosure *pg)        " wireout_uuid AS serial"        ",execution_date"        ",wtid_raw" -      ",wire_target_serial_id" +      ",wire_target_h_payto"        ",exchange_account_section"        ",amount_val"        ",amount_frac" @@ -2487,7 +2479,7 @@ prepare_statements (struct PostgresClosure *pg)        "insert_into_table_wire_targets",        "INSERT INTO wire_targets"        "(wire_target_serial_id" -      ",h_payto" +      ",wire_target_h_payto"        ",payto_uri"        ",kyc_ok"        ",external_id" @@ -2513,7 +2505,7 @@ prepare_statements (struct PostgresClosure *pg)        ",wire_reference"        ",credit_val"        ",credit_frac" -      ",wire_source_serial_id" +      ",wire_source_h_payto"        ",exchange_account_section"        ",execution_date"        ",reserve_pub" @@ -2526,7 +2518,7 @@ prepare_statements (struct PostgresClosure *pg)        "(close_uuid"        ",execution_date"        ",wtid" -      ",wire_target_serial_id" +      ",wire_target_h_payto"        ",amount_val"        ",amount_frac"        ",closing_fee_val" @@ -2660,7 +2652,7 @@ prepare_statements (struct PostgresClosure *pg)        ",h_contract_terms"        ",coin_sig"        ",wire_salt" -      ",wire_target_serial_id" +      ",wire_target_h_payto"        ",tiny"        ",done"        ",extension_blocked" @@ -3914,22 +3906,22 @@ postgres_reserves_get (void *cls,   * Set the KYC status to "OK" for a bank account.   *   * @param cls the @e cls of this struct with the plugin-specific state - * @param payment_target_uuid which account has been checked + * @param h_payto which account has been checked   * @param id external ID to persist   * @return transaction status   */  static enum GNUNET_DB_QueryStatus  postgres_set_kyc_ok (void *cls, -                     uint64_t payment_target_uuid, +                     const struct TALER_PaytoHashP *h_payto,                       const char *id)  {    struct PostgresClosure *pg = cls;    struct GNUNET_PQ_QueryParam params[] = { -    GNUNET_PQ_query_param_uint64 (&payment_target_uuid), +    GNUNET_PQ_query_param_auto_from_type (h_payto),      GNUNET_PQ_query_param_end    };    struct GNUNET_PQ_QueryParam params2[] = { -    GNUNET_PQ_query_param_uint64 (&payment_target_uuid), +    GNUNET_PQ_query_param_auto_from_type (h_payto),      GNUNET_PQ_query_param_string (id),      GNUNET_PQ_query_param_end    }; @@ -3938,7 +3930,7 @@ postgres_set_kyc_ok (void *cls,      .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED)    };    struct GNUNET_PQ_ResultSpec rs[] = { -    GNUNET_PQ_result_spec_auto_from_type ("h_payto", +    GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",                                            &rep.h_payto),      GNUNET_PQ_result_spec_end    }; @@ -3967,34 +3959,31 @@ postgres_set_kyc_ok (void *cls,   * Get the @a kyc status and @a h_payto by UUID.   *   * @param cls the @e cls of this struct with the plugin-specific state - * @param payment_target_uuid which account to get the KYC status for - * @param[out] h_payto set to the hash of the account's payto URI (unsalted) + * @param h_payto set to the hash of the account's payto URI (unsalted)   * @param[out] kyc set to the KYC status of the account   * @return transaction status   */  static enum GNUNET_DB_QueryStatus  postgres_select_kyc_status (void *cls, -                            uint64_t payment_target_uuid, -                            struct TALER_PaytoHashP *h_payto, +                            const struct TALER_PaytoHashP *h_payto,                              struct TALER_EXCHANGEDB_KycStatus *kyc)  {    struct PostgresClosure *pg = cls;    struct GNUNET_PQ_QueryParam params[] = { -    GNUNET_PQ_query_param_uint64 (&payment_target_uuid), +    GNUNET_PQ_query_param_auto_from_type (&h_payto),      GNUNET_PQ_query_param_end    };    struct GNUNET_PQ_ResultSpec rs[] = { -    GNUNET_PQ_result_spec_auto_from_type ("h_payto", -                                          h_payto), -    GNUNET_PQ_result_spec_auto_from_type ("kyc_ok", -                                          &kyc->ok), +    GNUNET_PQ_result_spec_uint64 ("wire_target_serial_id", +                                  &kyc->payment_target_uuid), +    GNUNET_PQ_result_spec_bool ("kyc_ok", +                                &kyc->ok),      GNUNET_PQ_result_spec_end    };    kyc->type = TALER_EXCHANGEDB_KYC_UNKNOWN; -  kyc->payment_target_uuid = payment_target_uuid;    return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, -                                                   "select_kyc_status", +                                                   "select_kyc_status_by_payto",                                                     params,                                                     rs);  } @@ -4015,7 +4004,6 @@ inselect_account_kyc_status (    const char *payto_uri,    struct TALER_EXCHANGEDB_KycStatus *kyc)  { -    struct TALER_PaytoHashP h_payto;    enum GNUNET_DB_QueryStatus qs; @@ -4267,10 +4255,14 @@ postgres_reserves_in_insert (void *cls,      enum GNUNET_DB_QueryStatus qs2;      struct TALER_EXCHANGEDB_KycStatus kyc;      enum GNUNET_DB_QueryStatus qs3; +    struct TALER_PaytoHashP h_payto; +    TALER_payto_hash (sender_account_details, +                      &h_payto);      memset (&kyc,              0,              sizeof (kyc)); +    /* FIXME: inselect re-computes h_payto... */      qs3 = inselect_account_kyc_status (pg,                                         sender_account_details,                                         &kyc); @@ -4286,7 +4278,7 @@ postgres_reserves_in_insert (void *cls,        GNUNET_PQ_query_param_uint64 (&wire_ref),        TALER_PQ_query_param_amount (balance),        GNUNET_PQ_query_param_string (exchange_account_section), -      GNUNET_PQ_query_param_uint64 (&kyc.payment_target_uuid), +      GNUNET_PQ_query_param_auto_from_type (&h_payto),        GNUNET_PQ_query_param_timestamp (&execution_time),        GNUNET_PQ_query_param_end      }; @@ -5686,7 +5678,7 @@ match_deposit_cb (void *cls,   * destination.  Those deposits must not already be "done".   *   * @param cls the @e cls of this struct with the plugin-specific state - * @param wire_target destination of the wire transfer + * @param h_payto destination of the wire transfer   * @param merchant_pub public key of the merchant   * @param deposit_cb function to call for each deposit   * @param deposit_cb_cls closure for @a deposit_cb @@ -5697,7 +5689,7 @@ match_deposit_cb (void *cls,  static enum GNUNET_DB_QueryStatus  postgres_iterate_matching_deposits (    void *cls, -  uint64_t wire_target, +  const struct TALER_PaytoHashP *h_payto,    const struct TALER_MerchantPublicKeyP *merchant_pub,    TALER_EXCHANGEDB_MatchingDepositIterator deposit_cb,    void *deposit_cb_cls, @@ -5707,7 +5699,7 @@ postgres_iterate_matching_deposits (    struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();    struct GNUNET_PQ_QueryParam params[] = {      GNUNET_PQ_query_param_auto_from_type (merchant_pub), -    GNUNET_PQ_query_param_uint64 (&wire_target), +    GNUNET_PQ_query_param_auto_from_type (h_payto),      GNUNET_PQ_query_param_absolute_time (&now),      GNUNET_PQ_query_param_end    }; @@ -5955,7 +5947,11 @@ postgres_insert_deposit (void *cls,    struct PostgresClosure *pg = cls;    struct TALER_EXCHANGEDB_KycStatus kyc;    enum GNUNET_DB_QueryStatus qs; +  struct TALER_PaytoHashP h_payto; +  TALER_payto_hash (deposit->receiver_wire_account, +                    &h_payto); +  /* FIXME: inselect re-computes h_payto... */    qs = inselect_account_kyc_status (pg,                                      deposit->receiver_wire_account,                                      &kyc); @@ -5975,7 +5971,7 @@ postgres_insert_deposit (void *cls,        GNUNET_PQ_query_param_auto_from_type (&deposit->merchant_pub),        GNUNET_PQ_query_param_auto_from_type (&deposit->h_contract_terms),        GNUNET_PQ_query_param_auto_from_type (&deposit->wire_salt), -      GNUNET_PQ_query_param_uint64 (&kyc.payment_target_uuid), +      GNUNET_PQ_query_param_auto_from_type (&h_payto),        GNUNET_PQ_query_param_auto_from_type (&deposit->csig),        GNUNET_PQ_query_param_timestamp (&exchange_timestamp),        GNUNET_PQ_query_param_uint64 (&shard), @@ -7264,7 +7260,7 @@ handle_wt_result (void *cls,                                              &h_contract_terms),        GNUNET_PQ_result_spec_string ("payto_uri",                                      &payto_uri), -      GNUNET_PQ_result_spec_auto_from_type ("h_payto", +      GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",                                              &h_payto),        TALER_PQ_result_spec_denom_pub ("denom_pub",                                        &denom_pub), @@ -7798,7 +7794,11 @@ postgres_insert_reserve_closed (    struct TALER_EXCHANGEDB_Reserve reserve;    struct TALER_EXCHANGEDB_KycStatus kyc;    enum GNUNET_DB_QueryStatus qs; +  struct TALER_PaytoHashP h_payto; +  TALER_payto_hash (receiver_account, +                    &h_payto); +  /* FIXME: inselect re-computes h_payto... */    qs = inselect_account_kyc_status (pg,                                      receiver_account,                                      &kyc); @@ -7813,7 +7813,7 @@ postgres_insert_reserve_closed (        GNUNET_PQ_query_param_auto_from_type (reserve_pub),        GNUNET_PQ_query_param_timestamp (&execution_date),        GNUNET_PQ_query_param_auto_from_type (wtid), -      GNUNET_PQ_query_param_uint64 (&kyc.payment_target_uuid), +      GNUNET_PQ_query_param_auto_from_type (&h_payto),        TALER_PQ_query_param_amount (amount_with_fee),        TALER_PQ_query_param_amount (closing_fee),        GNUNET_PQ_query_param_end @@ -8094,7 +8094,7 @@ postgres_start_deferred_wire_out (void *cls)   * @param cls closure   * @param date time of the wire transfer   * @param wtid subject of the wire transfer - * @param wire_target identifies the receiver account of the wire transfer + * @param h_payto identifies the receiver account of the wire transfer   * @param exchange_account_section configuration section of the exchange specifying the   *        exchange's bank account being used   * @param amount amount that was transmitted @@ -8105,7 +8105,7 @@ postgres_store_wire_transfer_out (    void *cls,    struct GNUNET_TIME_Timestamp date,    const struct TALER_WireTransferIdentifierRawP *wtid, -  uint64_t wire_target, +  const struct TALER_PaytoHashP *h_payto,    const char *exchange_account_section,    const struct TALER_Amount *amount)  { @@ -8113,7 +8113,7 @@ postgres_store_wire_transfer_out (    struct GNUNET_PQ_QueryParam params[] = {      GNUNET_PQ_query_param_timestamp (&date),      GNUNET_PQ_query_param_auto_from_type (wtid), -    GNUNET_PQ_query_param_uint64 (&wire_target), +    GNUNET_PQ_query_param_auto_from_type (h_payto),      GNUNET_PQ_query_param_string (exchange_account_section),      TALER_PQ_query_param_amount (amount),      GNUNET_PQ_query_param_end @@ -11774,9 +11774,9 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)    plugin->iterate_active_auditors = &postgres_iterate_active_auditors;    plugin->iterate_auditor_denominations =      &postgres_iterate_auditor_denominations; +  plugin->select_kyc_status = &postgres_select_kyc_status;    plugin->reserves_get = &postgres_reserves_get;    plugin->set_kyc_ok = &postgres_set_kyc_ok; -  plugin->select_kyc_status = &postgres_select_kyc_status;    plugin->inselect_wallet_kyc_status = &postgres_inselect_wallet_kyc_status;    plugin->reserves_in_insert = &postgres_reserves_in_insert;    plugin->get_withdraw_info = &postgres_get_withdraw_info; diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 7ca1839f..10390b7f 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -616,6 +616,10 @@ static uint64_t deposit_rowid;   */  static uint64_t wire_target_row; +/** + * Here #deposit_cb() will store the hash of the payto URI. + */ +static struct TALER_PaytoHashP wire_target_h_payto;  /**   * Function called with details about deposits that @@ -662,6 +666,8 @@ deposit_cb (void *cls,    {      deposit_rowid = rowid;      wire_target_row = wire_target; +    TALER_payto_hash (payto_uri, +                      &wire_target_h_payto);      result = 9;    }    return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; @@ -1048,6 +1054,10 @@ audit_wire_cb (void *cls,  static enum GNUNET_GenericReturnValue  test_wire_out (const struct TALER_EXCHANGEDB_Deposit *deposit)  { +  struct TALER_PaytoHashP h_payto; + +  TALER_payto_hash (deposit->receiver_wire_account, +                    &h_payto);    auditor_row_cnt = 0;    memset (&wire_out_wtid,            42, @@ -1127,7 +1137,7 @@ test_wire_out (const struct TALER_EXCHANGEDB_Deposit *deposit)              plugin->store_wire_transfer_out (plugin->cls,                                               wire_out_date,                                               &wire_out_wtid, -                                             kyc.payment_target_uuid, +                                             &h_payto,                                               "my-config-section",                                               &wire_out_amount));    } @@ -2267,7 +2277,7 @@ run (void *cls)    FAILIF (8 == result);    FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=            plugin->iterate_matching_deposits (plugin->cls, -                                             wire_target_row, +                                             &wire_target_h_payto,                                               &deposit.merchant_pub,                                               &matching_deposit_cb,                                               &deposit, diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h index e114ef83..c23de357 100644 --- a/src/include/taler_crypto_lib.h +++ b/src/include/taler_crypto_lib.h @@ -546,7 +546,7 @@ struct TALER_PaytoHashP    /**     * Actual hash value.     */ -  struct GNUNET_HashCode hash; +  struct GNUNET_ShortHashCode hash;  }; diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h index 2a20bda7..88be1ee3 100644 --- a/src/include/taler_exchange_service.h +++ b/src/include/taler_exchange_service.h @@ -2090,12 +2090,12 @@ typedef void   * @return a handle for this request   */  struct TALER_EXCHANGE_LinkHandle * -TALER_EXCHANGE_link (struct TALER_EXCHANGE_Handle *exchange, -                     const struct TALER_CoinSpendPrivateKeyP *coin_priv, -                     const struct -                     TALER_AgeCommitmentProof *age_commitment_proof, -                     TALER_EXCHANGE_LinkCallback link_cb, -                     void *link_cb_cls); +TALER_EXCHANGE_link ( +  struct TALER_EXCHANGE_Handle *exchange, +  const struct TALER_CoinSpendPrivateKeyP *coin_priv, +  const struct TALER_AgeCommitmentProof *age_commitment_proof, +  TALER_EXCHANGE_LinkCallback link_cb, +  void *link_cb_cls);  /** @@ -2699,7 +2699,7 @@ struct TALER_EXCHANGE_KycProofHandle;   * Run interaction with exchange to provide proof of KYC status.   *   * @param eh exchange handle to use - * @param payment_target number identifying the target + * @param h_payto hash of payto URI identifying the target account   * @param code OAuth 2.0 code argument   * @param state OAuth 2.0 state argument   * @param cb function to call with the result @@ -2708,7 +2708,7 @@ struct TALER_EXCHANGE_KycProofHandle;   */  struct TALER_EXCHANGE_KycProofHandle *  TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *eh, -                          uint64_t payment_target, +                          const struct TALER_PaytoHashP *h_payto,                            const char *code,                            const char *state,                            TALER_EXCHANGE_KycProofCallback cb, diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 35bf673b..c8953b94 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -239,7 +239,7 @@ struct TALER_EXCHANGEDB_TableData      {        uint64_t wire_reference;        struct TALER_Amount credit; -      uint64_t sender_account; +      struct TALER_PaytoHashP sender_account_h_payto;        char *exchange_account_section;        struct GNUNET_TIME_Timestamp execution_date;        struct TALER_ReservePublicKeyP reserve_pub; @@ -250,7 +250,7 @@ struct TALER_EXCHANGEDB_TableData        struct TALER_ReservePublicKeyP reserve_pub;        struct GNUNET_TIME_Timestamp execution_date;        struct TALER_WireTransferIdentifierRawP wtid; -      uint64_t wire_target_serial_id; +      struct TALER_PaytoHashP sender_account_h_payto;        struct TALER_Amount amount;        struct TALER_Amount closing_fee;      } reserves_close; @@ -347,7 +347,7 @@ struct TALER_EXCHANGEDB_TableData        struct TALER_PrivateContractHashP h_contract_terms;        struct TALER_CoinSpendSignatureP coin_sig;        struct TALER_WireSaltP wire_salt; -      uint64_t wire_target_serial_id; +      struct TALER_PaytoHashP wire_target_h_payto;        bool tiny;        bool done;        bool extension_blocked; @@ -366,7 +366,7 @@ struct TALER_EXCHANGEDB_TableData      {        struct GNUNET_TIME_Timestamp execution_date;        struct TALER_WireTransferIdentifierRawP wtid_raw; -      uint64_t wire_target_serial_id; +      struct TALER_PaytoHashP wire_target_h_payto;        char *exchange_account_section;        struct TALER_Amount amount;      } wire_out; @@ -2479,13 +2479,13 @@ struct TALER_EXCHANGEDB_Plugin     * Set the KYC status to "OK" for a bank account.     *     * @param cls the @e cls of this struct with the plugin-specific state -   * @param payment_target_uuid which account has been checked +   * @param h_payto which account has been checked     * @param id ID data to persist     * @return transaction status     */    enum GNUNET_DB_QueryStatus    (*set_kyc_ok)(void *cls, -                uint64_t payment_target_uuid, +                const struct TALER_PaytoHashP *h_payto,                  const char *id); @@ -2493,15 +2493,13 @@ struct TALER_EXCHANGEDB_Plugin     * Get the @a kyc status and @a h_payto by UUID.     *     * @param cls the @e cls of this struct with the plugin-specific state -   * @param payment_target_uuid which account to get the KYC status for -   * @param[out] h_payto set to the hash of the account's payto URI (unsalted) +   * @param h_payto set to the hash of the account's payto URI (unsalted)     * @param[out] kyc set to the KYC status of the account     * @return transaction status     */    enum GNUNET_DB_QueryStatus    (*select_kyc_status)(void *cls, -                       uint64_t payment_target_uuid, -                       struct TALER_PaytoHashP *h_payto, +                       const struct TALER_PaytoHashP *h_payto,                         struct TALER_EXCHANGEDB_KycStatus *kyc); @@ -3044,7 +3042,7 @@ struct TALER_EXCHANGEDB_Plugin     * destination.  Those deposits must not already be "done".     *     * @param cls the @e cls of this struct with the plugin-specific state -   * @param h_wire destination of the wire transfer +   * @param h_payto destination of the wire transfer     * @param merchant_pub public key of the merchant     * @param deposit_cb function to call for each deposit     * @param deposit_cb_cls closure for @a deposit_cb @@ -3057,7 +3055,7 @@ struct TALER_EXCHANGEDB_Plugin    enum GNUNET_DB_QueryStatus    (*iterate_matching_deposits)(      void *cls, -    uint64_t wire_target, +    const struct TALER_PaytoHashP *h_payto,      const struct TALER_MerchantPublicKeyP *merchant_pub,      TALER_EXCHANGEDB_MatchingDepositIterator deposit_cb,      void *deposit_cb_cls, @@ -3399,7 +3397,7 @@ struct TALER_EXCHANGEDB_Plugin     *     * @param cls closure     * @param date time of the wire transfer -   * @param wtid subject of the wire transfer +   * @param h_payto identifies the receiver account of the wire transfer     * @param wire_account details about the receiver account of the wire transfer,     *        including 'url' in payto://-format     * @param amount amount that was transmitted @@ -3412,7 +3410,7 @@ struct TALER_EXCHANGEDB_Plugin      void *cls,      struct GNUNET_TIME_Timestamp date,      const struct TALER_WireTransferIdentifierRawP *wtid, -    uint64_t wire_target, +    const struct TALER_PaytoHashP *h_payto,      const char *exchange_account_section,      const struct TALER_Amount *amount); diff --git a/src/lib/exchange_api_kyc_proof.c b/src/lib/exchange_api_kyc_proof.c index f2ca24eb..d3debbdb 100644 --- a/src/lib/exchange_api_kyc_proof.c +++ b/src/lib/exchange_api_kyc_proof.c @@ -141,7 +141,7 @@ handle_kyc_proof_finished (void *cls,  struct TALER_EXCHANGE_KycProofHandle *  TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *exchange, -                          uint64_t payment_target, +                          const struct TALER_PaytoHashP *h_payto,                            const char *code,                            const char *state,                            TALER_EXCHANGE_KycProofCallback cb, @@ -158,11 +158,21 @@ TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *exchange,      return NULL;    }    /* TODO: any escaping of code/state needed??? */ -  GNUNET_asprintf (&arg_str, -                   "/kyc-proof/%llu?code=%s&state=%s", -                   (unsigned long long) payment_target, -                   code, -                   state); +  { +    char hstr[sizeof (struct TALER_PaytoHashP) * 2]; +    char *end; + +    end = GNUNET_STRINGS_data_to_string (h_payto, +                                         sizeof (*h_payto), +                                         hstr, +                                         sizeof (hstr)); +    *end = '\0'; +    GNUNET_asprintf (&arg_str, +                     "/kyc-proof/%s?code=%s&state=%s", +                     hstr, +                     code, +                     state); +  }    kph = GNUNET_new (struct TALER_EXCHANGE_KycProofHandle);    kph->exchange = exchange;    kph->cb = cb; diff --git a/src/lib/exchange_api_reserves_get.c b/src/lib/exchange_api_reserves_get.c index 7f919ef8..3bdfbd28 100644 --- a/src/lib/exchange_api_reserves_get.c +++ b/src/lib/exchange_api_reserves_get.c @@ -260,7 +260,7 @@ TALER_EXCHANGE_reserves_get (      end = GNUNET_STRINGS_data_to_string (        reserve_pub, -      sizeof (struct TALER_ReservePublicKeyP), +      sizeof (*reserve_pub),        pub_str,        sizeof (pub_str));      *end = '\0'; diff --git a/src/testing/testing_api_cmd_kyc_proof.c b/src/testing/testing_api_cmd_kyc_proof.c index fdd3affd..05c1e7cb 100644 --- a/src/testing/testing_api_cmd_kyc_proof.c +++ b/src/testing/testing_api_cmd_kyc_proof.c @@ -131,13 +131,14 @@ proof_kyc_run (void *cls,  {    struct KycProofGetState *kps = cls;    const struct TALER_TESTING_Command *res_cmd; -  const uint64_t *payment_target; +  const char **payto_uri; +  struct TALER_PaytoHashP h_payto;    (void) cmd;    kps->is = is; -  res_cmd = TALER_TESTING_interpreter_lookup_command (kps->is, -                                                      kps-> -                                                      payment_target_reference); +  res_cmd = TALER_TESTING_interpreter_lookup_command ( +    kps->is, +    kps->payment_target_reference);    if (NULL == res_cmd)    {      GNUNET_break (0); @@ -145,15 +146,17 @@ proof_kyc_run (void *cls,      return;    }    if (GNUNET_OK != -      TALER_TESTING_get_trait_payment_target_uuid (res_cmd, -                                                   &payment_target)) +      TALER_TESTING_get_trait_payto_uri (res_cmd, +                                         &payto_uri))    {      GNUNET_break (0);      TALER_TESTING_interpreter_fail (kps->is);      return;    } +  TALER_payto_hash (*payto_uri, +                    &h_payto);    kps->kph = TALER_EXCHANGE_kyc_proof (is->exchange, -                                       *payment_target, +                                       &h_payto,                                         kps->code,                                         kps->state,                                         &proof_kyc_cb, diff --git a/src/util/payto.c b/src/util/payto.c index bfc8eb1b..c596f8d3 100644 --- a/src/util/payto.c +++ b/src/util/payto.c @@ -228,9 +228,16 @@ void  TALER_payto_hash (const char *payto,                    struct TALER_PaytoHashP *h_payto)  { +  struct GNUNET_HashCode sha512; +    GNUNET_CRYPTO_hash (payto,                        strlen (payto) + 1, -                      &h_payto->hash); +                      &sha512); +  GNUNET_static_assert (sizeof (sha512) > sizeof (*h_payto)); +  /* truncate */ +  memcpy (h_payto, +          &sha512, +          sizeof (*h_payto));  } | 
