From c3fc7cb3429d87fac19154741a4ee8b8014743e6 Mon Sep 17 00:00:00 2001 From: Maksym Date: Wed, 20 Mar 2024 19:25:24 +0100 Subject: [PATCH] change PSP22 calls to builder --- shielder/contract/lib.rs | 46 ++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/shielder/contract/lib.rs b/shielder/contract/lib.rs index 0eb0b0e..b09021d 100755 --- a/shielder/contract/lib.rs +++ b/shielder/contract/lib.rs @@ -12,7 +12,9 @@ mod types; #[ink::contract] pub mod contract { - use crate::{errors::ShielderError, merkle::MerkleTree, traits::psp22::PSP22, types::Set}; + use crate::{errors::ShielderError, merkle::MerkleTree, traits::psp22::PSP22Error, types::Set}; + use ink::env::call::{build_call, ExecutionInput, Selector}; + use ink::env::DefaultEnvironment; use mocked_zk::{ops::OpPub, relations::ZkProof, Scalar}; pub const MERKLE_TREE_DEPTH: usize = mocked_zk::MERKLE_TREE_DEPTH; @@ -76,23 +78,39 @@ pub mod contract { amount, token, user, - } => { - let mut psp22: ink::contract_ref!(PSP22) = AccountId::from(token.bytes).into(); - psp22.transfer_from( - AccountId::from(user.bytes), - self.env().account_id(), - amount, - [].to_vec(), - )?; - } + } => build_call::() + .call(AccountId::from(token.bytes)) + .call_v1() + .gas_limit(0) + .transferred_value(0) + .exec_input( + ExecutionInput::new(Selector::new(ink::selector_bytes!( + "PSP22::transfer_from" + ))) + .push_arg(AccountId::from(user.bytes)) + .push_arg(self.env().account_id()) + .push_arg(amount) + .push_arg([].to_vec() as ink::prelude::vec::Vec), + ) + .returns::>() + .invoke()?, OpPub::Withdraw { amount, token, user, - } => { - let mut psp22: ink::contract_ref!(PSP22) = AccountId::from(token.bytes).into(); - psp22.transfer(AccountId::from(user.bytes), amount, [].to_vec())?; - } + } => build_call::() + .call(AccountId::from(token.bytes)) + .call_v1() + .gas_limit(0) + .transferred_value(0) + .exec_input( + ExecutionInput::new(Selector::new(ink::selector_bytes!("PSP22::transfer"))) + .push_arg(AccountId::from(user.bytes)) + .push_arg(amount) + .push_arg([].to_vec() as ink::prelude::vec::Vec), + ) + .returns::>() + .invoke()?, }; Ok(()) }