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

46 add contributors to the concert account #47

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions anchor/programs/concert-x/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub mod concert_x {
concert.ticket_price = ticket_price;
concert.start_date = start_date;
concert.end_date = end_date;
concert.status = 0;
concert.status = 0;
Ok(())
}

Expand Down Expand Up @@ -72,6 +72,7 @@ pub mod concert_x {

//Update the current amount
ctx.accounts.concert.current_amount += amount;
ctx.accounts.concert.contributors.push(*ctx.accounts.backer.key);
Copy link
Preview

Copilot AI Dec 18, 2024

Choose a reason for hiding this comment

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

This line may cause a 'contributor' to be added multiple times if they contribute more than once. Consider checking if the contributor already exists in the list before adding.

Suggested change
ctx.accounts.concert.contributors.push(*ctx.accounts.backer.key);
if !ctx.accounts.concert.contributors.contains(&ctx.accounts.backer.key()) { ctx.accounts.concert.contributors.push(*ctx.accounts.backer.key()); }

Copilot is powered by AI, so mistakes are possible. Review output carefully before use.

Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

Ok(())
}
Expand Down Expand Up @@ -146,7 +147,10 @@ pub struct Concert {
/// Unix timestamps when the campaign ends
pub end_date: i64,
/// 0 = active, 1 = completed, 2 = cancelled
pub status: u8,
pub status: u8,
/// Concert contributors
#[max_len(100)]
pub contributors: Vec<Pubkey>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to make this a vec of a map with {Pubkey: contribution amount} key:value pairs? Since the logic currently allows people to donate any amount above the ticket price. We can also change the logic easily so that they can only contribute the price of the ticket and nothing above it. What do you think?

}

/// Size of the account discriminator
Expand Down
1 change: 1 addition & 0 deletions anchor/tests/concert-x.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe("concert-x", () => {

const updatedConcertAccount = await program.account.concert.fetch(concertXPda);
expect(updatedConcertAccount.currentAmount.toNumber()).to.equal(contributionAmount);
expect(updatedConcertAccount.contributors.length).greaterThan(0);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we could check that contributors Pubkey is in the vec instead? Something like copilot suggests above:
ctx.accounts.concert.contributors.contains(&ctx.accounts.backer.key())




Expand Down