-
Notifications
You must be signed in to change notification settings - Fork 0
Repository
Repository is used for storing data corresponding to uid/addresses. Both the uid/address and the data field [string] (Policy name) must be specified when querying and modifying data. To facilitate on-chain data consensus, the first byte of the actual data storage is always the data type, and the subsequent bytes are stored as a vector.
Definition
// Repository: Data storage object
struct Repository has key {
id: UID,
description: String,
// Key-value pairs of policy name and rule; used for write permission, description, and type consensus settings for data fields marked by the policy name
policies: sui_table::Table<String, PolicyRule>,
// Data storage related to uid/address; VecMap is a key-value pair of data fields and data content; PolicyRule can be provided for data fields
data: Table<address, VecMap<String, vector<u8>>>,
// Permission table
permission: address,
// 0 (Normal), 1 (Wowok grantee), 2 (Wowok grantor)
type: u8,
// 0 (Relax mode, any data field can be written), 1 (Strict mode, only allows writing to data fields included in policies)
policy_mode: u8,
}
// PolicyRule: Provides write permission, description, and type consensus capabilities for the required data fields
struct PolicyRule has copy, store, drop {
// Rule description
description: String,
// Permission index in the repository permission, determines who has the authority to modify the data fields specified by the policy
permission_index: Option<u64>,
// Value type, used for on-chain data consensus, supported data types (link to...)
value_type: u8,
}
// Maximum length of a data field key
const MAX_KEY_LENGTH: u64 = 128;
// Maximum length of data
const MAX_VALUE_LENGTH: u64 = 204800;
// Maximum number of policies
const MAX_POLICY_COUNT: u64 = 1024;
// TYPE_NORMAL;TYPE_WOWOK_GRANTEE(used for trust transfer, such as proving to be an employee or a title, etc.)
// TYPE_WOWOK_GRANTEE must be generated by wowok's grantor (see the registration of grantor in wowok.md for details)
TYPE_NORMAL : 0
TYPE_WOWOK_GRANTEE : 1
// Supported data types:
View const-value type.md ValueType
Operations
Launch repository (shared object)
create(repository: Repository) : address
Add data (overwrites if data exists). Operation permissions are controlled by policy. type
: data type, raw_value
is the actual data.
add(repository: &mut Repository, id: address, key: String, type: u8, raw_value: vector<u8>, permission: &Permission)
Add data (overwrites if data exists). Operation permissions are controlled by policy. The first byte of value
must conform to the definition of Wowok protocol data types.
add_typed_data(repository: &mut Repository, id: address, key: String, value: vector<u8>, permission: &Permission)
Remove data. Operation permissions are controlled by policy.
remove(repository: &mut Repository, id: address, key: String, permission: &Permission)
Set a new permission. The operation permission must satisfy being the builder of the old permission.
permission_set(repository: &mut Repository, old: &Permission, new: &Permission)
[Permission index: 100] Create a new Repository
new(description: String, policy_mode: u8, permission: &Permission) : Repository
[Permission index: 101] Set Description
description_set(repository: &mut Repository, description: String, permission: &Permission)
[Permission index: 102] Set PolicyMode
policy_mode_set(repository: &mut Repository, policy_mode: u8, permission: &Permission)
[Permission index: 103] Add Policy
policy_add(repository: &mut Repository, policy: String, description: String, permission_index: Option<u64>, value_type: u8, permission: &Permission)
[Permission index: 104] Remove Policy
policy_remove(repository: &mut Repository, policy: String, permission: &Permission)
[Permission index: 105] Set Policy's Description
policy_description_set(repository: &mut Repository, policy: String, description: String, permission: &Permission)
[Permission index: 106] Set and cancel Policy's Permission index (must be greater than 10000). permission_index
: To cancel the permission requirement, use Option::None()
.
policy_permission_set(repository: &mut Repository, policy: String, permission_index: Option<u64>, permission: &Permission)
[Permission index: 107] Add reference
reference_add(repository: &mut Repository, reference: address, permission: &Permission, ctx: &mut TxContext)
[Permission index: 108] Remove reference
reference_remove(repository: &mut Repository, reference: address, permission: &Permission, ctx: &mut TxContext)
reference_removeall(repository: &mut Repository, permission: &Permission, ctx: &mut TxContext)
Operations with passport
new_with_passport(passport:&mut Passport, description:String, policy_mode:u8, permission:&Permission) : Repository
description_set_with_passport(passport:&mut Passport, repository:&mut Repository, description:String, permission:&Permission)
policy_mode_set_with_passport(passport:&mut Passport, repository:&mut Repository, policy_mode:u8, permission:&Permission)
policy_add_with_passport(passport:&mut Passport, repository:&mut Repository, policy:String, description:String, permission_index:Option<u64>, value_type:u8, permission:&Permission)
policy_remove_with_passport(passport:&mut Passport, repository:&mut Repository, policy:String, permission:&Permission)
policy_description_set_with_passport(passport:&mut Passport, repository:&mut Repository, policy:String, description:String, permission:&Permission)
policy_permission_set_with_passport(passport:&mut Passport, repository:&mut Repository, policy:String, permission_index:Option<u64>, permission:&Permission)
reference_add_with_passport(passport:&mut Passport, repository:&mut Repository, reference:address, permission:&Permission, ctx:&mut TxContext)
reference_remove_with_passport(passport:&mut Passport, repository:&mut Repository, reference:address, permission:&Permission, ctx:&mut TxContext)
reference_removeall_with_passport(passport:&mut Passport, repository:&mut Repository, permission:&Permission, ctx:&mut TxContext)
<<<<<<< HEAD
=======
### Queries
Type [u8]
type(repository: &Repository): u8
Whether a policy for the data field is set [bool]; policy: data field
policy_contains(repository: &Repository, policy: String) : bool
The type [u8] specified by the policy for the data field; policy: data field
policy_value_type(repository: &Repository, policy: String) : u8
The permission [Option<u64>] specified by the policy for the data field; policy: data field
policy_permission_get(repository: &Repository, policy: String) : Option
Whether there is corresponding data for the id/address [bool]; id: object address or address
data_contains_id(repository: &Repository, id: address) : bool
Whether there is corresponding data for the id/address and the specified data field [bool]; id: object address or address; key: data field
data_contains_value(repository: &Repository, id: address, key: String) : bool
Query data (including data type) [vector<u8>]; assert if data does not exist. id: object address or address; key: data field
get(repository: &Repository, id: address, key: String): vector
Query data (excluding data type) [vector<u8>]; assert if data does not exist. id: object address or address; key: data field
get_without_type(repository: &Repository, id: address, key: String) : vector
Query data (including data type) [Option<vector<u8>>]; return Option::None() if data does not exist. id: object address or address; key: data field
try_get(repository: &Repository, id: address, key: String) : Option<vector>
Query data (excluding data type) [vector<u8>]; return Option::None() if data does not exist. id: object address or address; key: data field
try_get_without_type(repository: &Repository, id: address, key: String) : Option<vector>
### On-chain query for Guard
[Query: 1] Repository Permission [address]; input: none
[Query: 2] Whether a policy for the data field is set [bool]; input: data field [string]
[Query: 3] Whether a policy and its permission index[u64] for the data field are set [bool]; input: data field [string]
[Query: 4] The permission index[u64] for the data field; input: data field [string]; [Query: 3] must be true
[Query: 5] The type [u8] for the data field; input: data field [string]; [Query: 2] must be true
[Query: 6] Whether there is corresponding data for the address [bool]; input: object id or address [address]
[Query: 7] Whether there is corresponding data for the address and the specified data field [bool]; input: object id or address [address] data field [string]
[Query: 8] Query the address and the specified data field, the corresponding data without type [vector<u8>]; input: object id or address [address] data field [string]; [Query: 7] must be true
[Query: 9] Query the address and the specified data field, the corresponding data with type [vector<u8>]; input: object id or address [address] data field [string]; [Query: 7] must be true
[Query: 10] repository.type [u8]; input: none
[Query: 11] repository.policy_mode [u8]; input: none
>>>>>>> 2217e7070efb353b274f2103c828de5b3f68d1c8
**Errors**
104006: The repository's policy_mode is set to 1, the data name must conform to the policy's definition. 104008: The data name (policy name) is too long. 104010: The data content (value content) is too long. 104012: The policy mode is invalid. 104014: The repository's policies have reached the maximum number allowed.