Skip to content
Open
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
20 changes: 15 additions & 5 deletions contracts/admin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
//! | `1` | `RoleNotGranted` | unused (ABI-stable; revoke now uses `RoleNotHeld`) |
//! | `2` | `RoleNotHeld` | `revoke_role` / `require_role` when the role is missing |
//! | `3` | `UnauthorizedRole` | `require_role_guard` failure (caller not authorized) |
//! | `4` | `InvalidAddress` | operation attempted with the canonical zero address |
//! | `5` | `InvalidRole` | unrecognized role discriminant supplied |
//! | `6` | `AlreadyInitialized` | `init_storage` called on an already-initialized contract |
//! | `7` | `RoleAlreadyGranted` | role has already been granted to the target address |
//!
//! ## Event Emissions
//!
Expand Down Expand Up @@ -156,6 +160,9 @@ pub enum AdminError {
/// The contract has already been initialized; calling `init_storage` again
/// is not allowed.
AlreadyInitialized = 6,
/// The role has already been granted to the target address.
#[allow(dead_code)]
RoleAlreadyGranted = 7,
}

/// Storage keys for the access-control layer.
Expand Down Expand Up @@ -335,7 +342,7 @@ pub fn set_admin(env: &Env, admin: &Address) {
}
env.storage().instance().set(&AdminKey::Admin, admin);
extend_instance_ttl(env);
_grant_role(env, admin, Role::Admin, admin);
_grant_role(env, admin, Role::Admin, admin).ok();
}

/// Migrates the singular admin into the SuperAdmin mapping.
Expand Down Expand Up @@ -407,11 +414,14 @@ pub fn grant_role(env: &Env, caller: &Address, role: Role, address: &Address) {
/// @param address The address to receive the role.
fn _grant_role(env: &Env, admin: &Address, role: Role, address: &Address) {
require_non_zero_address(env, address);
env.storage()
.persistent()
.set(&AdminKey::Role(role, address.clone()), &true);
extend_storage_ttl_for_key(env, &AdminKey::Role(role, address.clone()));
let key = AdminKey::Role(role, address.clone());
if env.storage().persistent().has(&key) {
return Err(AdminError::RoleAlreadyGranted);
}
env.storage().persistent().set(&key, &true);
extend_storage_ttl_for_key(env, &key);
events::emit_role_granted(env, admin, role, address);
Ok(())
}

/// Revokes a role from an address.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
{
"generators": {
"address": 3,
"nonce": 0
},
"auth": [
[],
[],
[
[
"CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4",
{
"function": {
"contract_fn": {
"contract_address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"function_name": "grant_role",
"args": [
{
"vec": [
{
"symbol": "Minter"
}
]
},
{
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M"
}
]
}
},
"sub_invocations": []
}
]
],
[]
],
"ledger": {
"protocol_version": 22,
"sequence_number": 0,
"timestamp": 0,
"network_id": "0000000000000000000000000000000000000000000000000000000000000000",
"base_reserve": 0,
"min_persistent_entry_ttl": 4096,
"min_temp_entry_ttl": 16,
"max_entry_ttl": 6312000,
"ledger_entries": [
[
{
"contract_data": {
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": {
"vec": [
{
"symbol": "Role"
},
{
"vec": [
{
"symbol": "Admin"
}
]
},
{
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4"
}
]
},
"durability": "persistent"
}
},
[
{
"last_modified_ledger_seq": 0,
"data": {
"contract_data": {
"ext": "v0",
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": {
"vec": [
{
"symbol": "Role"
},
{
"vec": [
{
"symbol": "Admin"
}
]
},
{
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4"
}
]
},
"durability": "persistent",
"val": {
"bool": true
}
}
},
"ext": "v0"
},
4095
]
],
[
{
"contract_data": {
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": {
"vec": [
{
"symbol": "Role"
},
{
"vec": [
{
"symbol": "Minter"
}
]
},
{
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M"
}
]
},
"durability": "persistent"
}
},
[
{
"last_modified_ledger_seq": 0,
"data": {
"contract_data": {
"ext": "v0",
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": {
"vec": [
{
"symbol": "Role"
},
{
"vec": [
{
"symbol": "Minter"
}
]
},
{
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHK3M"
}
]
},
"durability": "persistent",
"val": {
"bool": true
}
}
},
"ext": "v0"
},
4095
]
],
[
{
"contract_data": {
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": "ledger_key_contract_instance",
"durability": "persistent"
}
},
[
{
"last_modified_ledger_seq": 0,
"data": {
"contract_data": {
"ext": "v0",
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"key": "ledger_key_contract_instance",
"durability": "persistent",
"val": {
"contract_instance": {
"executable": {
"wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
},
"storage": [
{
"key": {
"vec": [
{
"symbol": "Admin"
}
]
},
"val": {
"address": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4"
}
}
]
}
}
}
},
"ext": "v0"
},
4095
]
],
[
{
"contract_data": {
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4",
"key": {
"ledger_key_nonce": {
"nonce": 801925984706572462
}
},
"durability": "temporary"
}
},
[
{
"last_modified_ledger_seq": 0,
"data": {
"contract_data": {
"ext": "v0",
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFCT4",
"key": {
"ledger_key_nonce": {
"nonce": 801925984706572462
}
},
"durability": "temporary",
"val": "void"
}
},
"ext": "v0"
},
6311999
]
],
[
{
"contract_code": {
"hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
}
},
[
{
"last_modified_ledger_seq": 0,
"data": {
"contract_code": {
"ext": "v0",
"hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"code": ""
}
},
"ext": "v0"
},
4095
]
]
]
},
"events": []
}
Loading
Loading