Skip to content

Commit

Permalink
Merge pull request #1778 from multiversx/sdk-gateway-split
Browse files Browse the repository at this point in the history
sdk - separated gateway in new crate
  • Loading branch information
andrei-marinica authored Sep 26, 2024
2 parents 390d18d + ac12c0c commit f735e6a
Show file tree
Hide file tree
Showing 48 changed files with 212 additions and 196 deletions.
218 changes: 86 additions & 132 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"framework/wasm-adapter",

"sdk/core",
"sdk/reqwest",
"sdk/scenario-format",

"tools/mxpy-snippet-generator",
Expand Down
4 changes: 2 additions & 2 deletions framework/snippets/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ path = "../scenario"
version = "0.23.0"
path = "../../sdk/scenario-format"

[dependencies.multiversx-sdk]
[dependencies.multiversx-sdk-reqwest]
version = "=0.6.0"
path = "../../sdk/core"
path = "../../sdk/reqwest"

[dev-dependencies]
serde_json = "1.0"
8 changes: 3 additions & 5 deletions framework/snippets/src/account_tool.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::sdk_core::data::{address::Address, esdt::EsdtBalance};
use multiversx_chain_scenario_format::interpret_trait::IntoRaw;
use multiversx_sc_scenario::{
imports::Bech32Address,
scenario_model::{Account, BytesKey, BytesValue, Scenario, SetStateStep, Step},
};
use multiversx_sdk::{
data::{address::Address, esdt::EsdtBalance},
gateway::GatewayProxy,
};
use multiversx_sdk_reqwest::gateway::GatewayProxy;
use std::collections::{BTreeMap, HashMap};

/// Called directly from CLI, from `sc-meta`.
Expand Down Expand Up @@ -67,7 +65,7 @@ pub async fn retrieve_account_as_scenario_set_state(
}

fn set_account(
account: multiversx_sdk::data::account::Account,
account: crate::sdk::data::account::Account,
account_storage: HashMap<String, String>,
account_esdt: HashMap<String, EsdtBalance>,
account_esdt_roles: HashMap<String, Vec<String>>,
Expand Down
2 changes: 1 addition & 1 deletion framework/snippets/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub use crate::{
dns_address_for_name, test_wallets, Interactor, InteractorPrepareAsync, StepBuffer,
};

pub use multiversx_sdk::{data::keystore::InsertPassword, wallet::Wallet};
pub use crate::sdk::{data::keystore::InsertPassword, wallet::Wallet};

pub use env_logger;
pub use tokio;
10 changes: 5 additions & 5 deletions framework/snippets/src/interactor.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::sdk::{
data::{address::Address as ErdrsAddress, network_config::NetworkConfig},
wallet::Wallet,
};
use multiversx_sc_scenario::{
imports::{Bech32Address, ScenarioRunner},
mandos_system::{run_list::ScenarioRunnerList, run_trace::ScenarioTraceFile},
multiversx_sc::types::Address,
scenario_model::AddressValue,
};
use multiversx_sdk::{
data::{address::Address as ErdrsAddress, network_config::NetworkConfig},
gateway::GatewayProxy,
wallet::Wallet,
};
use multiversx_sdk_reqwest::gateway::GatewayProxy;
use std::{
collections::HashMap,
path::{Path, PathBuf},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use multiversx_sc_scenario::{
scenario::ScenarioRunner,
scenario_model::{ScCallStep, SetStateStep, TxCall},
};
use multiversx_sdk::{data::transaction::Transaction, utils::base64_encode};
use crate::sdk::{data::transaction::Transaction, utils::base64_encode};

impl Interactor {
pub async fn sc_call<S>(&mut self, mut sc_call_step: S)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use multiversx_sc_scenario::{
mandos_system::ScenarioRunner,
scenario_model::{ScDeployStep, SetStateStep},
};
use multiversx_sdk::{
use crate::sdk::{
data::{address::Address as ErdrsAddress, transaction::Transaction},
utils::base64_encode,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use multiversx_sc_scenario::{
multiversx_sc::{abi::TypeAbiFrom, codec::TopDecodeMulti, types::ContractCall},
scenario_model::{ScQueryStep, TxResponse},
};
use multiversx_sdk::{data::vm::VmValueRequest, utils::base64_decode};
use crate::sdk::{data::vm::VmValueRequest, utils::base64_decode};

impl Interactor {
pub async fn sc_query<S>(&mut self, mut step: S) -> &mut Self
Expand Down
2 changes: 1 addition & 1 deletion framework/snippets/src/interactor_sender.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use log::debug;
use multiversx_sc_scenario::multiversx_sc::types::Address;
use multiversx_sdk::{data::transaction::Transaction, wallet::Wallet};
use crate::sdk::{data::transaction::Transaction, wallet::Wallet};

use crate::{address_h256_to_erdrs, Interactor};

Expand Down
4 changes: 2 additions & 2 deletions framework/snippets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub use interactor_tx::*;
pub use log;
pub use multi::*;
pub use multiversx_sc_scenario::{self, multiversx_sc};
pub use multiversx_sdk as erdrs; // TODO: remove
pub use multiversx_sdk as sdk;
pub use multiversx_sdk_reqwest::core as sdk_core;
pub use multiversx_sdk_reqwest::core as sdk;
pub use tokio;

/// Imports normally needed in interactors, grouped together.
Expand Down
2 changes: 1 addition & 1 deletion framework/snippets/src/multi/interactor_multi_sc_exec.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::interactor_multi_sc_process::{update_nonces_and_sign_tx, SenderSet, Txs};
use crate::sdk::data::transaction::Transaction;
use crate::{network_response, Interactor, InteractorStep, StepBuffer};
use multiversx_sdk::data::transaction::Transaction;

impl Interactor {
pub async fn multi_sc_exec(&mut self, mut buffer: StepBuffer<'_>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{multiversx_sc::types::Address, Interactor, Sender};
use futures::future::join_all;
use multiversx_sdk::data::transaction::{Transaction, TransactionOnNetwork};
use crate::sdk::data::transaction::{Transaction, TransactionOnNetwork};
use std::collections::HashSet;

pub(crate) type Txs = Vec<Transaction>;
Expand Down
2 changes: 1 addition & 1 deletion framework/snippets/src/multi/interactor_step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use multiversx_sc_scenario::{
mandos_system::ScenarioRunner,
scenario_model::{AddressValue, ScCallStep, ScDeployStep, TxResponse},
};
use multiversx_sdk::data::transaction::Transaction;
use crate::sdk::data::transaction::Transaction;

use crate::Interactor;

Expand Down
2 changes: 1 addition & 1 deletion framework/snippets/src/network_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use multiversx_sc_scenario::{
multiversx_chain_vm::crypto_functions::keccak256,
scenario_model::{Log, TxResponse, TxResponseStatus},
};
use multiversx_sdk::{
use crate::sdk::{
data::transaction::{ApiSmartContractResult, Events, TransactionOnNetwork},
utils::base64_decode,
};
Expand Down
2 changes: 1 addition & 1 deletion framework/snippets/src/test_wallets.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use multiversx_sdk::wallet::Wallet;
use crate::sdk::wallet::Wallet;

fn test_wallet(pem_file_contents: &str) -> Wallet {
Wallet::from_pem_file_contents(pem_file_contents.to_string()).unwrap()
Expand Down
4 changes: 2 additions & 2 deletions framework/snippets/tests/test_tx_deployed_address.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use multiversx_sc_scenario::imports::Address;
use multiversx_sc_snippets::network_response;
use multiversx_sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};
use multiversx_sc_snippets::sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};

#[test]
fn test_deployed_address() {
Expand Down Expand Up @@ -55,7 +55,7 @@ fn test_deployed_address() {
.transaction;
let tx_response = network_response::parse_tx_response(tx_on_network);
let opt_address = tx_response.new_deployed_address.map(|e| {
multiversx_sdk::data::address::Address::from_bytes(*e.as_array())
multiversx_sc_snippets::sdk::data::address::Address::from_bytes(*e.as_array())
.to_bech32_string()
.unwrap()
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use multiversx_sc_snippets::network_response;
use multiversx_sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};
use multiversx_sc_snippets::sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};

#[test]
fn test_process_issued_token_identifier_fungible() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use multiversx_sc_snippets::network_response;
use multiversx_sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};
use multiversx_sc_snippets::sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};

#[test]
fn test_with_multi_contract_same_shard_tx_that_has_no_sc_result() {
Expand Down
2 changes: 1 addition & 1 deletion framework/snippets/tests/test_tx_multiple_sc_results.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use multiversx_sc_snippets::network_response::{self, is_out_scr};
use multiversx_sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};
use multiversx_sc_snippets::sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};

#[test]
fn test_transaction_multiple_sc_results() {
Expand Down
2 changes: 1 addition & 1 deletion framework/snippets/tests/test_tx_sc_result.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use multiversx_sc_snippets::network_response;
use multiversx_sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};
use multiversx_sc_snippets::sdk::data::transaction::{TransactionInfo, TransactionOnNetwork};

#[test]
fn test_with_tx_that_has_sc_result() {
Expand Down
2 changes: 0 additions & 2 deletions sdk/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ categories = ["cryptography::cryptocurrencies", "api-bindings"]
keywords = ["multiversx", "blockchain", "sdk", "api"]

[dependencies]
tokio = { version = "1.24", features = ["full"] }
reqwest = { version = "0.12", features = ["blocking", "json"] }
serde = { version = "1.0.130", features = ["derive"] }
serde_json = { version = "1.0.68", features = ["preserve_order"] }
serde_repr = "0.1.8"
Expand Down
1 change: 0 additions & 1 deletion sdk/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod crypto;
pub mod data;
pub mod gateway;
pub mod utils;
pub mod wallet;
28 changes: 28 additions & 0 deletions sdk/reqwest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "multiversx-sdk-reqwest"
version = "0.6.0"
edition = "2021"

authors = [
"MultiversX <[email protected]>",
]
license = "MIT"
readme = "README.md"
repository = "https://github.com/multiversx/mx-sdk-rs"
homepage = "https://multiversx.com/"
documentation = "https://docs.multiversx.com/"
description = "SDK for interacting with the MultiversX blockchain"
categories = ["cryptography::cryptocurrencies", "api-bindings"]
keywords = ["multiversx", "blockchain", "sdk", "api"]

[dependencies]
tokio = { version = "1.24", features = ["full"] }
reqwest = { version = "0.12", features = ["blocking", "json"] }
anyhow = "1.0.44"
hex = "0.4.3"
itertools = "0.13.0"
log = "0.4.17"

[dependencies.multiversx-sdk]
version = "=0.6.0"
path = "../core"
25 changes: 25 additions & 0 deletions sdk/reqwest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# MultiversX SDK for Rust

[![Crates.io](https://img.shields.io/crates/v/multiversx-sdk)](https://crates.io/crates/multiversx-sdk)

General purpose collection of tools & SDKs to interact with the MultiversX blockchain from Rust projects.

## Example

```rust
use multiversx_sdk::blockchain::rpc::{CommunicationProxy, DEVNET_GATEWAY};

#[tokio::test]
async fn get_network_config() {
let blockchain = CommunicationProxy::new(DEVNET_GATEWAY.to_string());
let network_config = blockchain.get_network_config().await.unwrap();

println!("network_config: {:?}", network_config)
}
```

More examples in `./examples`.

## Acknowledgements

Project originally started by [Bicarus labs](https://github.com/bicarus-labs/elrond-sdk-erdrs), later integrated into the MultiversX official codebase.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use multiversx_sdk::{
data::address::Address,
use multiversx_sdk_reqwest::{
core::data::address::Address,
gateway::{GatewayProxy, DEVNET_GATEWAY},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use multiversx_sdk::{
data::address::Address,
use multiversx_sdk_reqwest::{
core::data::address::Address,
gateway::{GatewayProxy, DEVNET_GATEWAY},
};

Expand Down
9 changes: 9 additions & 0 deletions sdk/reqwest/examples/generate_mnemonic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use multiversx_sdk::wallet::Wallet;

fn main() {
let mnemonic = Wallet::generate_mnemonic();
println!("mnemonic: {mnemonic}");

let private_key = Wallet::get_private_key_from_mnemonic(mnemonic, 0, 0);
println!("private key: {:?}", private_key.to_string());
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use multiversx_sdk::{
data::address::Address,
use multiversx_sdk_reqwest::{
core::data::address::Address,
gateway::{GatewayProxy, DEVNET_GATEWAY},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use multiversx_sdk::gateway::{GatewayProxy, DEVNET_GATEWAY};
use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEVNET_GATEWAY};

#[tokio::main]
async fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use multiversx_sdk::gateway::{GatewayProxy, DEVNET_GATEWAY};
use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEVNET_GATEWAY};

#[tokio::main]
async fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use multiversx_sdk::gateway::{GatewayProxy, DEVNET_GATEWAY};
use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEVNET_GATEWAY};

#[tokio::main]
async fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use multiversx_sdk::gateway::{GatewayProxy, DEVNET_GATEWAY};
use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEVNET_GATEWAY};

#[tokio::main]
async fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use multiversx_sdk::gateway::{GatewayProxy, DEVNET_GATEWAY};
use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEVNET_GATEWAY};

#[tokio::main]
async fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use multiversx_sdk::{
data::transaction::Transaction,
use multiversx_sdk_reqwest::{
core::data::transaction::Transaction,
gateway::{GatewayProxy, DEVNET_GATEWAY},
wallet::Wallet,
core::wallet::Wallet,
};

#[tokio::main]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use multiversx_sdk::{
data::transaction::Transaction,
use multiversx_sdk_reqwest::{
core::data::transaction::Transaction,
gateway::{GatewayProxy, DEVNET_GATEWAY},
wallet::Wallet,
core::wallet::Wallet,
};

#[tokio::main]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use multiversx_sdk::{
data::{address::Address, transaction::Transaction},
use multiversx_sdk_reqwest::{
core::data::{address::Address, transaction::Transaction},
core::utils::base64_encode,
gateway::{GatewayProxy, DEVNET_GATEWAY},
utils::base64_encode,
};

#[tokio::main]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use multiversx_sdk::{
data::address::Address,
use multiversx_sdk_reqwest::{
core::data::address::Address,
gateway::{GatewayProxy, DEVNET_GATEWAY},
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use multiversx_sdk::gateway::{GatewayProxy, DEVNET_GATEWAY};
use multiversx_sdk_reqwest::gateway::{GatewayProxy, DEVNET_GATEWAY};

#[tokio::main]
async fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use multiversx_sdk::{
data::{address::Address, vm::VmValueRequest},
use multiversx_sdk_reqwest::{
core::data::{address::Address, vm::VmValueRequest},
gateway::{GatewayProxy, DEVNET_GATEWAY},
wallet::Wallet,
core::wallet::Wallet,
};

#[tokio::main]
Expand Down
File renamed without changes.
Loading

0 comments on commit f735e6a

Please sign in to comment.