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

core Address referenced in SDK #1782

Merged
merged 5 commits into from
Sep 30, 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
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.

7 changes: 5 additions & 2 deletions contracts/examples/adder/interact/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
chain_type = 'simulator'
gateway_uri = 'http://localhost:8085'
# chain_type = 'simulator'
# gateway_uri = 'http://localhost:8085'

chain_type = 'real'
gateway_uri = 'https://devnet-gateway.multiversx.com'
26 changes: 4 additions & 22 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,12 +42,13 @@ impl Interactor {
}

pub async fn register_wallet(&mut self, wallet: Wallet) -> Address {
let address = erdrs_address_to_h256(wallet.address());
let wallet_address = wallet.address();
self.proxy
.send_user_funds(&Bech32Address::from(&address).to_bech32_string())
.send_user_funds(&wallet_address.to_bech32_string().unwrap())
.await
.unwrap();

let address: Address = wallet_address.into();
self.sender_map.insert(
address.clone(),
Sender {
Expand Down Expand Up @@ -80,17 +76,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 @@ -61,8 +61,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())
}
}

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
Loading