Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sovereign Forge Interactor #204

Merged
merged 21 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ permissions:
jobs:
contracts:
name: Contracts
uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v3.3.1
uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@79d7ac76e34b3208fbe07559ac276d0ea48be4da
with:
rust-toolchain: stable
coverage-args: --ignore-filename-regex='/.cargo/git' --output ./coverage.md
Expand Down
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ members = [
"testing-sc",
"testing-sc/meta",
"sovereign-forge",
"sovereign-forge/interactor",
"sovereign-forge/meta",
]
5 changes: 5 additions & 0 deletions sovereign-forge/interactor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Pem files are used for interactions, but shouldn't be committed
*.pem

# State files are used for interactions, but shouldn't be committed
state.toml
34 changes: 34 additions & 0 deletions sovereign-forge/interactor/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "forge-rust-interact"
version = "0.0.0"
authors = ["you"]
edition = "2021"
publish = false

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

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

[dependencies.sovereign-forge]
path = ".."

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

[dependencies.multiversx-sc]
version = "0.54.5"

[dependencies.proxies]
path = "../../common/proxies"

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

[features]
chain-simulator-tests = []

7 changes: 7 additions & 0 deletions sovereign-forge/interactor/config.toml
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'

51 changes: 51 additions & 0 deletions sovereign-forge/interactor/src/config.rs
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
Loading