Registry¶
Overview¶
Registry is a flexible key-value storage contract supporting multiple data types. It provides a generic storage mechanism with type conversion utilities and ordered key tracking.
- Kind: Contract
- License: Sharia
- Solidity: ^0.8.21
- Source:
lib/registry.sol
Inheritance Chain (C3 Linearized)¶
- self — Registry
- MultiOwnable
Immediate Parents¶
What This Means For Players¶
Plain English Summary: Registry is a general-purpose database that can store any type of data. It's like a universal key-value storage locker where you can save information by name (key) and retrieve it later. The game uses it for various internal bookkeeping.
Real-World Analogy: Think of Registry like a safe deposit box facility at a bank. Each box has a unique number (key), and you can store whatever you want inside (value). You can check if a box exists, count how many boxes are used, and retrieve contents by box number.
How It Affects Your Gameplay: - System storage - The game uses registries to store internal data - No overwrites - Once data is stored, it can only be removed (not changed) - Type flexible - Can store strings, numbers, or addresses with the same interface
State Variables¶
| Variable | Type | Visibility | Mutability | Initial Value | NatSpec |
|---|---|---|---|---|---|
_values |
mapping(bytes => bytes) |
private | mutable | `` | |
_inserted |
mapping(bytes => bool) |
private | mutable | `` | |
_indexOf |
mapping(bytes => uint256) |
private | mutable | `` | |
_keys |
bytes[] |
private | mutable | `` |
Constructor¶
constructor¶
- Modifiers:
MultiOwnable(msg.sender)
Functions¶
External & Public¶
Get¶
- Visibility: public
- State Mutability: view
- Parameters: bytes memory key
- Returns: bytes memory
Get¶
- Visibility: public
- State Mutability: view
- Parameters: uint256 idx
- Returns: bytes memory
Inserted¶
- Visibility: public
- State Mutability: view
- Parameters: bytes memory what
- Returns: bool
Inserted¶
- Visibility: public
- State Mutability: view
- Parameters: string memory what
- Returns: bool
Uint64ToBytes¶
- Visibility: public
- State Mutability: pure
- Parameters: uint64 what
- Returns: bytes memory _w
Inserted¶
- Visibility: public
- State Mutability: view
- Parameters: uint64 what
- Returns: bool
Uint256ToBytes¶
- Visibility: public
- State Mutability: pure
- Parameters: uint256 what
- Returns: bytes memory _w
Inserted¶
- Visibility: public
- State Mutability: view
- Parameters: uint256 what
- Returns: bool
AddressToBytes¶
- Visibility: public
- State Mutability: pure
- Parameters: address what
- Returns: bytes memory _w
Inserted¶
- Visibility: public
- State Mutability: view
- Parameters: address what
- Returns: bool
Count¶
- Visibility: public
- State Mutability: view
- Returns: uint256
GetHashByIndex¶
- Visibility: public
- State Mutability: view
- Parameters: uint256 index
- Returns: bytes memory
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: bytes memory key, bytes memory value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: string memory _key, bytes memory value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: string memory _key, string memory value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: string memory _key, uint64 value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: string memory _key, uint256 value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: string memory _key, address value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: uint64 _key, bytes memory value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: uint64 _key, string memory value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: uint64 _key, uint64 value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: uint64 _key, uint256 value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: uint64 _key, address value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: uint256 _key, bytes memory value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: uint256 _key, string memory value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: uint256 _key, uint64 value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: uint256 _key, uint256 value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: uint256 _key, address value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: address _key, bytes memory value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: address _key, string memory value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: address _key, uint64 value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: address _key, uint256 value
Register¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: address _key, address value
Remove¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: bytes memory key
Remove¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: string memory _key
Remove¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: uint64 _key
Remove¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: uint256 _key
Remove¶
- Visibility: public
- Modifiers:
onlyOwners - Parameters: address _key
Inherited Members¶
This contract inherits the members below from its parents. See each parent's dedicated MD for full signatures, NatSpec, and semantics.
From MultiOwnable¶
External & Public Functions
| Function | Signature | State Mutability |
|---|---|---|
owner |
function owner() external view virtual returns (address) |
view |
renounceOwnership |
function renounceOwnership(address toRemove) public virtual onlyOwners |
nonpayable |
addOwner |
function addOwner(address newOwner) public virtual onlyOwners |
nonpayable |
Internal Functions
| Function | Signature |
|---|---|
_checkOwner |
function _checkOwner() internal view virtual |
_changeOwnership |
function _changeOwnership(address cOwner, bool cState) internal virtual |
Events
| Event | Parameters |
|---|---|
OwnershipUpdate |
address indexed newOwner, bool indexed state |
Errors
| Error | Parameters |
|---|---|
OwnableUnauthorizedAccount |
address origin, address account, address what |
OwnableInvalidOwner |
address origin, address owner, address what |
Modifiers
| Modifier | Parameters |
|---|---|
onlyOwners |
(none) |
Utility Functions¶
Uint64ToBytes¶
- Description: Converts uint64 to 8-byte representation - In Plain English: Prepare a 64-bit number for storage by converting it to the registry's internal format. Required when storing Soul IDs or other numeric identifiers that need to be looked up later.Uint256ToBytes¶
- Description: Converts uint256 to 32-byte representation - In Plain English: Prepare a large number (like token amounts or Waat positions) for storage by converting it to the registry's internal format.AddressToBytes¶
- Description: Converts address to 20-byte representation - In Plain English: Prepare a contract or wallet address for storage by converting it to the registry's internal format. Useful when indexing data by who owns it or where it came from.Contract Interactions¶
Depends On¶
- MultiOwnable - Access control
Depended On By¶
- Any contract needing generic storage
Special Mechanisms¶
No Overwrites¶
Register only adds new keys - it won't overwrite existing values:
if(!_inserted[key]) {
_inserted[key] = true;
_indexOf[key] = _keys.length;
_values[key] = value;
_keys.push(key);
}
Efficient Removal¶
Remove uses swap-and-pop pattern to maintain array without gaps:
bytes memory lastKey = _keys[_keys.length - 1];
_indexOf[lastKey] = index;
_keys[index] = lastKey;
_keys.pop();
Type Agnostic Storage¶
Everything is stored as bytes internally. Type-specific overloads handle conversion: - strings → bytes directly - uint64 → 8 bytes (little-endian) - uint256 → 32 bytes (little-endian) - address → 20 bytes
Usage Pattern¶
Registry registry = new Registry();
// Store values
registry.Register("myKey", "myValue");
registry.Register("userId", uint64(12345));
registry.Register(someAddress, "Alice");
// Check existence
bool exists = registry.Inserted("myKey");
// Retrieve
bytes memory value = registry.Get("myKey");
// Iterate
uint256 count = registry.Count();
for(uint256 i = 0; i < count; i++) {
bytes memory key = registry.GetHashByIndex(i);
bytes memory val = registry.Get(i);
}
// Remove
registry.Remove("myKey");
Gas Considerations¶
- Insert: O(1) plus mapping writes
- Get: O(1)
- Remove: O(1) due to swap-and-pop
- Count: O(1)
- Enumeration: O(n)
Contract Verification¶
| Property | Value |
|---|---|
| Keccak256 Hash | 0xcb6c1fa88f25cc768a872653807808641d3e699291a176cdf5b1586ee06ff665 |
| Source URL | https://raw.githubusercontent.com/busytoby/atropa_pulsechain/main/solidity/dysnomia/lib/registry.sol |
| Hash Generated | 2026-04-17T20:48:17Z |