Skip to content

Commit

Permalink
change PSP22 calls to builder
Browse files Browse the repository at this point in the history
  • Loading branch information
kroist committed Mar 20, 2024
1 parent 333bc00 commit c3fc7cb
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions shielder/contract/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<DefaultEnvironment>()
.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<u8>),
)
.returns::<Result<(), PSP22Error>>()
.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::<DefaultEnvironment>()
.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<u8>),
)
.returns::<Result<(), PSP22Error>>()
.invoke()?,
};
Ok(())
}
Expand Down

0 comments on commit c3fc7cb

Please sign in to comment.