Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] #327 Add Legacy Map to Fund Contract for Donation Tracking #334

Merged
merged 5 commits into from
Jan 23, 2025

Conversation

CollinsC1O
Copy link
Contributor

@CollinsC1O CollinsC1O commented Jan 23, 2025

Description:

This pull request implements donor tracking functionality in the fund contract as requested in issue #327. The implementation introduces a permanent record of donor contributions while maintaining the contract's existing behavior.

Changes Made:

Storage Addition:

Added legacy map for donor addresses and totals

  • The LegacyMap creates an on-chain record that maps donor addresses to their total contributed amounts. When a new donor makes their first contribution, they are automatically initialized with a zero balance.

The update_receive_donation function now:

  • Retrieves the caller's address once and stores it for consistent use
  • Reads the donor's previous total from storage
  • Updates their total by adding the new donation
  • Maintains existing goal-checking logic
  • Emits the donation event with proper donor attribution

Requirements Fulfilled:

  • ✓ Added legacy map to store donator addresses
  • ✓ Track total amount donated by each donor
  • ✓ Update donation records before event emission
  • ✓ Maintain existing contract functionality
  • ✓ Handle both new and existing donors correctly

Current output

  • Evidence that the code compiles successfully:
Screenshot 2025-01-23 at 17 13 07
  • Evidence that code was formatted:
Screenshot 2025-01-23 at 17 08 39
  • Evidence that all test cases passed successfully:
Screenshot 2025-01-23 at 17 14 51 Screenshot 2025-01-23 at 17 15 29

Note:

  • Commented my implementation/changes to have a clear and well explained code
  • 'scarb build' used for compiling the code
  • 'scarb fmt' for formatting the code, to have a clean code structure
  • used scarb version 2.6.5, cairo version 2.6.4, sierra version 1.5.0, snforge version 0.27.0

@CollinsC1O
Copy link
Contributor Author

CollinsC1O commented Jan 23, 2025

Hello @EmmanuelAR, I wanted to confirm if I'm to provide test cases for my implementations considering there is an issue #328 to address creating unit test for legacy map. let me Know if I'm to provide this test case for clarity. Thank you

I will love to get your telegram handle or the projects telegram handle, or any means in which I can reach out to you or any member of the team, that's if its ok

@EmmanuelAR
Copy link
Collaborator

Hey @CollinsC1O, yes the unit test will be work in other issue.

Our discord channel: https://discord.gg/sEpnC6JB2U

tks for the pr, let me check it

@EmmanuelAR
Copy link
Collaborator

Hey @CollinsC1O could you please add the evidence of

scarb build
scarb fmt
scarb test

please :)

@EmmanuelAR
Copy link
Collaborator

Also @CollinsC1O, please check this important note attach to the ticket:

Captura de pantalla 2025-01-23 a la(s) 9 43 16 a  m

@CollinsC1O
Copy link
Contributor Author

ok I will provide all that you require of me

@CollinsC1O
Copy link
Contributor Author

Hello @EmmanuelAR, below are the provided evidences as also included in the description above, updating the comment

  • Evidence that code was formatted:
Screenshot 2025-01-23 at 17 08 39 - Evidence that the code compiles successfully: Screenshot 2025-01-23 at 17 13 07 - Evidence that all test cases passed successfully: Screenshot 2025-01-23 at 17 14 51 Screenshot 2025-01-23 at 17 15 29

src/fund.cairo Outdated
@@ -88,6 +88,7 @@ pub mod Fund {
reason: ByteArray,
up_votes: u32,
voters: LegacyMap::<ContractAddress, u32>,
donator_totals: LegacyMap::<ContractAddress, u256>, // Track total donations per address
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please called the legacy map as: donators
Also remove the comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

src/fund.cairo Outdated
@@ -205,6 +206,12 @@ pub mod Fund {
}
fn update_receive_donation(ref self: ContractState, strks: u256) {
let current_balance = self.get_current_goal_state();
// Get caller address
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

src/fund.cairo Outdated
@@ -205,6 +206,12 @@ pub mod Fund {
}
fn update_receive_donation(ref self: ContractState, strks: u256) {
let current_balance = self.get_current_goal_state();
// Get caller address
let caller: ContractAddress = get_caller_address();
// Read donor's existing total
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

src/fund.cairo Outdated
let caller: ContractAddress = get_caller_address();
// Read donor's existing total
let prev_total = self.donator_totals.read(caller);
// Add current donation to their running total (adding donation)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing all comments

@CollinsC1O
Copy link
Contributor Author

CollinsC1O commented Jan 23, 2025

Hello @EmmanuelAR all requested changes have been observed and implemented. Thanks for your review

Copy link
Collaborator

@EmmanuelAR EmmanuelAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@EmmanuelAR EmmanuelAR merged commit 5ac4435 into undefinedorgcr:dev Jan 23, 2025
@EmmanuelAR EmmanuelAR linked an issue Jan 23, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] Add Legacy Map to Fund Contract
2 participants