Skip to content

Commit

Permalink
Fix compilation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
CostinCarabas committed Mar 22, 2024
1 parent 7ad3b14 commit 5a43063
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 139 deletions.
238 changes: 118 additions & 120 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions bridge-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ path = "../common/transaction"
[dependencies.eth-address]
path = "../common/eth-address"

[dependencies.esdt-safe]
path = "../esdt-safe"

[dependencies.multiversx-sc]
version = "=0.47.5"

Expand Down
20 changes: 14 additions & 6 deletions bridge-proxy/src/bridge-proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ multiversx_sc::derive_imports!();

pub mod config;

use esdt_safe::ProxyTrait as _;
use transaction::EthTransaction;

#[multiversx_sc::contract]
Expand All @@ -26,16 +27,17 @@ pub trait BridgeProxyContract:
#[endpoint]
fn deposit(&self, eth_tx: EthTransaction<Self::Api>) {
self.require_not_paused();
let (token_id, amount) = self.call_value().single_fungible_esdt().into_tuple();
let (token_id, amount) = self.call_value().single_fungible_esdt();
require!(token_id == eth_tx.token_id, "Invalid token id");
require!(amount == eth_tx.amount, "Invalid amount");
self.pending_transactions().push(&eth_tx);
}

#[endpoint(executeWithAsnyc)]
fn execute_with_async(&self, tx_id: u64) {
fn execute_with_async(&self, tx_id: usize) {
self.require_not_paused();
let tx = self.pending_transactions().get_or_else(tx_id, || panic!("Invalid tx id"));
let tx = self.get_pending_transaction_by_id(tx_id);

require!(
tx.call_data.is_some(),
"There is no data for a SC call!"
Expand All @@ -56,21 +58,27 @@ pub trait BridgeProxyContract:
fn execution_callback(
&self,
#[call_result] result: ManagedAsyncCallResult<()>,
tx_id: u64,
tx_id: usize,
) {
if result.is_err() {
self.refund_transaction(tx_id);
}
self.pending_transactions().clear_entry_unchecked(tx_id);
}

fn refund_transaction(&self, tx_id: u64) {
let tx = self.eth_transaction().get(tx_id);
fn refund_transaction(&self, tx_id: usize) {
let tx = self.get_pending_transaction_by_id(tx_id);

let _: IgnoreValue = self
.get_esdt_safe_proxy_instance()
.create_transaction(tx.from)
.with_esdt_transfer((tx.token_id.clone(), 0, tx.amount.clone()))
.execute_on_dest_context();
}

#[view(getPendingTransactionById)]
fn get_pending_transaction_by_id(&self, tx_id: usize) -> EthTransaction<Self::Api> {
self.pending_transactions().get_or_else(tx_id, || panic!("Invalid tx id"))
}

}
1 change: 0 additions & 1 deletion bridge-proxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use transaction::EthTransaction;
use esdt_safe::ProxyTrait as _;

#[multiversx_sc::module]
pub trait ConfigModule {
Expand Down
8 changes: 4 additions & 4 deletions bridge-proxy/tests/bridge_proxy_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use multiversx_sc_scenario::{
};

use eth_address::*;
use transaction::{CallData, EthTransaction, EthTransactionPayment};
use transaction::{CallData, EthTransaction};

const BRIDGE_TOKEN_ID: &[u8] = b"BRIDGE-123456";
const GAS_LIMIT: u64 = 1_000_000;
Expand Down Expand Up @@ -161,7 +161,7 @@ fn deploy_deposit_test() {
test.world.sc_query(
ScQueryStep::new()
.to(&test.bridge_proxy_contract)
.call(test.bridge_proxy_contract.get_eth_transaction_by_id(1u32))
.call(test.bridge_proxy_contract.get_pending_transaction_by_id(1u32))
.expect_value(eth_tx),
);

Expand Down Expand Up @@ -251,14 +251,14 @@ fn multiple_deposit_test() {
test.world.sc_query(
ScQueryStep::new()
.to(&test.bridge_proxy_contract)
.call(test.bridge_proxy_contract.get_eth_transaction_by_id(1u32))
.call(test.bridge_proxy_contract.get_pending_transaction_by_id(1u32))
.expect_value(eth_tx1),
);

test.world.sc_query(
ScQueryStep::new()
.to(&test.bridge_proxy_contract)
.call(test.bridge_proxy_contract.get_eth_transaction_by_id(2u32))
.call(test.bridge_proxy_contract.get_pending_transaction_by_id(2u32))
.expect_value(eth_tx2),
);

Expand Down
207 changes: 207 additions & 0 deletions bridge-proxy/wasm/Cargo.lock

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

Loading

0 comments on commit 5a43063

Please sign in to comment.