Skip to content

ERC930 - Eternal Storage Standard #930

Closed
@AugustoL

Description

@AugustoL
EIP: 930
Title: ERC930 Eternal Storage
Author: Augusto Lemble <me@augustolemble.com>
Type: Contract Standard
Category: ERC
Status: Draft
Created: 2018-03-15

Simple Summary

This contract provides the necessary logic to store any type of data in a smart contract using it as a storage.

Abstract

The ES (Eternal Storage) contract is owned by an address that have write permissions. The storage is public, which means everyone has read permissions.
It store the data on mappings, using one mapping per type of variable.
The use of this contract allows the developer to migrate the storage easily to another contract if needed.

// Using contract storage
string myName = "Vitalik"; 

// Using Eternal Storage
s.getString(keccak256("myName")) = "Vitalik";

Motivation

There is some implementations of Eternal Storage contracts already done and being used but there is not some consensus over it. Storage is one of the most important parts of smart contracts development and using this contract will allow developers to use a standardized version of ES and therefore have safer contracts and also use this standard with another that define only certain logic and behavior over a contract, for example: An ERC20 token can use the contract or eternal storage it wont affect the standard since the only thing that changes is the write/read operations used inside the functions.

Specification

EternalStorage

Note The nomenclature used for the functions and variables was tried to be as short as possible, since we don't want to have to use +30 more characters per line to assign an uint.

  • s == storage
  • h == hash
  • v == value

Storage

The storage of the contract is kept in a internal variable, it is also an struct with a set of mappings, one per each variable type.

  struct Storage {
    mapping(bytes32 => bool) _bool;
    mapping(bytes32 => int) _int;
    mapping(bytes32 => uint) _uint;
    mapping(bytes32 => string) _string;
    mapping(bytes32 => address) _address;
    mapping(bytes32 => bytes) _bytes;
  }

  Storage internal s;

Methods

owner

Returns the owner address of the ES.

function owner() constant returns (address owner)

SET methods

Execute a write operation over the storage, it can only be called by the ES
owner. It will write the value v over the boolean value identified with the
hash h.

The function SHOULD revert if the msg.sender is not the owner.

  function setBoolean(bytes32 h, bool v) public onlyOwner {
    s._bool[h] = v;
  }
  function setInt(bytes32 h, int v) public onlyOwner {
    s._int[h] = v;
  }
  function setUint(bytes32 h, uint256 v) public onlyOwner {
    s._uint[h] = v;
  }
  function setAddress(bytes32 h, address v) public onlyOwner {
    s._address[h] = v;
  }
  function setString(bytes32 h, string v) public onlyOwner {
    s._string[h] = v;
  }
  function setBytes(bytes32 h, bytes v) public onlyOwner {
    s._bytes[h] = v;
  }

GET methods

Execute a read operation over the storage. It receives the hash identifier h of the variable stored and it returns the value of it.

function getBoolean(bytes32 h) public view returns (bool){
  return s._bool[h];
}
function getInt(bytes32 h) public view returns (int){
  return s._int[h];
}
function getUint(bytes32 h) public view returns (uint256){
  return s._uint[h];
}
function getAddress(bytes32 h) public view returns (address){
  return s._address[h];
}
function getString(bytes32 h) public view returns (string){
  return s._string[h];
}
function getBytes(bytes32 h) public view returns (bytes){
  return s._bytes[h];
}

Events

OwnershipTransfered

Triggered when the ownership of the contract change.

event OwnershipTransfered(address indexed previousOwner, address indexed newOwner);

Implementations

Revisions

  • 2018/03/15: Initial Draft

Copyright

Copyright and related rights waived via CC0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions