From 3a34992ded3499b0b762d2b6928f5f90d2dfe4f8 Mon Sep 17 00:00:00 2001 From: PICKQUE <925537712@qq.com> Date: Mon, 27 May 2024 14:51:31 +0800 Subject: [PATCH] some bug --- contract-rs/src/donation.rs | 8 +++++--- contract-rs/src/lib.rs | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/contract-rs/src/donation.rs b/contract-rs/src/donation.rs index d0cd5ef..b5725c8 100644 --- a/contract-rs/src/donation.rs +++ b/contract-rs/src/donation.rs @@ -31,6 +31,7 @@ impl Contract { let mut donated_so_far: NearToken = self .donations .get(&donor) + .cloned() .unwrap_or(NearToken::from_near(0)); let to_transfer = if donated_so_far.is_zero() { @@ -44,7 +45,7 @@ impl Contract { // Persist in storage the amount donated so far donated_so_far = donated_so_far.saturating_add(donation_amount); - self.donations.insert(&donor, &donated_so_far); + self.donations.insert(donor.clone(), donated_so_far); log!( "Thank you {} for donating {}! You donated a total of {}", @@ -64,6 +65,7 @@ impl Contract { let amount = self .donations .get(&account_id) + .cloned() .unwrap_or(NearToken::from_near(0)) .as_yoctonear(); @@ -75,7 +77,7 @@ impl Contract { // Public Method - get total number of donors pub fn number_of_donors(&self) -> U64 { - U64::from(self.donations.len()) + U64::from(self.donations.len() as u64) } // Public Method - paginate through all donations on the contract @@ -88,7 +90,7 @@ impl Contract { .skip(start as usize) .take(limit.unwrap_or(10) as usize) .map(|(account_id, total_amount)| Donation { - account_id, + account_id: account_id.clone(), total_amount: U128::from(total_amount.as_yoctonear()), }) .collect() diff --git a/contract-rs/src/lib.rs b/contract-rs/src/lib.rs index ac4fd86..9078613 100644 --- a/contract-rs/src/lib.rs +++ b/contract-rs/src/lib.rs @@ -1,5 +1,5 @@ // Find all our documentation at https://docs.near.org -use near_sdk::collections::UnorderedMap; +use near_sdk::store::UnorderedMap; use near_sdk::{near, AccountId, NearToken, PanicOnDefault}; mod donation; @@ -47,7 +47,7 @@ mod tests { const ONE_NEAR: NearToken = NearToken::from_near(1); #[test] - fn initializes() { + fn initalizes() { let contract = Contract::init(BENEFICIARY.parse().unwrap()); assert_eq!( contract.beneficiary,