From 5965919a1750fb85511ef5cfd8d082154bc4ac71 Mon Sep 17 00:00:00 2001 From: Doris Benda Date: Thu, 11 Jan 2024 11:24:08 +0100 Subject: [PATCH] Address comments --- sponsoredTransactionsAuction/Dockerfile | 2 +- .../backend/Cargo.lock | 2 +- .../backend/Cargo.toml | 3 +- .../backend/README.md | 4 +-- .../backend/src/main.rs | 26 ++++------------- .../backend/src/types.rs | 2 +- .../frontend/.eslintrc.cjs | 1 - .../frontend/src/constants.ts | 4 +-- .../frontend/src/scss/_bootstrap-config.scss | 29 ------------------- 9 files changed, 13 insertions(+), 60 deletions(-) diff --git a/sponsoredTransactionsAuction/Dockerfile b/sponsoredTransactionsAuction/Dockerfile index 719fae37..a2e00c61 100644 --- a/sponsoredTransactionsAuction/Dockerfile +++ b/sponsoredTransactionsAuction/Dockerfile @@ -1,5 +1,5 @@ ARG node_base_image=node:18-slim -ARG rust_base_image=rust:1.67 +ARG rust_base_image=rust:1.70 FROM ${node_base_image} AS front_end diff --git a/sponsoredTransactionsAuction/backend/Cargo.lock b/sponsoredTransactionsAuction/backend/Cargo.lock index 1f7b4068..8a61cf0e 100644 --- a/sponsoredTransactionsAuction/backend/Cargo.lock +++ b/sponsoredTransactionsAuction/backend/Cargo.lock @@ -227,6 +227,7 @@ checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", "axum-core", + "axum-macros", "bitflags 1.3.2", "bytes", "futures-util", @@ -2397,7 +2398,6 @@ version = "1.0.0" dependencies = [ "anyhow", "axum", - "axum-macros", "clap", "concordium-rust-sdk", "futures", diff --git a/sponsoredTransactionsAuction/backend/Cargo.toml b/sponsoredTransactionsAuction/backend/Cargo.toml index c6f5b62a..45ba719c 100644 --- a/sponsoredTransactionsAuction/backend/Cargo.toml +++ b/sponsoredTransactionsAuction/backend/Cargo.toml @@ -9,7 +9,7 @@ license-file = "../../LICENSE" [dependencies] anyhow = "1.0" -axum = "0.6" +axum = { version = "0.6", features = ["macros"] } clap = { version = "4.3", features = ["derive", "env"] } serde_json = "1.0" tokio = { version = "1.29", features = ["rt-multi-thread", "signal"] } @@ -17,7 +17,6 @@ tracing = "0.1" tracing-subscriber = "0.3" serde = { version = "1.0", features = ["derive"] } futures = "0.3" -axum-macros = "0.3" tower-http = { version = "0.4", features = [ "trace", "limit", diff --git a/sponsoredTransactionsAuction/backend/README.md b/sponsoredTransactionsAuction/backend/README.md index 34f6c193..1a9932ce 100644 --- a/sponsoredTransactionsAuction/backend/README.md +++ b/sponsoredTransactionsAuction/backend/README.md @@ -9,7 +9,7 @@ The following parameters are supported - `port` the port on which the server will listen for incoming requests, e.g., 127.0.0.1:8080. - `log-level` maximum log level (defaults to `info` if not given). - `frontend` the path to the folder, which should be served, defaults to the `../frontent/dist` folder. -- `account-key-file` the path to a file which contains the key credentials. +- `account-key-file` the path to a file which contains the key credentials for the sponsorer account. - `cis2-token-smart-contract-index` the smart contract index which the sponsored transaction is submitted to. - `auction-smart-contract-index` the smart contract index of the auction smart contract. - `request-timeout` the request timeout (both of request to the node and server requests) in milliseconds. The node timeout is 500 ms less than the request-timeout to make sure we can fail properly in the server in case of connection timeout due to node connectivity problems. @@ -59,7 +59,7 @@ Changes to any of the packages must be such that - ```cargo clippy --all``` produces no warnings - ```rust fmt``` makes no changes. -Everything in this repository should build with rust version 1.65 however the `fmt` tool must be from a nightly release since some of the configuration options are not stable. One way to run the `fmt` tool is +Everything in this repository should build with rust version 1.70 however the `fmt` tool must be from a nightly release since some of the configuration options are not stable. One way to run the `fmt` tool is ``` cargo +nightly-2023-04-01 fmt ``` diff --git a/sponsoredTransactionsAuction/backend/src/main.rs b/sponsoredTransactionsAuction/backend/src/main.rs index da158030..cd28b6f1 100644 --- a/sponsoredTransactionsAuction/backend/src/main.rs +++ b/sponsoredTransactionsAuction/backend/src/main.rs @@ -153,10 +153,8 @@ async fn main() -> anyhow::Result<()> { .context("Unable to establish connection to the node.")?; // Load account keys and sender address from a file - let keys: WalletAccount = serde_json::from_str( - &std::fs::read_to_string(app.keys_path).context("Could not read the keys file.")?, - ) - .context("Could not parse the keys file.")?; + let keys: WalletAccount = + WalletAccount::from_json_file(app.keys_path).context("Could not read the keys file.")?; let sponsorer_key = Arc::new(keys); @@ -166,9 +164,9 @@ async fn main() -> anyhow::Result<()> { .context("NonceQueryError.")?; tracing::debug!( - "Starting server with sponsorer {:?}. Current sponsorer nonce: {:?}.", + "Starting server with sponsorer {}. Current sponsorer nonce: {}.", sponsorer_key.address, - nonce_response + nonce_response.nonce ); let state = Server { @@ -221,10 +219,6 @@ async fn handle_signature_bid( ) -> Result, ServerError> { let Json(request) = request?; - tracing::debug!("Request: {:?}", request); - - tracing::debug!("Create payload ..."); - let transfer = Transfer { from: Address::Account(request.from), to: Receiver::Contract( @@ -240,8 +234,6 @@ async fn handle_signature_bid( tracing::debug!("Created payload: {:?}", payload); - tracing::debug!("Create permitMessage ..."); - let message: PermitMessage = PermitMessage { contract_address: state.cis2_token_smart_contract, nonce: request.nonce, @@ -252,8 +244,6 @@ async fn handle_signature_bid( tracing::debug!("Created {:?}", message); - tracing::debug!("Create signature map ..."); - let mut signature = [0; 64]; if request.signature.len() != 128 { @@ -272,8 +262,6 @@ async fn handle_signature_bid( tracing::debug!("Created signature_map {:?}", signature_map); - tracing::debug!("Create parameter ..."); - let param: PermitParam = PermitParam { message, signature: AccountSignatures { @@ -287,8 +275,6 @@ async fn handle_signature_bid( tracing::debug!("Created {:?}", parameter); - tracing::debug!("Simulate transaction to check its validity ..."); - let payload = transactions::UpdateContractPayload { amount: Amount::from_micro_ccd(0), address: state.cis2_token_smart_contract, @@ -385,8 +371,6 @@ async fn handle_signature_bid( *limit += 1; - tracing::debug!("Create transaction ..."); - let tx = transactions::send::make_and_sign_transaction( &state.key.keys, state.key.address, @@ -401,7 +385,7 @@ async fn handle_signature_bid( concordium_rust_sdk::types::transactions::Payload::Update { payload }, ); - tracing::debug!("Submit transaction {:?} ...", tx.clone()); + tracing::debug!("Submit transaction {:?} ...", tx); let bi = transactions::BlockItem::AccountTransaction(tx); diff --git a/sponsoredTransactionsAuction/backend/src/types.rs b/sponsoredTransactionsAuction/backend/src/types.rs index b1b72f2a..f00c07bc 100644 --- a/sponsoredTransactionsAuction/backend/src/types.rs +++ b/sponsoredTransactionsAuction/backend/src/types.rs @@ -78,7 +78,7 @@ pub struct RevertReason { pub reason: RejectReason, } -/// Paramters passed from the front end to this back end when calling the API +/// Parameters passed from the front end to this back end when calling the API /// endpoint `/bid`. #[derive(serde::Deserialize, serde::Serialize, Debug, Clone)] pub struct BidParams { diff --git a/sponsoredTransactionsAuction/frontend/.eslintrc.cjs b/sponsoredTransactionsAuction/frontend/.eslintrc.cjs index e55316ee..4bddf35b 100644 --- a/sponsoredTransactionsAuction/frontend/.eslintrc.cjs +++ b/sponsoredTransactionsAuction/frontend/.eslintrc.cjs @@ -9,7 +9,6 @@ module.exports = { 'plugin:react/recommended', 'plugin:react/jsx-runtime', 'plugin:jsx-a11y/recommended', - 'eslint-config-prettier', 'prettier', ], parser: '@typescript-eslint/parser', diff --git a/sponsoredTransactionsAuction/frontend/src/constants.ts b/sponsoredTransactionsAuction/frontend/src/constants.ts index b9922fdf..28f02da1 100644 --- a/sponsoredTransactionsAuction/frontend/src/constants.ts +++ b/sponsoredTransactionsAuction/frontend/src/constants.ts @@ -9,7 +9,7 @@ export const NODE = 'http://node.testnet.concordium.com'; export const PORT = 20000; -export const REFRESH_INTERVAL = moment.duration(5, 'seconds'); +export const REFRESH_INTERVAL = moment.duration(2, 'seconds'); export const SPONSORED_TX_CONTRACT_NAME = ContractName.fromString('cis2_multi'); export const AUCTION_CONTRACT_NAME = ContractName.fromString('sponsored_tx_enabled_auction'); @@ -21,7 +21,7 @@ export const CONTRACT_SUB_INDEX = 0n; // allow an additional small amount of energy `EPSILON_ENERGY` to be consumed by // the transaction to cover small variations (e.g. changes to the smart contract // state) caused by transactions that have been executed meanwhile. -export const EPSILON_ENERGY = 1000n; +export const EPSILON_ENERGY = 200n; export const AUCTION_START = '2000-01-01T12:00:00Z'; // Hardcoded value for simplicity for this demo dApp. export const AUCTION_END = '2050-01-01T12:00:00Z'; // Hardcoded value for simplicity for this demo dApp. diff --git a/sponsoredTransactionsAuction/frontend/src/scss/_bootstrap-config.scss b/sponsoredTransactionsAuction/frontend/src/scss/_bootstrap-config.scss index 9ee2d182..02b1cb4f 100644 --- a/sponsoredTransactionsAuction/frontend/src/scss/_bootstrap-config.scss +++ b/sponsoredTransactionsAuction/frontend/src/scss/_bootstrap-config.scss @@ -4,39 +4,10 @@ @import 'bootstrap/scss/maps'; @import 'bootstrap/scss/mixins'; @import 'bootstrap/scss/utilities'; - -// Bootstrap layout & components - toggle components as needed -// @import 'bootstrap/scss/root'; -// @import 'bootstrap/scss/reboot'; @import 'bootstrap/scss/type'; -// @import 'bootstrap/scss/images'; -// @import 'bootstrap/scss/containers'; -// @import 'bootstrap/scss/grid'; -// @import 'bootstrap/scss/tables'; @import 'bootstrap/scss/forms'; @import 'bootstrap/scss/buttons'; -// @import 'bootstrap/scss/transitions'; -// @import 'bootstrap/scss/dropdown'; -// @import 'bootstrap/scss/button-group'; -// @import 'bootstrap/scss/nav'; -// @import 'bootstrap/scss/navbar'; -// @import 'bootstrap/scss/card'; -// @import 'bootstrap/scss/accordion'; -// @import 'bootstrap/scss/breadcrumb'; -// @import 'bootstrap/scss/pagination'; -// @import 'bootstrap/scss/badge'; @import 'bootstrap/scss/alert'; -// @import 'bootstrap/scss/progress'; -// @import 'bootstrap/scss/list-group'; -// @import 'bootstrap/scss/close'; -// @import 'bootstrap/scss/toasts'; -// @import 'bootstrap/scss/modal'; -// @import 'bootstrap/scss/tooltip'; -// @import 'bootstrap/scss/popover'; -// @import 'bootstrap/scss/carousel'; -// @import 'bootstrap/scss/spinners'; -// @import 'bootstrap/scss/offcanvas'; -// @import 'bootstrap/scss/placeholders'; // Bootstrap helpers @import 'bootstrap/scss/helpers';