Skip to content

Commit

Permalink
patch implementation of activation to team
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Feb 21, 2022
1 parent 7dd61b6 commit 12aa63f
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions language/diem-framework/modules/0L/Teams.move
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module Teams {
// a member states his team's preference.
// the member only actually joins a team for the purposes of calculating rewards
// when they do enough mining in a period
public fun join_team(sender: &signer, new_captain: address) acquires Member, Team {
public fun join_team(sender: &signer, new_captain: address) acquires Member, Team, AllTeams {
let addr = Signer::address_of(sender);
// needs to check if this is a slow wallet.
// ask user to resubmit if not a slow wallet, so they are explicitly setting it, no surprises, no tears.
Expand All @@ -117,13 +117,21 @@ module Teams {
if (exists<Member>(addr)) {
let member_state = borrow_global_mut<Member>(addr);
let old_captain = member_state.captain_address;
maybe_switch_team(&addr, &new_captain, &old_captain);

// remove miner from old team list
let old_team = borrow_global_mut<Team>(*&old_captain);
let (found, i) = Vector::index_of<address>(&old_team.members, &addr);
if (found) {
Vector::remove(&mut old_team.members, i);
};

// update the membership list of the former captain
member_state.captain_address = new_captain;

// if the user has enough proofs he can be activated to the team list
maybe_activate_member_to_team(sender)

// TODO: Do we need to reset mining_above_threshold if they are switching?
// TODO: Do we nesed to reset mining_above_threshold if they are switching?
} else { // first time joining a Team.
move_to<Member>(sender, Member {
captain_address: new_captain,
Expand All @@ -132,23 +140,6 @@ module Teams {
};
}

fun maybe_switch_team(miner_addr: &address, new_captain: &address, old_captain: &address) acquires Team {

// search for member, and drop
let old_team = borrow_global_mut<Team>(*old_captain);
let (found, i) = Vector::index_of<address>(&old_team.members, miner_addr);
if (found) {
Vector::remove(&mut old_team.members, i);
};

// join new team
let new_team = borrow_global_mut<Team>(*new_captain);
let (found, _) = Vector::index_of<address>(&new_team.members, miner_addr);
if (!found) {
Vector::push_back<address>(&mut new_team.members, *miner_addr);
};
}

// triggered on Epoch B each time the miner submits a new proof.
// as the epoch progresses and a miner's epoch proof count is above the threshold
// then assign the member to the team's list for payment at the end of the epoch.
Expand Down

0 comments on commit 12aa63f

Please sign in to comment.