diff --git a/dist/nft_benefits_vault.wasm b/dist/nft_benefits_vault.wasm index d2f6073..a27f03d 100755 Binary files a/dist/nft_benefits_vault.wasm and b/dist/nft_benefits_vault.wasm differ diff --git a/src/calls.rs b/src/calls.rs index 5727680..1d29f19 100644 --- a/src/calls.rs +++ b/src/calls.rs @@ -216,15 +216,16 @@ impl Contract { if replenish { for replenisher in vault.replenishers().iter() { log!( - "calling replenisher: {}.{}({})", + "calling replenisher: {}.{}({}) with deposit {}", replenisher.contract_id(), replenisher.callback(), - replenisher.args() + replenisher.args(), + replenisher.deposit(), ); let replenish = Promise::new(replenisher.contract_id().clone()).function_call( replenisher.callback().to_owned(), replenisher.args().as_bytes().to_vec(), - 0, + replenisher.deposit(), Gas::ONE_TERA * 100, ); promise = Some(if let Some(p) = promise { @@ -251,6 +252,7 @@ impl Contract { nft_id: TokenId, callback: String, args: String, + deposit: U128, ) { assert_one_yocto(); @@ -261,8 +263,13 @@ impl Contract { let contract_id = env::predecessor_account_id(); - log!("add replenisher: [{}].{}(args)", contract_id, callback); - vault.add_replenisher(contract_id, callback, args); + log!( + "add replenisher: [{}].{}(args) with deposit: {}", + contract_id, + callback, + deposit.0 + ); + vault.add_replenisher(contract_id, callback, args, deposit); self.vaults.insert(&nft_id, &vault); } diff --git a/src/interface/ft_receiver.rs b/src/interface/ft_receiver.rs index e61c471..9593a0b 100644 --- a/src/interface/ft_receiver.rs +++ b/src/interface/ft_receiver.rs @@ -30,7 +30,12 @@ impl FungibleTokenReceiver for Contract { // so predecessor account IS the FT contract. let fungible_token = env::predecessor_account_id(); - log!("received {} tokens from {}", amount, sender_id); + log!( + "received {} tokens from {}, msg: {}", + amount, + sender_id, + msg + ); let request = match Request::from_json(&msg) { Ok(req) => req, diff --git a/src/vault.rs b/src/vault.rs index 350cdc8..79d11ec 100644 --- a/src/vault.rs +++ b/src/vault.rs @@ -2,6 +2,7 @@ use near_sdk::{ borsh::{self, BorshDeserialize, BorshSerialize}, collections::{UnorderedMap, UnorderedSet}, env::sha256, + json_types::U128, require, serde::{Deserialize, Serialize}, AccountId, @@ -17,12 +18,13 @@ pub struct Vault { replenishers: UnorderedSet, } -#[derive(Debug, BorshSerialize, BorshDeserialize, Serialize, Deserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize, Serialize, Deserialize, Clone)] #[serde(crate = "near_sdk::serde")] pub struct Replenisher { contract_id: AccountId, callback: String, args: String, + deposit: U128, } impl Vault { @@ -68,11 +70,18 @@ impl Vault { /// # Panics /// /// Panics if replenisher is already registered. - pub fn add_replenisher(&mut self, contract_id: AccountId, callback: String, args: String) { + pub fn add_replenisher( + &mut self, + contract_id: AccountId, + callback: String, + args: String, + deposit: U128, + ) { let replenisher = Replenisher { contract_id, callback, args, + deposit, }; require!( !self.replenishers.contains(&replenisher), @@ -117,4 +126,9 @@ impl Replenisher { pub fn args(&self) -> &str { self.args.as_ref() } + + /// Returns required deposit for the call. + pub fn deposit(&self) -> u128 { + self.deposit.0 + } }