Skip to content

Commit

Permalink
Fix(engine): Remove unnecessary eth-connector logic (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
birchmd committed Oct 21, 2021
1 parent 581ecb2 commit 6b1ea7d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 35 deletions.
10 changes: 0 additions & 10 deletions engine/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,16 +338,6 @@ impl EthConnectorContract {
}
}

/// Internal logic for explicitly setting an eth balance (needed by ApplyBackend for Engine)
pub(crate) fn internal_set_eth_balance(&mut self, address: &Address, amount: &U256) {
// Call to `as_u128` here should be fine because u128::MAX is a value greater than
// all the Wei in existence, so a u128 should always be able to represent
// the balance of a single account.
self.ft
.internal_set_eth_balance(address.0, amount.as_u128());
self.save_ft_contract();
}

/// Internal ETH withdraw ETH logic
pub(crate) fn internal_remove_eth(&mut self, address: &Address, amount: &U256) {
self.burn_eth_on_aurora(address.0, amount.as_u128());
Expand Down
4 changes: 0 additions & 4 deletions engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,10 +1028,6 @@ impl ApplyBackend for Engine {
} => {
let generation = Self::get_generation(&address);
Engine::set_nonce(&address, &basic.nonce);

// Apply changes for eth-connector
EthConnectorContract::get_instance()
.internal_set_eth_balance(&address, &basic.balance);
Engine::set_balance(&address, &Wei::new(basic.balance));

if let Some(code) = code {
Expand Down
23 changes: 2 additions & 21 deletions engine/src/fungible_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::json::{parse_json, JsonValue};
use crate::parameters::{FtResolveTransfer, NEP141FtOnTransferArgs, StorageBalance};
use crate::prelude::{
sdk, storage, str_from_slice, AccountId, Address, BTreeMap, Balance, BorshDeserialize,
BorshSerialize, EthAddress, Gas, Ordering, PromiseResult, StorageBalanceBounds, StorageUsage,
String, ToString, TryInto, Vec, Wei, U256,
BorshSerialize, EthAddress, Gas, PromiseResult, StorageBalanceBounds, StorageUsage, String,
ToString, TryInto, Vec, Wei, U256,
};

const GAS_FOR_RESOLVE_TRANSFER: Gas = 5_000_000_000_000;
Expand Down Expand Up @@ -130,25 +130,6 @@ impl FungibleToken {
}
}

/// Needed by engine to update balances after a transaction (see ApplyBackend for Engine)
pub(crate) fn internal_set_eth_balance(&mut self, address: EthAddress, new_balance: Balance) {
let current_balance = self.internal_unwrap_balance_of_eth_on_aurora(address);
match current_balance.cmp(&new_balance) {
Ordering::Less => {
// current_balance is smaller, so we need to deposit
let diff = new_balance - current_balance;
self.internal_deposit_eth_to_aurora(address, diff);
}
Ordering::Greater => {
// current_balance is larger, so we need to withdraw
let diff = current_balance - new_balance;
self.internal_withdraw_eth_from_aurora(address, diff);
}
// if the balances are equal then we do not need to do anything
Ordering::Equal => (),
}
}

/// Withdraw NEAR tokens
pub fn internal_withdraw_eth_from_near(&mut self, account_id: &str, amount: Balance) {
let balance = self.internal_unwrap_balance_of_eth_on_near(account_id);
Expand Down

0 comments on commit 6b1ea7d

Please sign in to comment.