diff --git a/common/transaction/src/lib.rs b/common/transaction/src/lib.rs index a0999a48..56cd8383 100644 --- a/common/transaction/src/lib.rs +++ b/common/transaction/src/lib.rs @@ -54,6 +54,15 @@ pub struct EthTransaction { pub call_data: ManagedOption>, } +pub type EthTxAsMultiValue = MultiValue6< + EthAddress, + ManagedAddress, + TokenIdentifier, + BigUint, + TxNonce, + ManagedOption>, +>; + #[type_abi] #[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, ManagedVecItem, Clone)] pub struct Transaction { diff --git a/multi-transfer-esdt/src/lib.rs b/multi-transfer-esdt/src/lib.rs index 2ef176d0..491646bb 100644 --- a/multi-transfer-esdt/src/lib.rs +++ b/multi-transfer-esdt/src/lib.rs @@ -44,7 +44,7 @@ pub trait MultiTransferEsdt: fn batch_transfer_esdt_token( &self, batch_id: u64, - transfers: ManagedVec>, + transfers: MultiValueEncoded>, ) { let mut valid_payments_list = ManagedVec::new(); let mut valid_tx_list = ManagedVec::new(); @@ -55,7 +55,7 @@ pub trait MultiTransferEsdt: let safe_address = self.esdt_safe_contract_address().get(); - for eth_tx in transfers.iter() { + for eth_tx in transfers { let is_success: bool = self .tx() .to(safe_address.clone()) diff --git a/multi-transfer-esdt/src/multi_transfer_proxy.rs b/multi-transfer-esdt/src/multi_transfer_proxy.rs index 9c884eae..914e46aa 100644 --- a/multi-transfer-esdt/src/multi_transfer_proxy.rs +++ b/multi-transfer-esdt/src/multi_transfer_proxy.rs @@ -83,7 +83,7 @@ where { pub fn batch_transfer_esdt_token< Arg0: ProxyArg, - Arg1: ProxyArg>>, + Arg1: ProxyArg>>, >( self, batch_id: Arg0, diff --git a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs index 0e173ce6..b0a940e5 100644 --- a/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs +++ b/multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs @@ -11,7 +11,7 @@ use multiversx_sc::{ api::{HandleConstraints, ManagedTypeApi}, codec::{ multi_types::{MultiValueVec, OptionalValue}, - Empty, + Empty, TopEncode, }, contract_base::ManagedSerializer, storage::mappers::SingleValue, @@ -297,7 +297,8 @@ fn basic_transfer_test() { call_data: ManagedOption::some(call_data), }; - let mut transfers: ManagedVec> = ManagedVec::new(); + let mut transfers: MultiValueEncoded> = + MultiValueEncoded::new(); transfers.push(eth_tx); state @@ -360,7 +361,8 @@ fn batch_transfer_both_executed_test() { call_data: ManagedOption::some(call_data), }; - let mut transfers: ManagedVec> = ManagedVec::new(); + let mut transfers: MultiValueEncoded> = + MultiValueEncoded::new(); transfers.push(eth_tx1); transfers.push(eth_tx2); @@ -429,7 +431,8 @@ fn batch_two_transfers_same_token_test() { call_data: ManagedOption::some(call_data), }; - let mut transfers: ManagedVec> = ManagedVec::new(); + let mut transfers: MultiValueEncoded> = + MultiValueEncoded::new(); transfers.push(eth_tx1); transfers.push(eth_tx2); @@ -498,7 +501,8 @@ fn batch_transfer_both_failed_test() { call_data: ManagedOption::some(call_data), }; - let mut transfers: ManagedVec> = ManagedVec::new(); + let mut transfers: MultiValueEncoded> = + MultiValueEncoded::new(); transfers.push(eth_tx1); transfers.push(eth_tx2); diff --git a/multisig/scenarios/ethereum_to_multiversx_relayer_call_data_several_tx_test.scen.json b/multisig/scenarios/ethereum_to_multiversx_relayer_call_data_several_tx_test.scen.json index ebbe2cd9..f93e050c 100644 --- a/multisig/scenarios/ethereum_to_multiversx_relayer_call_data_several_tx_test.scen.json +++ b/multisig/scenarios/ethereum_to_multiversx_relayer_call_data_several_tx_test.scen.json @@ -353,7 +353,10 @@ "function": "proposeMultiTransferEsdtBatch", "arguments": [ "0x01", - "0x356439353965393865613733633335373738666665726431647977376179736e306e776d75616876786e68326530706d306b676a0000000e455448555344432d616661363839000000021388000000000000000100356439353965393865613733633335373738666665726431647977376179736e306e776d75616876786e68326530706d306b676a0000000e455448555344432d616661363839000000021388000000000000000200356439353965393865613733633335373738666665726431647977376179736e306e776d75616876786e68326530706d306b676a0000000e455448555344432d616661363839000000021388000000000000000301000000110000000466756e640000000005f5e10000356439353965393865613733633335373738666665726431647977376179736e306e776d75616876786e68326530706d306b676a0000000e455448555344432d6166613638390000000213880000000000000004010000001a0000000466756e640000000005f5e10001000000010000000135" + "0x356439353965393865613733633335373738666665726431647977376179736e306e776d75616876786e68326530706d306b676a0000000e455448555344432d616661363839000000021388000000000000000100", + "0x356439353965393865613733633335373738666665726431647977376179736e306e776d75616876786e68326530706d306b676a0000000e455448555344432d616661363839000000021388000000000000000200", + "0x356439353965393865613733633335373738666665726431647977376179736e306e776d75616876786e68326530706d306b676a0000000e455448555344432d616661363839000000021388000000000000000301000000110000000466756e640000000005f5e10000", + "0x356439353965393865613733633335373738666665726431647977376179736e306e776d75616876786e68326530706d306b676a0000000e455448555344432d6166613638390000000213880000000000000004010000001a0000000466756e640000000005f5e10001000000010000000135" ], "gasLimit": "5,000,000" }, diff --git a/multisig/scenarios/unstake.scen.json b/multisig/scenarios/unstake.scen.json index c952941a..ab177b2a 100644 --- a/multisig/scenarios/unstake.scen.json +++ b/multisig/scenarios/unstake.scen.json @@ -179,8 +179,7 @@ "value": "0", "function": "proposeMultiTransferEsdtBatch", "arguments": [ - "1", - "0x" + "1" ], "gasLimit": "40,000,000", "gasPrice": "0" @@ -194,4 +193,4 @@ } } ] -} +} \ No newline at end of file diff --git a/multisig/src/lib.rs b/multisig/src/lib.rs index e056130f..2c866839 100644 --- a/multisig/src/lib.rs +++ b/multisig/src/lib.rs @@ -267,7 +267,7 @@ pub trait Multisig: fn propose_multi_transfer_esdt_batch( &self, eth_batch_id: u64, - transfers: ManagedVec>, + transfers: MultiValueEncoded>, ) -> usize { let next_eth_batch_id = self.last_executed_eth_batch_id().get() + 1; require!( @@ -275,9 +275,10 @@ pub trait Multisig: "Can only propose for next batch ID" ); - self.require_valid_eth_tx_ids(&transfers); + let transfers_as_eth_tx = self.transfers_multi_value_to_eth_tx_vec(transfers); + self.require_valid_eth_tx_ids(&transfers_as_eth_tx); - let batch_hash = self.hash_eth_tx_batch(&transfers); + let batch_hash = self.hash_eth_tx_batch(&transfers_as_eth_tx); require!( self.batch_id_to_action_id_mapping(eth_batch_id) .get(&batch_hash) @@ -287,7 +288,7 @@ pub trait Multisig: let action_id = self.propose_action(Action::BatchTransferEsdtToken { eth_batch_id, - transfers, + transfers: transfers_as_eth_tx, }); self.batch_id_to_action_id_mapping(eth_batch_id) @@ -409,11 +410,13 @@ pub trait Multisig: self.last_executed_eth_tx_id().set(last_tx.tx_nonce); let multi_transfer_esdt_addr = self.multi_transfer_esdt_address().get(); + let transfers_multi: MultiValueEncoded> = + transfers.into(); self.tx() .to(multi_transfer_esdt_addr) .typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy) - .batch_transfer_esdt_token(eth_batch_id, transfers) + .batch_transfer_esdt_token(eth_batch_id, transfers_multi) .sync_call(); } } diff --git a/multisig/src/multi_transfer_esdt_proxy.rs b/multisig/src/multi_transfer_esdt_proxy.rs index 9c884eae..914e46aa 100644 --- a/multisig/src/multi_transfer_esdt_proxy.rs +++ b/multisig/src/multi_transfer_esdt_proxy.rs @@ -83,7 +83,7 @@ where { pub fn batch_transfer_esdt_token< Arg0: ProxyArg, - Arg1: ProxyArg>>, + Arg1: ProxyArg>>, >( self, batch_id: Arg0, diff --git a/multisig/src/multisig_proxy.rs b/multisig/src/multisig_proxy.rs index d80dfff6..f28b749e 100644 --- a/multisig/src/multisig_proxy.rs +++ b/multisig/src/multisig_proxy.rs @@ -180,7 +180,7 @@ where /// Sender Address, Destination Address, Token ID, Amount, Tx Nonce pub fn propose_multi_transfer_esdt_batch< Arg0: ProxyArg, - Arg1: ProxyArg>>, + Arg1: ProxyArg>>, >( self, eth_batch_id: Arg0, @@ -843,7 +843,7 @@ where /// To check if it was executed as well, use the wasActionExecuted view pub fn was_transfer_action_proposed< Arg0: ProxyArg, - Arg1: ProxyArg>>, + Arg1: ProxyArg>>, >( self, eth_batch_id: Arg0, @@ -862,7 +862,7 @@ where /// Will return 0 if the transfers were not proposed pub fn get_action_id_for_transfer_batch< Arg0: ProxyArg, - Arg1: ProxyArg>>, + Arg1: ProxyArg>>, >( self, eth_batch_id: Arg0, diff --git a/multisig/src/queries.rs b/multisig/src/queries.rs index e1e0ace6..4bb93210 100644 --- a/multisig/src/queries.rs +++ b/multisig/src/queries.rs @@ -1,7 +1,7 @@ use multiversx_sc::imports::*; use crate::{action::Action, esdt_safe_proxy, multi_transfer_esdt_proxy, user_role::UserRole}; -use transaction::{transaction_status::TransactionStatus, EthTransaction, TxBatchSplitInFields}; +use transaction::{transaction_status::TransactionStatus, EthTxAsMultiValue, TxBatchSplitInFields}; /// Note: Additional queries can be found in the Storage module #[multiversx_sc::module] @@ -73,7 +73,7 @@ pub trait QueriesModule: crate::storage::StorageModule + crate::util::UtilModule fn was_transfer_action_proposed( &self, eth_batch_id: u64, - transfers: ManagedVec>, + transfers: MultiValueEncoded>, ) -> bool { let action_id = self.get_action_id_for_transfer_batch(eth_batch_id, transfers); @@ -87,9 +87,10 @@ pub trait QueriesModule: crate::storage::StorageModule + crate::util::UtilModule fn get_action_id_for_transfer_batch( &self, eth_batch_id: u64, - transfers: ManagedVec>, + transfers: MultiValueEncoded>, ) -> usize { - let batch_hash = self.hash_eth_tx_batch(&transfers); + let transfers_as_struct = self.transfers_multi_value_to_eth_tx_vec(transfers); + let batch_hash = self.hash_eth_tx_batch(&transfers_as_struct); self.batch_id_to_action_id_mapping(eth_batch_id) .get(&batch_hash) diff --git a/multisig/src/util.rs b/multisig/src/util.rs index 36e9eff0..36661a1c 100644 --- a/multisig/src/util.rs +++ b/multisig/src/util.rs @@ -1,6 +1,6 @@ use multiversx_sc::imports::*; -use transaction::EthTransaction; +use transaction::{EthTransaction, EthTxAsMultiValue}; use crate::storage::EthBatchHash; use crate::user_role::UserRole; @@ -45,11 +45,23 @@ pub trait UtilModule: crate::storage::StorageModule { fn transfers_multi_value_to_eth_tx_vec( &self, - transfers: MultiValueEncoded>, + transfers: MultiValueEncoded>, ) -> ManagedVec> { let mut transfers_as_eth_tx = ManagedVec::new(); + // for transfer in transfers { + // transfers_as_eth_tx.push(transfer); + // } for transfer in transfers { - transfers_as_eth_tx.push(transfer); + let (from, to, token_id, amount, tx_nonce, call_data) = transfer.into_tuple(); + + transfers_as_eth_tx.push(EthTransaction { + from, + to, + token_id, + amount, + tx_nonce, + call_data, + }); } transfers_as_eth_tx diff --git a/multisig/tests/multisig_blackbox_test.rs b/multisig/tests/multisig_blackbox_test.rs index 6c50c24a..d6260c54 100644 --- a/multisig/tests/multisig_blackbox_test.rs +++ b/multisig/tests/multisig_blackbox_test.rs @@ -385,7 +385,8 @@ fn ethereum_to_multiversx_call_data_empty_test() { call_data: ManagedOption::none(), }; - let mut transfers: ManagedVec> = ManagedVec::new(); + let mut transfers: MultiValueEncoded> = + MultiValueEncoded::new(); transfers.push(eth_tx); state @@ -493,7 +494,8 @@ fn ethereum_to_multiversx_relayer_call_data_several_tx_test() { tx_nonce: 4u64, call_data: ManagedOption::some(call_data2), }; - let mut transfers: ManagedVec> = ManagedVec::new(); + let mut transfers: MultiValueEncoded> = + MultiValueEncoded::new(); transfers.push(eth_tx); transfers.push(eth_tx2); transfers.push(eth_tx3); @@ -556,7 +558,8 @@ fn ethereum_to_multiversx_relayer_query_test() { call_data: ManagedOption::none(), }; - let mut transfers: ManagedVec> = ManagedVec::new(); + let mut transfers: MultiValueEncoded> = + MultiValueEncoded::new(); transfers.push(eth_tx); state @@ -647,7 +650,8 @@ fn ethereum_to_multiversx_relayer_query2_test() { call_data: ManagedOption::none(), }; - let mut transfers: ManagedVec> = ManagedVec::new(); + let mut transfers: MultiValueEncoded> = + MultiValueEncoded::new(); transfers.push(eth_tx); state @@ -751,7 +755,8 @@ fn ethereum_to_multiversx_tx_batch_ok_test() { call_data: ManagedOption::some(call_data), }; - let mut transfers: ManagedVec> = ManagedVec::new(); + let mut transfers: MultiValueEncoded> = + MultiValueEncoded::new(); transfers.push(eth_tx1); transfers.push(eth_tx2); @@ -835,7 +840,8 @@ fn ethereum_to_multiversx_tx_batch_rejected_test() { call_data: ManagedOption::some(call_data), }; - let mut transfers: ManagedVec> = ManagedVec::new(); + let mut transfers: MultiValueEncoded> = + MultiValueEncoded::new(); transfers.push(eth_tx1); transfers.push(eth_tx2);