generated from multiversx/mx-template-sc
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #198 from multiversx/interactor-refactoring
Interactor file structure refactor
- Loading branch information
Showing
21 changed files
with
548 additions
and
1,203 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "interactor" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
path = "src/lib.rs" | ||
|
||
[dependencies] | ||
toml = "0.8.6" | ||
|
||
[dependencies.multiversx-sc] | ||
version = "=0.54.5" | ||
|
||
[dependencies.multiversx-sc-snippets] | ||
version = "=0.54.5" | ||
|
||
[dependencies.serde] | ||
version = "1.0" | ||
features = ["derive"] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pub const TOKEN_ID: &[u8] = b"SVT-805b28"; | ||
pub const WHITELIST_TOKEN_ID: &[u8] = b"CHOCOLATE-daf625"; | ||
pub const TOKEN_ID_FOR_EXECUTE: &[u8] = b"x-SOV-101252"; | ||
pub const WHITELISTED_TOKEN_ID: &[u8] = b"CHOCOLATE-daf625"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
use multiversx_sc_snippets::imports::*; | ||
use serde::{Deserialize, Serialize}; | ||
use std::{ | ||
io::{Read, Write}, | ||
path::Path, | ||
}; | ||
|
||
const STATE_FILE: &str = "state.toml"; | ||
|
||
#[derive(Debug, Default, Serialize, Deserialize)] | ||
pub struct State { | ||
esdt_safe_address: Option<Bech32Address>, | ||
header_verifier_address: Option<Bech32Address>, | ||
fee_market_address: Option<Bech32Address>, | ||
token_handler_address: Option<Bech32Address>, | ||
testing_sc_address: Option<Bech32Address>, | ||
} | ||
|
||
impl State { | ||
// Deserializes state from file | ||
pub fn load_state() -> Self { | ||
if Path::new(STATE_FILE).exists() { | ||
let mut file = std::fs::File::open(STATE_FILE).unwrap(); | ||
let mut content = String::new(); | ||
file.read_to_string(&mut content).unwrap(); | ||
toml::from_str(&content).unwrap() | ||
} else { | ||
Self::default() | ||
} | ||
} | ||
|
||
/// Sets the contract address | ||
pub fn set_esdt_safe_address(&mut self, address: Bech32Address) { | ||
self.esdt_safe_address = Some(address); | ||
} | ||
|
||
pub fn set_header_verifier_address(&mut self, address: Bech32Address) { | ||
self.header_verifier_address = Some(address); | ||
} | ||
|
||
pub fn set_fee_market_address(&mut self, address: Bech32Address) { | ||
self.fee_market_address = Some(address); | ||
} | ||
|
||
pub fn set_token_handler_address(&mut self, address: Bech32Address) { | ||
self.token_handler_address = Some(address); | ||
} | ||
|
||
pub fn set_testing_sc_address(&mut self, address: Bech32Address) { | ||
self.testing_sc_address = Some(address); | ||
} | ||
|
||
/// Returns the contract address | ||
pub fn esdt_safe_address(&self) -> &Bech32Address { | ||
self.esdt_safe_address | ||
.as_ref() | ||
.expect("no known esdt_safe contract, deploy first") | ||
} | ||
|
||
pub fn get_header_verifier_address(&self) -> &Bech32Address { | ||
self.header_verifier_address | ||
.as_ref() | ||
.expect("no known header verifier, deploy first") | ||
} | ||
|
||
pub fn get_fee_market_address(&self) -> &Bech32Address { | ||
self.fee_market_address | ||
.as_ref() | ||
.expect("no known fee market, deploy first") | ||
} | ||
|
||
pub fn get_token_handler_address(&self) -> &Bech32Address { | ||
self.token_handler_address | ||
.as_ref() | ||
.expect("no known token handler, deploy first") | ||
} | ||
|
||
pub fn get_testing_sc_address(&self) -> Address { | ||
self.testing_sc_address.clone().unwrap().to_address() | ||
} | ||
} | ||
|
||
impl Drop for State { | ||
// Serializes state to file | ||
fn drop(&mut self) { | ||
let mut file = std::fs::File::create(STATE_FILE).unwrap(); | ||
file.write_all(toml::to_string(self).unwrap().as_bytes()) | ||
.unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod interactor_config; | ||
pub mod interactor_state; | ||
pub mod constants; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.