Skip to content

Commit

Permalink
core Address referenced in SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica committed Sep 30, 2024
1 parent 33bdb49 commit 53613d0
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 57 deletions.
38 changes: 24 additions & 14 deletions Cargo.lock

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

23 changes: 2 additions & 21 deletions framework/snippets/src/interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ 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::{data::network_config::NetworkConfig, gateway::GatewayProxy, wallet::Wallet};
use std::{
collections::HashMap,
path::{Path, PathBuf},
Expand Down Expand Up @@ -47,7 +42,7 @@ impl Interactor {
}

pub fn register_wallet(&mut self, wallet: Wallet) -> Address {
let address = erdrs_address_to_h256(wallet.address());
let address: Address = wallet.address().into();
self.sender_map.insert(
address.clone(),
Sender {
Expand Down Expand Up @@ -75,17 +70,3 @@ impl Interactor {
self.post_runners.run_set_state_step(&set_state);
}
}

pub(crate) fn mandos_to_erdrs_address(mandos_address: &AddressValue) -> ErdrsAddress {
let bytes = mandos_address.value.as_array();
ErdrsAddress::from_bytes(*bytes)
}

pub(crate) fn address_h256_to_erdrs(address: &Address) -> ErdrsAddress {
let bytes = address.as_array();
ErdrsAddress::from_bytes(*bytes)
}

pub(crate) fn erdrs_address_to_h256(erdrs_address: ErdrsAddress) -> Address {
erdrs_address.to_bytes().into()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{address_h256_to_erdrs, mandos_to_erdrs_address, network_response, Interactor};
use crate::{network_response, Interactor};
use log::info;
use multiversx_sc_scenario::{
api::StaticApi,
Expand Down Expand Up @@ -57,8 +57,8 @@ impl Interactor {
Transaction {
nonce: 0,
value: contract_call.egld_payment.to_alloc().to_string(),
sender: mandos_to_erdrs_address(&tx_call.from),
receiver: address_h256_to_erdrs(&contract_call.basic.to.to_address()),
sender: tx_call.from.to_address().into(),
receiver: contract_call.basic.to.to_address().into(),
gas_price: self.network_config.min_gas_price,
gas_limit: tx_call.gas_limit.value,
data,
Expand Down
15 changes: 5 additions & 10 deletions framework/snippets/src/interactor_scenario/interactor_sc_deploy.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
use crate::{mandos_to_erdrs_address, network_response, Interactor};
use crate::{network_response, Interactor};
use log::info;
use multiversx_sc_scenario::{
imports::Bech32Address,
imports::{Address, Bech32Address},
mandos_system::ScenarioRunner,
scenario_model::{ScDeployStep, SetStateStep},
};
use multiversx_sdk::{
data::{address::Address as ErdrsAddress, transaction::Transaction},
utils::base64_encode,
};

const DEPLOY_RECEIVER: [u8; 32] = [0u8; 32];
use multiversx_sdk::{data::transaction::Transaction, utils::base64_encode};

impl Interactor {
pub(crate) fn sc_deploy_to_blockchain_tx(&self, sc_deploy_step: &ScDeployStep) -> Transaction {
Transaction {
nonce: 0,
value: sc_deploy_step.tx.egld_value.value.to_string(),
sender: mandos_to_erdrs_address(&sc_deploy_step.tx.from),
receiver: ErdrsAddress::from_bytes(DEPLOY_RECEIVER),
sender: sc_deploy_step.tx.from.to_address().into(),
receiver: Address::zero().into(),
gas_price: self.network_config.min_gas_price,
gas_limit: sc_deploy_step.tx.gas_limit.value,
data: Some(base64_encode(sc_deploy_step.tx.to_tx_data())),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(deprecated)]

use crate::{address_h256_to_erdrs, Interactor};
use crate::Interactor;
use log::info;
use multiversx_sc_scenario::{
api::StaticApi,
Expand All @@ -20,17 +20,17 @@ impl Interactor {
}

pub async fn perform_sc_query(&mut self, step: &mut ScQueryStep) {
let sc_address = address_h256_to_erdrs(&step.tx.to.to_address());
let req = VmValueRequest {
sc_address: sc_address.clone(),
let sc_address = step.tx.to.to_address();
let req = VmValueRequest {
sc_address: sc_address.clone().into(),
func_name: step.tx.function.clone(),
args: step
.tx
.arguments
.iter()
.map(|arg| hex::encode(&arg.value))
.collect(),
caller: sc_address,
caller: sc_address.into(),
value: "0".to_string(),
};
let result = self
Expand Down
5 changes: 2 additions & 3 deletions framework/snippets/src/interactor_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use log::debug;
use multiversx_sc_scenario::multiversx_sc::types::Address;
use multiversx_sdk::{data::transaction::Transaction, wallet::Wallet};

use crate::{address_h256_to_erdrs, Interactor};
use crate::Interactor;

/// A user account that can sign transactions (a pem is present).
pub struct Sender {
Expand All @@ -13,10 +13,9 @@ pub struct Sender {

impl Interactor {
pub async fn recall_nonce(&self, address: &Address) -> u64 {
let erdrs_address = address_h256_to_erdrs(address);
let account = self
.proxy
.get_account(&erdrs_address)
.get_account(&address.clone().into())
.await
.expect("failed to retrieve account nonce");
account.nonce
Expand Down
6 changes: 5 additions & 1 deletion sdk/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ log = "0.4.17"
scrypt = "0.11"
aes = "0.8"
ctr = "0.9.2"
uuid = {version = "1.10.0", features = ["v4"]}
uuid = {version = "1.10.0", features = ["v4"]}

[dependencies.multiversx-chain-core]
version = "=0.10.0"
path = "../../vm-core"
File renamed without changes.
12 changes: 12 additions & 0 deletions sdk/core/src/data/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ impl Address {
}
}

impl From<multiversx_chain_core::types::Address> for Address {
fn from(value: multiversx_chain_core::types::Address) -> Self {
Address(value.as_array().clone())

Check warning on line 45 in sdk/core/src/data/address.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] sdk/core/src/data/address.rs#L45

warning: using `clone` on type `[u8; 32]` which implements the `Copy` trait --> sdk/core/src/data/address.rs:45:17 | 45 | Address(value.as_array().clone()) | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*value.as_array()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy = note: `#[warn(clippy::clone_on_copy)]` on by default
Raw output
sdk/core/src/data/address.rs:45:17:w:warning: using `clone` on type `[u8; 32]` which implements the `Copy` trait
  --> sdk/core/src/data/address.rs:45:17
   |
45 |         Address(value.as_array().clone())
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*value.as_array()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
   = note: `#[warn(clippy::clone_on_copy)]` on by default


__END__

Check warning on line 45 in sdk/core/src/data/address.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] sdk/core/src/data/address.rs#L45

warning: using `clone` on type `[u8; 32]` which implements the `Copy` trait --> sdk/core/src/data/address.rs:45:17 | 45 | Address(value.as_array().clone()) | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*value.as_array()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy = note: `#[warn(clippy::clone_on_copy)]` on by default
Raw output
sdk/core/src/data/address.rs:45:17:w:warning: using `clone` on type `[u8; 32]` which implements the `Copy` trait
  --> sdk/core/src/data/address.rs:45:17
   |
45 |         Address(value.as_array().clone())
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*value.as_array()`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
   = note: `#[warn(clippy::clone_on_copy)]` on by default


__END__
}
}

impl From<Address> for multiversx_chain_core::types::Address {
fn from(value: Address) -> Self {
multiversx_chain_core::types::Address::new(value.0)
}
}

impl<'a> From<&'a PublicKey> for Address {
fn from(public_key: &PublicKey) -> Address {
let bytes = public_key.to_bytes();
Expand Down

0 comments on commit 53613d0

Please sign in to comment.