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

Feature claim and withdraw #45

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

marco-sundsk
Copy link
Contributor

Add two interfaces to support claim and withdraw in one TX:

  • claim_and_withdraw_by_farm(&mut self, farm_id: FarmId, withdraw_all_tokens: bool)
    If withdraw_all_tokens is true, all reward tokens will be withdrew to user's wallet. Otherwise, only reward token of that farm would be withdrew.
  • claim_and_withdraw_by_seed(&mut self, seed_id: SeedId)
    This interface would withdraw all reward tokens into user's wallet.

ref-farming/Cargo.toml Outdated Show resolved Hide resolved
ref-farming/src/actions_of_reward.rs Outdated Show resolved Hide resolved
ref-farming/src/actions_of_reward.rs Outdated Show resolved Hide resolved
ref-farming/src/farmer.rs Outdated Show resolved Hide resolved
Comment on lines 168 to 174
let tokens = {
if let Some(token) = token {
vec![token]
vec![token.clone()]
} else {
view_farmer.get_ref().rewards.keys().collect::<Vec<_>>()
view_farmer.get_ref().rewards.keys().map(|x| x.clone()).collect::<Vec<_>>()
}
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Why clone it, if you still borrowing it below? Is it because of the immutable/mutable burrow later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I use it mutable later. It's like to get an independent snapshot of all reward tokens into tokens.

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.

2 participants