Skip to content

Commit

Permalink
registry: GovBan flag (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba authored Sep 29, 2023
1 parent 94184b4 commit e780f6a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
2 changes: 2 additions & 0 deletions contracts/registry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Change log entries are to be added to the Unreleased section. Example entry:

### Features

- New `GovBan` flag. Reserved for accounts with a history of misconduct, limiting their governance role while maintaining their voting rights as valued members of the Voting Body.

### Breaking Changes

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion contracts/registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ See the function docs for more complete documentation.

- `admin_flag_accounts(flag: AccountFlag, accounts: Vec<AccountId>, memo: String)` - sets a flag for every account in the `accounts` list, overwriting if needed. Must be called by an authorized flagger.
- `admin_flag_accounts(flag: AccountFlag, accounts: Vec<AccountId>, memo: String)` - removes a flag for every account in the `accounts` list, overwriting if needed. Must be called by an authorized flagger.
Valid account flags are: "Verified", "Blacklisted".
Valid account flags are: "Verified", "Blacklisted", "GovBan".
- `admin_add_sbt_issuer(issuer: AccountId)` - authorizes new issuer to issue SBTs.

## Soul transfer
Expand Down
1 change: 1 addition & 0 deletions contracts/registry/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub(crate) fn emit_iah_flag_accounts(flag: crate::AccountFlag, accounts: Vec<Acc
let event = match flag {
AccountFlag::Blacklisted => "flag_blacklisted",
AccountFlag::Verified => "flag_verified",
AccountFlag::GovBan => "flag_govban",
};
emit_iah_event(EventPayload {
event,
Expand Down
27 changes: 9 additions & 18 deletions contracts/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,13 @@ impl Contract {

pub(crate) fn _transfer_flag(&mut self, from: &AccountId, recipient: &AccountId) {
if let Some(flag_from) = self.flagged.get(from) {
match self.flagged.get(recipient) {
Some(AccountFlag::Verified) => require!(
flag_from != AccountFlag::Blacklisted,
"can't transfer soul from a blacklisted account to a verified account"
),
Some(AccountFlag::Blacklisted) => require!(
flag_from != AccountFlag::Verified,
"can't transfer soul from a verified account to a blacklisted account"
),
None => {
self.flagged.insert(recipient, &flag_from);
}
if let Some(flag_to) = self.flagged.get(recipient) {
require!(
flag_from == flag_to,
"can't transfer soul when there is a flag conflict"
)
} else {
self.flagged.insert(recipient, &flag_from);
}
}
}
Expand Down Expand Up @@ -2966,9 +2961,7 @@ mod tests {
}

#[test]
#[should_panic(
expected = "can't transfer soul from a blacklisted account to a verified account"
)]
#[should_panic(expected = "can't transfer soul when there is a flag conflict")]
fn flagged_soul_transfer() {
let (mut ctx, mut ctr) = setup(&issuer1(), 2 * MINT_DEPOSIT);

Expand Down Expand Up @@ -3005,9 +2998,7 @@ mod tests {
}

#[test]
#[should_panic(
expected = "can't transfer soul from a verified account to a blacklisted account"
)]
#[should_panic(expected = "can't transfer soul when there is a flag conflict")]
fn flagged_soul_transfer2() {
let (mut ctx, mut ctr) = setup(&issuer1(), 2 * MINT_DEPOSIT);

Expand Down
6 changes: 5 additions & 1 deletion contracts/registry/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ pub enum StorageKey {
#[serde(crate = "near_sdk::serde")]
#[cfg_attr(not(target_arch = "wasm32"), derive(Debug))]
pub enum AccountFlag {
/// Account is "blacklisted" when it was marked as a scam or breaking the IAH rules.
/// Account is "blacklisted" when it was marked as a scam or suspectible to be a mnipulated account or not a human.
Blacklisted,
/// Manually verified account.
Verified,
/// Account misbehaved and should be refused to have a significant governance role. However
/// it will be able to vote as a Voting Body member.
GovBan,
}

/// Composition of issuer address and token id used for indexing
Expand Down

0 comments on commit e780f6a

Please sign in to comment.