Skip to content

Commit

Permalink
forwarder interactor setup
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaicalinluca committed Dec 9, 2024
1 parent e856a90 commit 9602c10
Show file tree
Hide file tree
Showing 15 changed files with 3,457 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ members = [
"contracts/feature-tests/composability/execute-on-dest-esdt-issue-callback/child",
"contracts/feature-tests/composability/execute-on-dest-esdt-issue-callback/child/meta",
"contracts/feature-tests/composability/forwarder",
"contracts/feature-tests/composability/forwarder-interactor",
"contracts/feature-tests/composability/forwarder/meta",
"contracts/feature-tests/composability/forwarder-legacy",
"contracts/feature-tests/composability/forwarder-legacy/meta",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Pem files are used for interactions, but shouldn't be committed
*.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "forwarder-interact"
version = "0.0.0"
authors = ["you"]
edition = "2021"
publish = false

[[bin]]
name = "forwarder-interact"
path = "src/interactor_main.rs"

[lib]
path = "src/interact.rs"

[dependencies.forwarder]
path = "../forwarder"

[dependencies.multiversx-sc-snippets]
version = "0.54.5"
path = "../../../../framework/snippets"

[dependencies.multiversx-sc]
version = "0.54.5"
path = "../../../../framework/base"

[dependencies]
clap = { version = "4.4.7", features = ["derive"] }
serde = { version = "1.0", features = ["derive"] }
toml = "0.8.6"

[features]
chain-simulator-tests = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# chain_type = 'simulator'
# gateway_uri = 'http://localhost:8085'

chain_type = 'real'
gateway_uri = 'https://devnet-gateway.multiversx.com'

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#![allow(unused)]

use serde::Deserialize;
use std::io::Read;

/// Config file
const CONFIG_FILE: &str = "config.toml";

#[derive(Debug, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ChainType {
Real,
Simulator,
}

/// Contract Interact configuration
#[derive(Debug, Deserialize)]
pub struct Config {
pub gateway_uri: String,
pub chain_type: ChainType,
}

impl Config {
// Deserializes config from file
pub fn new() -> Self {
let mut file = std::fs::File::open(CONFIG_FILE).unwrap();
let mut content = String::new();
file.read_to_string(&mut content).unwrap();
toml::from_str(&content).unwrap()
}

pub fn chain_simulator_config() -> Self {
Config {
gateway_uri: "http://localhost:8085".to_owned(),
chain_type: ChainType::Simulator,
}
}

// Returns the gateway URI
pub fn gateway_uri(&self) -> &str {
&self.gateway_uri
}

// Returns if chain type is chain simulator
pub fn use_chain_simulator(&self) -> bool {
match self.chain_type {
ChainType::Real => false,
ChainType::Simulator => true,
}
}
}
Loading

0 comments on commit 9602c10

Please sign in to comment.