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

SdkAddress rename #1800

Merged
merged 1 commit into from
Oct 3, 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
4 changes: 2 additions & 2 deletions framework/meta/src/cmd/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::str;
use crate::cli::{WalletAction, WalletArgs, WalletBech32Args, WalletConvertArgs, WalletNewArgs};
use multiversx_sc::types::{self};
use multiversx_sc_snippets::sdk::{
crypto::public_key::PublicKey, data::address::Address, wallet::Wallet,
crypto::public_key::PublicKey, data::sdk_address::SdkAddress, wallet::Wallet,
};
use multiversx_sc_snippets::{hex, imports::Bech32Address};
use std::{
Expand Down Expand Up @@ -137,7 +137,7 @@ fn bech32_conversion(bech32_args: &WalletBech32Args) {
}
}

fn get_wallet_address(private_key: &str) -> Address {
fn get_wallet_address(private_key: &str) -> SdkAddress {
let wallet = Wallet::from_private_key(private_key).unwrap();
wallet.address()
}
Expand Down
4 changes: 2 additions & 2 deletions framework/snippets-dapp/src/account_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use multiversx_sc_scenario::{
scenario_model::{Account, BytesKey, BytesValue, Scenario, SetStateStep, Step},
};
use multiversx_sdk_wbg::{
data::{address::Address, esdt::EsdtBalance},
data::{esdt::EsdtBalance, sdk_address::SdkAddress},
gateway::GatewayProxy,
};
use std::collections::{BTreeMap, HashMap};
Expand Down Expand Up @@ -37,7 +37,7 @@ pub async fn retrieve_account_as_scenario_set_state(
api: &GatewayProxy,
address: &Bech32Address,
) -> SetStateStep {
let sdk_address = Address::from_bech32_string(address.to_bech32_str()).unwrap();
let sdk_address = SdkAddress::from_bech32_string(address.to_bech32_str()).unwrap();
let sdk_account = api.get_account(&sdk_address).await.unwrap();

let account_esdt = api
Expand Down
2 changes: 1 addition & 1 deletion framework/snippets-dapp/src/interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use multiversx_sc_scenario::{
scenario_model::AddressValue,
};
use multiversx_sdk_wbg::{
data::{address::Address as ErdrsAddress, network_config::NetworkConfig},
data::{network_config::NetworkConfig, sdk_address::SdkAddress as ErdrsAddress},
gateway::GatewayProxy,
wallet::Wallet,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use multiversx_sc_scenario::{
scenario_model::{ScDeployStep, SetStateStep},
};
use multiversx_sdk_wbg::{
data::{address::Address as ErdrsAddress, transaction::Transaction},
data::{sdk_address::SdkAddress as ErdrsAddress, transaction::Transaction},
utils::base64_encode,
};

Expand Down
4 changes: 2 additions & 2 deletions framework/snippets/src/account_tool.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::sdk_core::data::{address::Address, esdt::EsdtBalance};
use crate::sdk_core::data::{esdt::EsdtBalance, sdk_address::SdkAddress};
use multiversx_chain_scenario_format::interpret_trait::IntoRaw;
use multiversx_sc_scenario::{
imports::Bech32Address,
Expand Down Expand Up @@ -38,7 +38,7 @@ pub async fn retrieve_account_as_scenario_set_state(
use_chain_simulator: bool,
address: &Bech32Address,
) -> SetStateStep {
let sdk_address = Address::from_bech32_string(address.to_bech32_str()).unwrap();
let sdk_address = SdkAddress::from_bech32_string(address.to_bech32_str()).unwrap();
let sdk_account = api.get_account(&sdk_address).await.unwrap();

let (account_esdt, account_esdt_roles, account_storage) = if use_chain_simulator {
Expand Down
4 changes: 2 additions & 2 deletions framework/snippets/src/interactor_chain_simulator.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::Error;
use multiversx_sdk::{
data::address::Address,
data::sdk_address::SdkAddress,
gateway::{
ChainSimulatorGenerateBlocksRequest, ChainSimulatorSendFundsRequest, GatewayAsyncService,
},
Expand All @@ -9,7 +9,7 @@ use multiversx_sdk::{
use crate::Interactor;

impl Interactor {
pub async fn send_user_funds(&self, receiver: &Address) -> Result<String, Error> {
pub async fn send_user_funds(&self, receiver: &SdkAddress) -> Result<String, Error> {
if !self.use_chain_simulator {
return Ok(String::from("no-simulator"));
}
Expand Down
2 changes: 1 addition & 1 deletion framework/snippets/tests/test_tx_deployed_address.rs
Original file line number Diff line number Diff line change
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_sc_snippets::sdk::data::address::Address::from_bytes(*e.as_array())
multiversx_sc_snippets::sdk::data::sdk_address::SdkAddress::from_bytes(*e.as_array())
.to_bech32_string()
.unwrap()
});
Expand Down
2 changes: 1 addition & 1 deletion sdk/core/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
pub mod account;
pub mod account_storage;
pub mod address;
pub mod esdt;
pub mod hyperblock;
pub mod keystore;
pub mod network_config;
pub mod network_economics;
pub mod network_status;
pub mod sdk_address;
pub mod transaction;
pub mod vm;
4 changes: 2 additions & 2 deletions sdk/core/src/data/account.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::address::Address;
use super::sdk_address::SdkAddress;
use serde::{Deserialize, Serialize};

// Account holds an Account's information
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Account {
pub address: Address,
pub address: SdkAddress,
pub nonce: u64,
pub balance: String,
pub username: String,
Expand Down
32 changes: 16 additions & 16 deletions sdk/core/src/data/address.rs → sdk/core/src/data/sdk_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use serde::{
};

#[derive(Clone)]
pub struct Address([u8; 32]);
pub struct SdkAddress([u8; 32]);

impl Address {
impl SdkAddress {
pub fn from_bytes(bytes: [u8; 32]) -> Self {
Self(bytes)
}
Expand Down Expand Up @@ -40,48 +40,48 @@ impl Address {
}
}

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

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

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

let mut bits: [u8; 32] = [0u8; 32];
bits.copy_from_slice(&bytes);

Address(bits)
SdkAddress(bits)
}
}

impl Display for Address {
impl Display for SdkAddress {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.to_bech32_string().unwrap().as_str())
}
}

impl Debug for Address {
impl Debug for SdkAddress {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.to_bech32_string().unwrap().as_str())
}
}

impl Default for Address {
impl Default for SdkAddress {
fn default() -> Self {
Address::from_bytes([0u8; 32])
SdkAddress::from_bytes([0u8; 32])
}
}

impl Serialize for Address {
impl Serialize for SdkAddress {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand All @@ -90,7 +90,7 @@ impl Serialize for Address {
}
}

impl<'de> Deserialize<'de> for Address {
impl<'de> Deserialize<'de> for SdkAddress {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
Expand All @@ -106,7 +106,7 @@ pub mod tests {

#[test]
fn test_decode_address() {
let addr = Address::from_bech32_string(
let addr = SdkAddress::from_bech32_string(
"erd1qqqqqqqqqqqqqpgqyfjjn43spw7teklwtpz4x5waygq2mluyj9ts0mdwn6",
)
.unwrap();
Expand Down
22 changes: 11 additions & 11 deletions sdk/core/src/data/transaction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use super::{address::Address, vm::CallType};
use super::{sdk_address::SdkAddress, vm::CallType};
use serde::{Deserialize, Serialize};

// Transaction holds the fields of a transaction to be broadcasted to the network
Expand All @@ -9,8 +9,8 @@ use serde::{Deserialize, Serialize};
pub struct Transaction {
pub nonce: u64,
pub value: String,
pub receiver: Address,
pub sender: Address,
pub receiver: SdkAddress,
pub sender: SdkAddress,
pub gas_price: u64,
pub gas_limit: u64,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -58,8 +58,8 @@ pub struct TransactionOnNetwork {
pub round: u64,
pub epoch: u64,
pub value: String,
pub receiver: Address,
pub sender: Address,
pub receiver: SdkAddress,
pub sender: SdkAddress,
pub gas_price: u64,
pub gas_limit: u64,
#[serde(default)]
Expand Down Expand Up @@ -90,7 +90,7 @@ pub struct TransactionOnNetwork {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Events {
pub address: Address,
pub address: SdkAddress,
pub identifier: String,
pub topics: Option<Vec<String>>,
#[serde(default)]
Expand Down Expand Up @@ -120,7 +120,7 @@ impl LogData {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ApiLogs {
pub address: Address,
pub address: SdkAddress,
pub events: Vec<Events>,
}

Expand All @@ -130,8 +130,8 @@ pub struct ApiSmartContractResult {
pub hash: String,
pub nonce: u64,
pub value: u64,
pub receiver: Address,
pub sender: Address,
pub receiver: SdkAddress,
pub sender: SdkAddress,
pub data: String,
pub prev_tx_hash: String,
pub original_tx_hash: String,
Expand Down Expand Up @@ -192,8 +192,8 @@ pub struct TransactionProcessStatus {
pub struct ArgCreateTransaction {
pub nonce: u64,
pub value: String,
pub rcv_addr: Address,
pub snd_addr: Address,
pub rcv_addr: SdkAddress,
pub snd_addr: SdkAddress,
pub gas_price: u64,
pub gas_limit: u64,
pub data: Option<String>,
Expand Down
10 changes: 5 additions & 5 deletions sdk/core/src/data/vm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::address::Address;
use super::sdk_address::SdkAddress;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use std::collections::HashMap;
Expand Down Expand Up @@ -26,7 +26,7 @@ pub enum CallType {
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VMQueryInput {
pub sc_address: Address,
pub sc_address: SdkAddress,
pub func_name: String,
pub args: Vec<String>,
}
Expand All @@ -36,7 +36,7 @@ pub struct VMQueryInput {
#[serde(rename_all = "camelCase")]
pub struct LogEntryApi {
pub identifier: String,
pub address: Address,
pub address: SdkAddress,
pub topics: Vec<String>,
pub data: String,
}
Expand All @@ -49,14 +49,14 @@ pub struct OutputTransferApi {
pub gas_limit: u64,
pub data: String,
pub call_type: CallType,
pub sender_address: Address,
pub sender_address: SdkAddress,
}

// OutputAccountApi is a wrapper over vmcommon's OutputAccount
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct OutputAccountApi {
address: Address,
address: SdkAddress,
nonce: u64,

// TODO: unknow type of data
Expand Down
6 changes: 3 additions & 3 deletions sdk/core/src/gateway/gateway_account.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::data::{
account::{Account, AccountResponse},
address::Address,
sdk_address::SdkAddress,
};
use anyhow::anyhow;

Expand All @@ -9,11 +9,11 @@ use super::{GatewayRequest, GatewayRequestType};

/// Retrieves an account info from the network (nonce, balance).
pub struct GetAccountRequest<'a> {
pub address: &'a Address,
pub address: &'a SdkAddress,
}

impl<'a> GetAccountRequest<'a> {
pub fn new(address: &'a Address) -> Self {
pub fn new(address: &'a SdkAddress) -> Self {
Self { address }
}
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/core/src/gateway/gateway_account_esdt_roles.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::data::{address::Address, esdt::EsdtRolesResponse};
use crate::data::{esdt::EsdtRolesResponse, sdk_address::SdkAddress};
use anyhow::anyhow;
use std::collections::HashMap;

Expand All @@ -8,11 +8,11 @@ const ACCOUNT_ENDPOINT: &str = "address/";

/// Retrieves an all esdt roles of an account from the network.
pub struct GetAccountEsdtRolesRequest<'a> {
pub address: &'a Address,
pub address: &'a SdkAddress,
}

impl<'a> GetAccountEsdtRolesRequest<'a> {
pub fn new(address: &'a Address) -> Self {
pub fn new(address: &'a SdkAddress) -> Self {
Self { address }
}
}
Expand Down
6 changes: 3 additions & 3 deletions sdk/core/src/gateway/gateway_account_esdt_tokens.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::data::{
address::Address,
esdt::{EsdtBalance, EsdtBalanceResponse},
sdk_address::SdkAddress,
};
use anyhow::anyhow;
use std::collections::HashMap;
Expand All @@ -9,11 +9,11 @@ use super::{GatewayRequest, GatewayRequestType, ACCOUNT_ENDPOINT};

/// Retrieves an all esdt tokens of an account from the network.
pub struct GetAccountEsdtTokensRequest<'a> {
pub address: &'a Address,
pub address: &'a SdkAddress,
}

impl<'a> GetAccountEsdtTokensRequest<'a> {
pub fn new(address: &'a Address) -> Self {
pub fn new(address: &'a SdkAddress) -> Self {
Self { address }
}
}
Expand Down
Loading
Loading