Skip to content

Commit

Permalink
re-entry issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
sagars committed Sep 11, 2024
1 parent 29cc674 commit 12cac36
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions contracts/asset_manager/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct ConfigData {
pub xcall_manager: Address,
pub native_address: Address,
pub icon_asset_manager: String,
pub xcall_network_address: String,
}

pub fn set_config(e: &Env, config: ConfigData) {
Expand Down
8 changes: 3 additions & 5 deletions contracts/asset_manager/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use crate::{
storage_types::{DataKey, POINTS},
xcall_manager_interface::XcallManagerClient,
};
use soroban_rlp::balanced::address_utils::{get_address_from, is_valid_string_address};
use soroban_rlp::balanced::address_utils::is_valid_string_address;
use soroban_rlp::balanced::messages::{
deposit::Deposit, deposit_revert::DepositRevert, withdraw_to::WithdrawTo,
};

use xcall::{AnyMessage, CallMessageWithRollback, Client, Envelope, NetworkAddress};
use xcall::{AnyMessage, CallMessageWithRollback, Client, Envelope};

const DEPOSIT_NAME: &str = "Deposit";
const WITHDRAW_TO_NAME: &str = "WithdrawTo";
Expand All @@ -35,7 +35,6 @@ impl AssetManager {
if has_registry(&env.clone()) {
panic_with_error!(&env, ContractError::ContractAlreadyInitialized)
}

write_registry(&env, &registry);
write_administrator(&env, &admin);
Self::configure(env, config);
Expand Down Expand Up @@ -273,8 +272,7 @@ impl AssetManager {
message.amount,
)?;
} else if method == String::from_str(&e, &DEPOSIT_REVERT_NAME) {
let xcall_network_address = Self::xcall_client(&e, &xcall).get_network_address();
if xcall_network_address != from {
if config.xcall_network_address != from {
return Err(ContractError::OnlyCallService);
}
let message: DepositRevert = DepositRevert::decode(&e.clone(), data);
Expand Down
2 changes: 1 addition & 1 deletion contracts/asset_manager/src/storage_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum DataKey {
Admin,
Config,
Tokens,
TokenData(Address),
TokenData(Address)
}

#[derive(Clone)]
Expand Down
6 changes: 4 additions & 2 deletions contracts/asset_manager/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ impl TestContext {

pub fn init_context(&self, client: &AssetManagerClient<'static>) {
self.env.mock_all_auths();
self.init_xcall_manager_context();
self.init_xcall_state();
let config = ConfigData {
xcall: self.xcall.clone(),
xcall_manager: self.xcall_manager.clone(),
native_address: self.native_token.clone(),
icon_asset_manager: self.icon_asset_manager.clone(),
xcall_network_address: self.xcall_client.get_network_address()
};
client.initialize(&self.registry, &self.admin, &config);
self.init_xcall_manager_context();
self.init_xcall_state();

}

pub fn init_xcall_manager_context(&self) {
Expand Down
3 changes: 1 addition & 2 deletions contracts/balanced_doller/src/balanced_dollar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ pub fn _handle_call_message(
let to_network_address: Address = get_address(message.to, &e)?;
_mint(&e, to_network_address, message.amount as i128);
} else if method == String::from_str(&e, &CROSS_TRANSFER_REVERT) {
let xcall_network_address = xcall_client(&e, &xcall).get_network_address();
if xcall_network_address != from {
if config.xcall_network_address != from {
return Err(ContractError::OnlyCallService);
}
let message = CrossTransferRevert::decode(&e, data);
Expand Down
1 change: 1 addition & 0 deletions contracts/balanced_doller/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct ConfigData {
pub xcall_manager: Address,
pub nid: String,
pub icon_bn_usd: String,
pub xcall_network_address: String
}

pub fn set_config(e: &Env, config: ConfigData) {
Expand Down
6 changes: 4 additions & 2 deletions contracts/balanced_doller/src/tests/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,17 @@ impl TestContext {

pub fn init_context(&self, client: &BalancedDollarClient<'static>) {
self.env.mock_all_auths();
self.init_xcall_manager_context();
self.init_xcall_state();
let config = ConfigData {
xcall: self.xcall.clone(),
xcall_manager: self.xcall_manager.clone(),
nid: self.nid.clone(),
icon_bn_usd: self.icon_bn_usd.clone(),
xcall_network_address: self.xcall_client.get_network_address()
};
client.initialize(&self.admin, &config);
self.init_xcall_manager_context();
self.init_xcall_state();

}

pub fn init_xcall_manager_context(&self) {
Expand Down

0 comments on commit 12cac36

Please sign in to comment.