Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed Jul 15, 2024
1 parent 0919cc2 commit bc58adb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 54 deletions.
2 changes: 1 addition & 1 deletion deps/concordium-rust-sdk
3 changes: 2 additions & 1 deletion sponsoredTransactions/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions sponsoredTransactionsAuction/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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",
Expand Down
31 changes: 13 additions & 18 deletions trackAndTrace/sponsored-transaction-service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,25 +273,20 @@ pub async fn handle_transaction(
state.keys.address,
&param,
)
.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
Expand Down
34 changes: 2 additions & 32 deletions trackAndTrace/sponsored-transaction-service/src/types.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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),
Expand Down

0 comments on commit bc58adb

Please sign in to comment.