use defuse::core::Nonce; use defuse_serde_utils::base64::AsBase64; use near_sdk::{AccountId, NearToken}; use serde_json::json; use crate::utils::test_log::TestLog; pub trait GarbageCollectorExt { async fn cleanup_nonces( &self, defuse_contract_id: &AccountId, data: impl IntoIterator)>, ) -> anyhow::Result; } impl GarbageCollectorExt for near_workspaces::Account { async fn cleanup_nonces( &self, defuse_contract_id: &AccountId, data: impl IntoIterator)>, ) -> anyhow::Result { let nonces = data .into_iter() .map(|(acc, nonces)| { let base64_nonces: Vec> = nonces.into_iter().map(AsBase64).collect(); (acc, base64_nonces) }) .collect::>(); let res = self .call(defuse_contract_id, "cleanup_nonces") .deposit(NearToken::from_yoctonear(1)) .args_json(json!({ "nonces": nonces, })) .max_gas() .transact() .await? .into_result() .map(TestLog::from)?; Ok(res) } } impl GarbageCollectorExt for near_workspaces::Contract { async fn cleanup_nonces( &self, defuse_contract_id: &AccountId, data: impl IntoIterator)>, ) -> anyhow::Result { self.as_account() .cleanup_nonces(defuse_contract_id, data) .await } }