diff --git a/eth-connector/src/contract.rs b/eth-connector/src/contract.rs index 16d93a1..175c772 100644 --- a/eth-connector/src/contract.rs +++ b/eth-connector/src/contract.rs @@ -9,7 +9,6 @@ use crate::operation::{ ViewStorageBalanceBounds, ViewStorageBalanceOf, }; use crate::types::{MigrationInputData, PausedMask, Proof}; -use aurora_engine_types::account_id::AccountId; use aurora_engine_types::types::Address; use aurora_workspace_utils::{Contract, ContractId}; use near_contract_standards::fungible_token::metadata::FungibleTokenMetadata; @@ -42,16 +41,16 @@ impl ContractId for EthConnectorContract { impl EthConnectorContract { pub fn init( &self, - prover_account: AccountId, + prover_account: &impl AsRef, eth_custodian_address: String, metadata: FungibleTokenMetadata, - account_with_access_right: &AccountId, - owner_id: AccountId, + account_with_access_right: &impl AsRef, + owner_id: &impl AsRef, ) -> CallNew { CallNew::call(&self.contract).args_json(json!({ - "prover_account": prover_account, - "account_with_access_right": account_with_access_right, - "owner_id": owner_id, + "prover_account": prover_account.as_ref(), + "account_with_access_right": account_with_access_right.as_ref(), + "owner_id": owner_id.as_ref(), "eth_custodian_address": eth_custodian_address, "metadata": metadata, })) @@ -59,23 +58,24 @@ impl EthConnectorContract { pub fn ft_transfer( &self, - receiver_id: AccountId, + receiver_id: &impl AsRef, amount: U128, memo: Option, ) -> CallFtTransfer { - CallFtTransfer::call(&self.contract) - .args_json(json!({ "receiver_id": receiver_id, "amount": amount, "memo": memo })) + CallFtTransfer::call(&self.contract).args_json( + json!({ "receiver_id": receiver_id.as_ref(), "amount": amount, "memo": memo }), + ) } pub fn ft_transfer_call( &self, - receiver_id: AccountId, + receiver_id: &impl AsRef, amount: U128, memo: Option, msg: String, ) -> CallFtTransferCall { CallFtTransferCall::call(&self.contract).args_json(json!({ - "receiver_id": receiver_id, + "receiver_id": receiver_id.as_ref(), "amount": amount, "memo": memo, "msg": msg, @@ -84,14 +84,14 @@ impl EthConnectorContract { pub fn engine_ft_transfer( &self, - sender_id: AccountId, - receiver_id: AccountId, + sender_id: &impl AsRef, + receiver_id: &impl AsRef, amount: U128, memo: Option, ) -> CallEngineFtTransfer { CallEngineFtTransfer::call(&self.contract).args_json(json!({ - "sender_id": sender_id, - "receiver_id": receiver_id, + "sender_id": sender_id.as_ref(), + "receiver_id": receiver_id.as_ref(), "amount": amount, "memo": memo })) @@ -99,38 +99,42 @@ impl EthConnectorContract { pub fn engine_ft_transfer_call( &self, - sender_id: AccountId, - receiver_id: AccountId, + sender_id: &impl AsRef, + receiver_id: &impl AsRef, amount: U128, memo: Option, msg: String, ) -> CallEngineFtTransferCall { CallEngineFtTransferCall::call(&self.contract).args_json(json!({ - "sender_id": sender_id, - "receiver_id": receiver_id, + "sender_id": sender_id.as_ref(), + "receiver_id": receiver_id.as_ref(), "amount": amount, "memo": memo, "msg": msg, })) } - pub fn set_engine_account(&self, engine_account: &AccountId) -> CallSetEngineAccount { + pub fn set_engine_account(&self, engine_account: &impl AsRef) -> CallSetEngineAccount { CallSetEngineAccount::call(&self.contract).args_json(json!({ - "engine_account": engine_account, + "engine_account": engine_account.as_ref(), })) } - pub fn remove_engine_account(&self, engine_account: &AccountId) -> CallRemoveEngineAccount { + pub fn remove_engine_account( + &self, + engine_account: &impl AsRef, + ) -> CallRemoveEngineAccount { CallRemoveEngineAccount::call(&self.contract).args_json(json!({ - "engine_account": engine_account, + "engine_account": engine_account.as_ref(), })) } pub fn storage_deposit( &self, - account_id: Option, + account_id: Option<&impl AsRef>, registration_only: Option, ) -> CallStorageDeposit { + let account_id = account_id.map(|a| a.as_ref()); CallStorageDeposit::call(&self.contract) .args_json(json!({ "account_id": account_id, "registration_only": registration_only})) } @@ -145,38 +149,39 @@ impl EthConnectorContract { pub fn engine_storage_deposit( &self, - sender_id: AccountId, - account_id: Option, + sender_id: &impl AsRef, + account_id: Option<&impl AsRef>, registration_only: Option, ) -> CallEngineStorageDeposit { + let account_id = account_id.map(|a| a.as_ref()); CallEngineStorageDeposit::call(&self.contract) - .args_json(json!({ "sender_id": sender_id, "account_id": account_id, "registration_only": registration_only})) + .args_json(json!({ "sender_id": sender_id.as_ref(), "account_id": account_id, "registration_only": registration_only})) } pub fn engine_storage_withdraw( &self, - sender_id: AccountId, + sender_id: &impl AsRef, amount: Option, ) -> CallEngineStorageWithdraw { CallEngineStorageWithdraw::call(&self.contract) - .args_json(json!({ "sender_id": sender_id, "amount": amount })) + .args_json(json!({ "sender_id": sender_id.as_ref(), "amount": amount })) } pub fn engine_storage_unregister( &self, - sender_id: AccountId, + sender_id: &impl AsRef, force: Option, ) -> CallEngineStorageUnregister { CallEngineStorageUnregister::call(&self.contract) - .args_json(json!({ "sender_id": sender_id, "force": force })) + .args_json(json!({ "sender_id": sender_id.as_ref(), "force": force })) } pub fn set_paused_flags(&self, paused: PausedMask) -> CallSetPausedFlags { CallSetPausedFlags::call(&self.contract).args_borsh(paused) } - pub fn set_access_right(&self, account: AccountId) -> CallSetAccessRight { - CallSetAccessRight::call(&self.contract).args_json((account,)) + pub fn set_access_right(&self, account: &impl AsRef) -> CallSetAccessRight { + CallSetAccessRight::call(&self.contract).args_json((account.as_ref(),)) } pub fn withdraw(&self, recipient_address: Address, amount: Balance) -> CallWithdraw { @@ -185,11 +190,15 @@ impl EthConnectorContract { pub fn engine_withdraw( &self, - sender_id: AccountId, + sender_id: &impl AsRef, recipient_address: Address, amount: Balance, ) -> CallEngineWithdraw { - CallEngineWithdraw::call(&self.contract).args_borsh((sender_id, recipient_address, amount)) + CallEngineWithdraw::call(&self.contract).args_borsh(( + sender_id.as_ref(), + recipient_address, + amount, + )) } pub fn deposit(&self, raw_proof: Proof) -> CallDeposit { @@ -234,17 +243,21 @@ impl EthConnectorContract { ViewIsUsedProof::view(&self.contract).args_borsh(proof) } - pub fn storage_balance_of(&self, account_id: AccountId) -> ViewStorageBalanceOf { - ViewStorageBalanceOf::view(&self.contract).args_json(json!({ "account_id": account_id })) + pub fn storage_balance_of(&self, account_id: &impl AsRef) -> ViewStorageBalanceOf { + ViewStorageBalanceOf::view(&self.contract) + .args_json(json!({ "account_id": account_id.as_ref() })) } pub fn storage_balance_bounds(&self) -> ViewStorageBalanceBounds { ViewStorageBalanceBounds::view(&self.contract) } - pub fn is_engine_account_exist(&self, engine_account: &AccountId) -> ViewIsEngineAccountExist { + pub fn is_engine_account_exist( + &self, + engine_account: &impl AsRef, + ) -> ViewIsEngineAccountExist { ViewIsEngineAccountExist::view(&self.contract).args_json(json!({ - "engine_account": engine_account, + "engine_account": engine_account.as_ref(), })) } @@ -252,7 +265,7 @@ impl EthConnectorContract { ViewFtTotalSupply::view(&self.contract) } - pub fn ft_balance_of(&self, account_id: AccountId) -> ViewFtBalanceOf { - ViewFtBalanceOf::view(&self.contract).args_json(json!((account_id,))) + pub fn ft_balance_of(&self, account_id: &impl AsRef) -> ViewFtBalanceOf { + ViewFtBalanceOf::view(&self.contract).args_json(json!((account_id.as_ref(),))) } } diff --git a/eth-connector/tests/fungible_token_tests.rs b/eth-connector/tests/fungible_token_tests.rs index 652e87d..d2407a9 100644 --- a/eth-connector/tests/fungible_token_tests.rs +++ b/eth-connector/tests/fungible_token_tests.rs @@ -35,11 +35,11 @@ async fn deploy_and_init() -> anyhow::Result { eth_contract .init( - prover_account, + &prover_account, eth_custodian_address, metadata, &account_with_access_right, - owner_id, + &owner_id, ) .transact() .await?; @@ -54,7 +54,7 @@ async fn test_ft_transfer() { let memo = Some(String::from("some message")); contract - .ft_transfer(some_acc, amount, memo) + .ft_transfer(&some_acc, amount, memo) .max_gas() .deposit(1) .transact() @@ -71,7 +71,7 @@ async fn test_ft_transfer_call() { let msg = String::from("some msg"); let res: PromiseOrValue = contract - .ft_transfer_call(some_acc, amount, memo, msg) + .ft_transfer_call(&some_acc, amount, memo, msg) .max_gas() .deposit(1) .transact() @@ -102,7 +102,7 @@ async fn test_ft_balance_of() { let contract = deploy_and_init().await.unwrap(); let account = contract.as_contract().id(); let account_id = AccountId::from_str(account.as_str()).unwrap(); - let res = contract.ft_balance_of(account_id).await.unwrap(); + let res = contract.ft_balance_of(&account_id).await.unwrap(); let expected = ViewResult { result: U128::from(200), logs: vec![], @@ -154,7 +154,7 @@ async fn test_storage_deposit() { let contract = deploy_and_init().await.unwrap(); let account_id = AccountId::from_str("test.near").unwrap(); let res = contract - .storage_deposit(Some(account_id), Some(true)) + .storage_deposit(Some(&account_id), Some(true)) .max_gas() .transact() .await @@ -199,7 +199,7 @@ async fn test_engine_storage_deposit() { let sender_id = AccountId::from_str("test.near").unwrap(); let account_id = sender_id.clone(); let res = contract - .engine_storage_deposit(sender_id, Some(account_id), Some(true)) + .engine_storage_deposit(&sender_id, Some(&account_id), Some(true)) .max_gas() .transact() .await @@ -215,7 +215,7 @@ async fn test_engine_storage_withdraw() { let sender_id = AccountId::from_str("test.near").unwrap(); let amount = Some(U128::from(100)); let res = contract - .engine_storage_withdraw(sender_id, amount) + .engine_storage_withdraw(&sender_id, amount) .max_gas() .transact() .await @@ -231,7 +231,7 @@ async fn test_engine_storage_unregister() { let sender_id = AccountId::from_str("test.near").unwrap(); let force = Some(true); let res = contract - .engine_storage_unregister(sender_id, force) + .engine_storage_unregister(&sender_id, force) .max_gas() .transact() .await @@ -244,7 +244,7 @@ async fn test_engine_storage_unregister() { async fn test_storage_balance_of() { let contract = deploy_and_init().await.unwrap(); let account_id = AccountId::from_str("test.near").unwrap(); - let res = contract.storage_balance_of(account_id).await.unwrap(); + let res = contract.storage_balance_of(&account_id).await.unwrap(); let result = res.result; assert_eq!(result.total, U128::from(10)); assert_eq!(result.available, U128::from(20)); @@ -274,7 +274,7 @@ async fn test_set_access_right() { let contract = deploy_and_init().await.unwrap(); let account = AccountId::from_str("test.near").unwrap(); contract - .set_access_right(account) + .set_access_right(&account) .max_gas() .transact() .await @@ -306,7 +306,7 @@ async fn test_engine_withdraw() { let sender_id = AccountId::from_str("test.near").unwrap(); let recipient_address = Address::zero(); let res = contract - .engine_withdraw(sender_id, recipient_address, 10) + .engine_withdraw(&sender_id, recipient_address, 10) .max_gas() .transact() .await