Skip to content

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.

Inheritance Chain (C3 Linearized)

  1. selfRegistry
  2. 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

constructor() MultiOwnable(msg.sender)
  • Modifiers: MultiOwnable(msg.sender)

Functions

External & Public

Get

function Get(bytes memory key) public view returns (bytes memory)
  • Visibility: public
  • State Mutability: view
  • Parameters: bytes memory key
  • Returns: bytes memory

Get

function Get(uint256 idx) public view returns (bytes memory)
  • Visibility: public
  • State Mutability: view
  • Parameters: uint256 idx
  • Returns: bytes memory

Inserted

function Inserted(bytes memory what) public view returns (bool)
  • Visibility: public
  • State Mutability: view
  • Parameters: bytes memory what
  • Returns: bool

Inserted

function Inserted(string memory what) public view returns (bool)
  • Visibility: public
  • State Mutability: view
  • Parameters: string memory what
  • Returns: bool

Uint64ToBytes

function Uint64ToBytes(uint64 what) public pure returns (bytes memory _w)
  • Visibility: public
  • State Mutability: pure
  • Parameters: uint64 what
  • Returns: bytes memory _w

Inserted

function Inserted(uint64 what) public view returns (bool)
  • Visibility: public
  • State Mutability: view
  • Parameters: uint64 what
  • Returns: bool

Uint256ToBytes

function Uint256ToBytes(uint256 what) public pure returns (bytes memory _w)
  • Visibility: public
  • State Mutability: pure
  • Parameters: uint256 what
  • Returns: bytes memory _w

Inserted

function Inserted(uint256 what) public view returns (bool)
  • Visibility: public
  • State Mutability: view
  • Parameters: uint256 what
  • Returns: bool

AddressToBytes

function AddressToBytes(address what) public pure returns (bytes memory _w)
  • Visibility: public
  • State Mutability: pure
  • Parameters: address what
  • Returns: bytes memory _w

Inserted

function Inserted(address what) public view returns (bool)
  • Visibility: public
  • State Mutability: view
  • Parameters: address what
  • Returns: bool

Count

function Count() public view returns (uint256)
  • Visibility: public
  • State Mutability: view
  • Returns: uint256

GetHashByIndex

function GetHashByIndex(uint256 index) public view returns (bytes memory)
  • Visibility: public
  • State Mutability: view
  • Parameters: uint256 index
  • Returns: bytes memory

Register

function Register(bytes memory key, bytes memory value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: bytes memory key, bytes memory value

Register

function Register(string memory _key, bytes memory value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: string memory _key, bytes memory value

Register

function Register(string memory _key, string memory value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: string memory _key, string memory value

Register

function Register(string memory _key, uint64 value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: string memory _key, uint64 value

Register

function Register(string memory _key, uint256 value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: string memory _key, uint256 value

Register

function Register(string memory _key, address value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: string memory _key, address value

Register

function Register(uint64 _key, bytes memory value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: uint64 _key, bytes memory value

Register

function Register(uint64 _key, string memory value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: uint64 _key, string memory value

Register

function Register(uint64 _key, uint64 value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: uint64 _key, uint64 value

Register

function Register(uint64 _key, uint256 value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: uint64 _key, uint256 value

Register

function Register(uint64 _key, address value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: uint64 _key, address value

Register

function Register(uint256 _key, bytes memory value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: uint256 _key, bytes memory value

Register

function Register(uint256 _key, string memory value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: uint256 _key, string memory value

Register

function Register(uint256 _key, uint64 value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: uint256 _key, uint64 value

Register

function Register(uint256 _key, uint256 value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: uint256 _key, uint256 value

Register

function Register(uint256 _key, address value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: uint256 _key, address value

Register

function Register(address _key, bytes memory value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: address _key, bytes memory value

Register

function Register(address _key, string memory value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: address _key, string memory value

Register

function Register(address _key, uint64 value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: address _key, uint64 value

Register

function Register(address _key, uint256 value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: address _key, uint256 value

Register

function Register(address _key, address value) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: address _key, address value

Remove

function Remove(bytes memory key) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: bytes memory key

Remove

function Remove(string memory _key) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: string memory _key

Remove

function Remove(uint64 _key) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: uint64 _key

Remove

function Remove(uint256 _key) public onlyOwners
  • Visibility: public
  • Modifiers: onlyOwners
  • Parameters: uint256 _key

Remove

function Remove(address _key) public onlyOwners
  • 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

function Uint64ToBytes(uint64 what) public pure returns (bytes memory)
- 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

function Uint256ToBytes(uint256 what) public pure returns (bytes memory)
- 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

function AddressToBytes(address what) public pure returns (bytes memory)
- 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

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