From be672340932dcfd912eff969559a9c750e7f8dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Thu, 31 Oct 2024 10:32:25 +0000 Subject: [PATCH] bugfix: credential-proxy obtain-async (#5067) * removed foreign key constraint on deposit table * fixed sql nullability * fixed swagger arguments for '/api/v1/ticketbook/shares/device/{device_id}/credential/{credential_id}' route * fixed missing swagger component definitions --- .../nym-credential-proxy-requests/Cargo.toml | 4 ++-- .../src/api/v1/ticketbook/models.rs | 2 ++ .../nym-credential-proxy/Cargo.toml | 2 +- .../03_blinded_shares_no_foreign_table.sql | 20 +++++++++++++++++++ .../http/router/api/v1/ticketbook/shares.rs | 2 +- .../src/storage/manager.rs | 6 +++++- 6 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 nym-credential-proxy/nym-credential-proxy/migrations/03_blinded_shares_no_foreign_table.sql diff --git a/nym-credential-proxy/nym-credential-proxy-requests/Cargo.toml b/nym-credential-proxy/nym-credential-proxy-requests/Cargo.toml index 5f1d6a49a02..462fa8a4c15 100644 --- a/nym-credential-proxy/nym-credential-proxy-requests/Cargo.toml +++ b/nym-credential-proxy/nym-credential-proxy-requests/Cargo.toml @@ -22,12 +22,12 @@ reqwest = { workspace = true, features = ["json"] } wasm-bindgen = { workspace = true, optional = true } ## openapi: -utoipa = { workspace = true, optional = true } +utoipa = { workspace = true, optional = true, features = ["uuid"] } nym-credentials = { path = "../../common/credentials" } nym-credentials-interface = { path = "../../common/credentials-interface" } nym-http-api-common = { path = "../../common/http-api-common", optional = true } -nym-http-api-client = { path = "../../common/http-api-client" } +nym-http-api-client = { path = "../../common/http-api-client" } nym-serde-helpers = { path = "../../common/serde-helpers", features = ["bs58"] } [target."cfg(target_arch = \"wasm32\")".dependencies.wasmtimer] diff --git a/nym-credential-proxy/nym-credential-proxy-requests/src/api/v1/ticketbook/models.rs b/nym-credential-proxy/nym-credential-proxy-requests/src/api/v1/ticketbook/models.rs index 6ce58e81afc..46a65060ad0 100644 --- a/nym-credential-proxy/nym-credential-proxy-requests/src/api/v1/ticketbook/models.rs +++ b/nym-credential-proxy/nym-credential-proxy-requests/src/api/v1/ticketbook/models.rs @@ -40,6 +40,7 @@ pub struct TicketbookRequest { /// you **MUST** provide a valid value otherwise blacklisting won't work #[schemars(with = "String")] #[serde(with = "bs58_ecash")] + #[cfg_attr(feature = "openapi", schema(value_type = String))] pub ecash_pubkey: PublicKeyUser, // needs to be explicit in case user creates request at 23:59:59.999, but it reaches vpn-api at 00:00:00.001 @@ -48,6 +49,7 @@ pub struct TicketbookRequest { pub expiration_date: Date, #[schemars(with = "String")] + #[cfg_attr(feature = "openapi", schema(value_type = String))] pub ticketbook_type: TicketType, pub is_freepass_request: bool, diff --git a/nym-credential-proxy/nym-credential-proxy/Cargo.toml b/nym-credential-proxy/nym-credential-proxy/Cargo.toml index eb852c891ee..f04586b452f 100644 --- a/nym-credential-proxy/nym-credential-proxy/Cargo.toml +++ b/nym-credential-proxy/nym-credential-proxy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nym-credential-proxy" -version = "0.1.1" +version = "0.1.2" authors.workspace = true repository.workspace = true homepage.workspace = true diff --git a/nym-credential-proxy/nym-credential-proxy/migrations/03_blinded_shares_no_foreign_table.sql b/nym-credential-proxy/nym-credential-proxy/migrations/03_blinded_shares_no_foreign_table.sql new file mode 100644 index 00000000000..b7bc48ee96e --- /dev/null +++ b/nym-credential-proxy/nym-credential-proxy/migrations/03_blinded_shares_no_foreign_table.sql @@ -0,0 +1,20 @@ +/* + * Copyright 2024 - Nym Technologies SA + * SPDX-License-Identifier: Apache-2.0 + */ + + +DROP TABLE blinded_shares; +CREATE TABLE blinded_shares +( + id INTEGER NOT NULL PRIMARY KEY, +-- removed reference to `ticketbook_deposit` as the deposit wouldn't actually have been made before the pending share is inserted + request_uuid TEXT NOT NULL, + status TEXT NOT NULL, + device_id TEXT NOT NULL, + credential_id TEXT NOT NULL, + available_shares INTEGER NOT NULL DEFAULT 0, + error_message TEXT DEFAULT NULL, + created TIMESTAMP WITHOUT TIME ZONE NOT NULL, + updated TIMESTAMP WITHOUT TIME ZONE NOT NULL +); \ No newline at end of file diff --git a/nym-credential-proxy/nym-credential-proxy/src/http/router/api/v1/ticketbook/shares.rs b/nym-credential-proxy/nym-credential-proxy/src/http/router/api/v1/ticketbook/shares.rs index 174a4196946..a42ac2c8704 100644 --- a/nym-credential-proxy/nym-credential-proxy/src/http/router/api/v1/ticketbook/shares.rs +++ b/nym-credential-proxy/nym-credential-proxy/src/http/router/api/v1/ticketbook/shares.rs @@ -149,7 +149,7 @@ pub(crate) async fn query_for_shares_by_id( (status = 401, description = "authentication token is missing or is invalid"), (status = 500, body = ErrorResponse, description = "failed to query for bandwidth blinded shares"), ), - params(OutputParams), + params(SharesQueryParams), security( ("auth_token" = []) ) diff --git a/nym-credential-proxy/nym-credential-proxy/src/storage/manager.rs b/nym-credential-proxy/nym-credential-proxy/src/storage/manager.rs index c1dd782e00a..68990e5ba5a 100644 --- a/nym-credential-proxy/nym-credential-proxy/src/storage/manager.rs +++ b/nym-credential-proxy/nym-credential-proxy/src/storage/manager.rs @@ -82,7 +82,11 @@ impl SqliteStorageManager { sqlx::query_as!( MinimalWalletShare, r#" - SELECT t1.node_id, t1.blinded_signature, t1.epoch_id, t1.expiration_date + SELECT + t1.node_id as "node_id!", + t1.blinded_signature as "blinded_signature!", + t1.epoch_id as "epoch_id!", + t1.expiration_date as "expiration_date!" FROM partial_blinded_wallet as t1 JOIN ticketbook_deposit as t2 on t1.corresponding_deposit = t2.deposit_id