From bc58adbd1dfa47a2913b1cb5841af0cf756e793a Mon Sep 17 00:00:00 2001 From: Doris Benda Date: Fri, 12 Jul 2024 14:17:29 +0200 Subject: [PATCH] Address comments --- deps/concordium-rust-sdk | 2 +- sponsoredTransactions/backend/src/main.rs | 3 +- .../backend/src/main.rs | 4 +-- .../sponsored-transaction-service/src/main.rs | 31 +++++++---------- .../src/types.rs | 34 ++----------------- 5 files changed, 20 insertions(+), 54 deletions(-) diff --git a/deps/concordium-rust-sdk b/deps/concordium-rust-sdk index 82b76449..7f0566a0 160000 --- a/deps/concordium-rust-sdk +++ b/deps/concordium-rust-sdk @@ -1 +1 @@ -Subproject commit 82b76449ba7627a69d86cb39e448cd21447d25b8 +Subproject commit 7f0566a0defa63e37d9e0db0eb896acd3ddd2cc1 diff --git a/sponsoredTransactions/backend/src/main.rs b/sponsoredTransactions/backend/src/main.rs index 2874ec39..13f7f55c 100644 --- a/sponsoredTransactions/backend/src/main.rs +++ b/sponsoredTransactions/backend/src/main.rs @@ -7,6 +7,7 @@ use clap::Parser; use concordium_rust_sdk::{ common::{self as crypto_common}, types::WalletAccount, + v2::Endpoint, v2::Scheme, }; use std::collections::HashMap; @@ -26,7 +27,7 @@ struct IdVerifierConfig { help = "GRPC V2 interface of the node.", default_value = "http://localhost:20000" )] - endpoint: tonic::transport::Endpoint, + endpoint: Endpoint, #[clap( long = "port", default_value = "8100", diff --git a/sponsoredTransactionsAuction/backend/src/main.rs b/sponsoredTransactionsAuction/backend/src/main.rs index 72d44a0b..f03d326e 100644 --- a/sponsoredTransactionsAuction/backend/src/main.rs +++ b/sponsoredTransactionsAuction/backend/src/main.rs @@ -21,7 +21,7 @@ use concordium_rust_sdk::{ smart_contracts::{ContractContext, InvokeContractResult, OwnedReceiveName}, transactions, Energy, WalletAccount, }, - v2::{self, BlockIdentifier}, + v2::{self, BlockIdentifier, Endpoint}, }; use std::{ collections::{BTreeMap, HashMap}, @@ -51,7 +51,7 @@ struct App { default_value = "http://localhost:20000", env = "NODE" )] - endpoint: tonic::transport::Endpoint, + endpoint: Endpoint, #[clap( long = "log-level", default_value = "info", diff --git a/trackAndTrace/sponsored-transaction-service/src/main.rs b/trackAndTrace/sponsored-transaction-service/src/main.rs index edc15093..b29e9826 100644 --- a/trackAndTrace/sponsored-transaction-service/src/main.rs +++ b/trackAndTrace/sponsored-transaction-service/src/main.rs @@ -273,25 +273,20 @@ pub async fn handle_transaction( state.keys.address, ¶m, ) - .await + .await? { - Ok(invoke_contract_result) => match invoke_contract_result { - InvokeContractOutcome::Success(dry_run) => Ok(dry_run), - InvokeContractOutcome::Failure(rejected_transaction) => { - match rejected_transaction.decoded_reason { - Some(decoded_reason) => { - Err(ServerError::TransactionSimulationRejectedTransaction( - ErrorSchema(decoded_reason), - rejected_transaction.reason, - )) - } - None => Err(ServerError::TransactionSimulationError( - rejected_transaction.reason, - )), - } - }?, - }, - Err(e) => Err(e), + InvokeContractOutcome::Success(dry_run) => Ok(dry_run), + InvokeContractOutcome::Failure(rejected_transaction) => { + match rejected_transaction.decoded_reason { + Some(decoded_reason) => Err(ServerError::TransactionSimulationRejectedTransaction( + decoded_reason, + rejected_transaction.reason, + )), + None => Err(ServerError::TransactionSimulationError( + rejected_transaction.reason, + )), + } + } }?; // Get the current nonce for the backend wallet and lock it. This is necessary diff --git a/trackAndTrace/sponsored-transaction-service/src/types.rs b/trackAndTrace/sponsored-transaction-service/src/types.rs index 8de55ce9..108314fb 100644 --- a/trackAndTrace/sponsored-transaction-service/src/types.rs +++ b/trackAndTrace/sponsored-transaction-service/src/types.rs @@ -1,6 +1,7 @@ use axum::{extract::rejection::JsonRejection, http::StatusCode, Json}; use chrono::{prelude::*, TimeDelta}; use concordium_rust_sdk::{ + contract_client::DecodedReason, endpoints::QueryError, smart_contracts::common::{ self as concordium_std, AccountAddress, AccountSignatures, ContractAddress, @@ -10,7 +11,6 @@ use concordium_rust_sdk::{ types::{smart_contracts::ExceedsParameterSize, Nonce, RejectReason, WalletAccount}, }; use hex::FromHexError; -use serde_json::Value; use std::{ collections::{BTreeSet, HashMap}, fmt, @@ -19,36 +19,6 @@ use std::{ }; use tokio::sync::Mutex; -/// Define a newtype wrapper around the error schema type. -#[derive(Debug)] -pub struct ErrorSchema(pub Value); - -/// Write a custom display implementation for the error schema type. -/// This displays nested errors meaningfully. -impl std::fmt::Display for ErrorSchema { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match &self.0 { - Value::Object(map) => { - if let Some(key) = map.keys().next() { - write!(f, "{}", key)?; - if let Some(value) = map.values().next() { - if value.is_array() { - write!(f, "{}", ErrorSchema(value.clone()))?; - } - } - } - } - Value::Array(arr) => { - if let Some(value) = arr.iter().next() { - write!(f, "::{}", ErrorSchema(value.clone()))?; - } - } - _ => write!(f, "{}", self.0)?, - } - Ok(()) - } -} - #[derive(Debug, thiserror::Error)] /// Errors that can occur in the server. pub enum ServerError { @@ -73,7 +43,7 @@ pub enum ServerError { "Simulation of transaction rejected in smart contract with decoded reject reason: `{0}` \ derived from: {1:?}." )] - TransactionSimulationRejectedTransaction(ErrorSchema, RejectReason), + TransactionSimulationRejectedTransaction(DecodedReason, RejectReason), /// The contract client could not be created because of a network error. #[error("Failed to create contract client: {0:?}")] FailedToCreateContractClient(QueryError),