mirror of
https://github.com/status-im/liquid-funding.git
synced 2025-01-24 18:29:12 +00:00
bit of cleanup
This commit is contained in:
parent
544eee3508
commit
a5651f2186
@ -22,74 +22,67 @@ contract EternalStorage is Escapable {
|
|||||||
return UIntStorage[record];
|
return UIntStorage[record];
|
||||||
}
|
}
|
||||||
|
|
||||||
function setUIntValue(bytes32 record, uint value) public onlyOwner
|
function setUIntValue(bytes32 record, uint value) public onlyOwner {
|
||||||
{
|
|
||||||
UIntStorage[record] = value;
|
UIntStorage[record] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Int Storage
|
/// Int Storage
|
||||||
|
|
||||||
function getIntValue(bytes32 record) public view returns (int){
|
function getIntValue(bytes32 record) public view returns (int) {
|
||||||
return IntStorage[record];
|
return IntStorage[record];
|
||||||
}
|
}
|
||||||
|
|
||||||
function setIntValue(bytes32 record, int value) public onlyOwner
|
function setIntValue(bytes32 record, int value) public onlyOwner {
|
||||||
{
|
|
||||||
IntStorage[record] = value;
|
IntStorage[record] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Address Storage
|
/// Address Storage
|
||||||
|
|
||||||
function getAddressValue(bytes32 record) public view returns (address){
|
function getAddressValue(bytes32 record) public view returns (address) {
|
||||||
return AddressStorage[record];
|
return AddressStorage[record];
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAddressValue(bytes32 record, address value) public onlyOwner
|
function setAddressValue(bytes32 record, address value) public onlyOwner {
|
||||||
{
|
|
||||||
AddressStorage[record] = value;
|
AddressStorage[record] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// String Storage
|
/// String Storage
|
||||||
|
|
||||||
function getStringValue(bytes32 record) public view returns (string){
|
function getStringValue(bytes32 record) public view returns (string) {
|
||||||
return StringStorage[record];
|
return StringStorage[record];
|
||||||
}
|
}
|
||||||
|
|
||||||
function setStringValue(bytes32 record, string value) public onlyOwner
|
function setStringValue(bytes32 record, string value) public onlyOwner {
|
||||||
{
|
|
||||||
StringStorage[record] = value;
|
StringStorage[record] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bytes Storage
|
/// Bytes Storage
|
||||||
|
|
||||||
function getBytesValue(bytes32 record) public view returns (bytes){
|
function getBytesValue(bytes32 record) public view returns (bytes) {
|
||||||
return BytesStorage[record];
|
return BytesStorage[record];
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBytesValue(bytes32 record, bytes value) public onlyOwner
|
function setBytesValue(bytes32 record, bytes value) public onlyOwner {
|
||||||
{
|
|
||||||
BytesStorage[record] = value;
|
BytesStorage[record] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bytes Storage
|
/// Bytes Storage
|
||||||
|
|
||||||
function getBytes32Value(bytes32 record) public view returns (bytes32){
|
function getBytes32Value(bytes32 record) public view returns (bytes32) {
|
||||||
return Bytes32Storage[record];
|
return Bytes32Storage[record];
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBytes32Value(bytes32 record, bytes32 value) public onlyOwner
|
function setBytes32Value(bytes32 record, bytes32 value) public onlyOwner {
|
||||||
{
|
|
||||||
Bytes32Storage[record] = value;
|
Bytes32Storage[record] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Boolean Storage
|
/// Boolean Storage
|
||||||
|
|
||||||
function getBooleanValue(bytes32 record) public view returns (bool){
|
function getBooleanValue(bytes32 record) public view returns (bool) {
|
||||||
return BooleanStorage[record];
|
return BooleanStorage[record];
|
||||||
}
|
}
|
||||||
|
|
||||||
function setBooleanValue(bytes32 record, bool value) public onlyOwner
|
function setBooleanValue(bytes32 record, bool value) public onlyOwner {
|
||||||
{
|
|
||||||
BooleanStorage[record] = value;
|
BooleanStorage[record] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import "./EternalStorage.sol";
|
|||||||
library EternallyPersistentLib {
|
library EternallyPersistentLib {
|
||||||
|
|
||||||
// UInt
|
// UInt
|
||||||
|
//TODO if we use assembly here, we can save ~ 600 gas / call, due to skipping the extcodesize check that solidity adds.
|
||||||
|
|
||||||
function stgObjectGetUInt(EternalStorage _storage, string class, uint id, string fieldName) internal view returns (uint) {
|
function stgObjectGetUInt(EternalStorage _storage, string class, uint id, string fieldName) internal view returns (uint) {
|
||||||
bytes32 record = keccak256(class, id, fieldName);
|
bytes32 record = keccak256(class, id, fieldName);
|
||||||
@ -32,40 +33,39 @@ library EternallyPersistentLib {
|
|||||||
|
|
||||||
function stgObjectGetString(EternalStorage _storage, string class, uint id, string fieldName) internal view returns (string) {
|
function stgObjectGetString(EternalStorage _storage, string class, uint id, string fieldName) internal view returns (string) {
|
||||||
bytes32 record = keccak256(class, id, fieldName);
|
bytes32 record = keccak256(class, id, fieldName);
|
||||||
bytes4 sig = bytes4(keccak256("getStringValue(bytes32)"));
|
|
||||||
//Function signature
|
//Function signature
|
||||||
address a = address(_storage);
|
bytes4 sig = bytes4(keccak256("getStringValue(bytes32)"));
|
||||||
string memory s;
|
string memory s;
|
||||||
|
|
||||||
assembly {
|
assembly {
|
||||||
let x := mload(0x40) //Find empty storage location using "free memory pointer"
|
let x := mload(0x40) //Find empty storage location using "free memory pointer"
|
||||||
mstore(x, sig) //Place signature at begining of empty storage
|
mstore(x, sig) //Place signature at beginning of empty storage
|
||||||
mstore(add(x, 0x04), record) //Place first argument directly next to signature
|
mstore(add(x, 0x04), record) //Place first argument directly next to signature
|
||||||
|
|
||||||
let success := call(//This is the critical change (Pop the top stack value)
|
let success := call(//This is the critical change (Pop the top stack value)
|
||||||
5000, //5k gas
|
5000, //5k gas
|
||||||
a, //To addr
|
_storage, //To addr
|
||||||
0, //No value
|
0, //No value
|
||||||
x, //Inputs are stored at location x
|
x, //Inputs are stored at location x
|
||||||
0x24, //Inputs are 36 byes long
|
0x24, //Inputs are 36 byes long
|
||||||
x, //Store output over input (saves space)
|
x, //Store output over input (saves space)
|
||||||
0x80) //Outputs are 32 bytes long
|
0x80) //Outputs are 32 bytes long
|
||||||
|
|
||||||
let strL := mload(add(x, 0x20)) // Load the length of the sring
|
let strL := mload(add(x, 0x20)) // Load the length of the string
|
||||||
|
|
||||||
jumpi(ask_more, gt(strL, 64))
|
jumpi(ask_more, gt(strL, 64))
|
||||||
|
|
||||||
mstore(0x40, add(x, add(strL, 0x40)))
|
mstore(0x40, add(x, add(strL, 0x40)))
|
||||||
|
|
||||||
s := add(x, 0x20)
|
s := add(x, 0x20)
|
||||||
// return(x, add(strL, 0x40))
|
|
||||||
ask_more :
|
ask_more :
|
||||||
mstore(x, sig) //Place signature at begining of empty storage
|
mstore(x, sig) //Place signature at beginning of empty storage
|
||||||
mstore(add(x, 0x04), record) //Place first argument directly next to signature
|
mstore(add(x, 0x04), record) //Place first argument directly next to signature
|
||||||
|
|
||||||
success := call(//This is the critical change (Pop the top stack value)
|
success := call(//This is the critical change (Pop the top stack value)
|
||||||
5000, //5k gas
|
5000, //5k gas
|
||||||
a, //To addr
|
_storage, //To addr
|
||||||
0, //No value
|
0, //No value
|
||||||
x, //Inputs are stored at location x
|
x, //Inputs are stored at location x
|
||||||
0x24, //Inputs are 36 byes long
|
0x24, //Inputs are 36 byes long
|
||||||
@ -74,8 +74,6 @@ library EternallyPersistentLib {
|
|||||||
|
|
||||||
mstore(0x40, add(x, add(strL, 0x40)))
|
mstore(0x40, add(x, add(strL, 0x40)))
|
||||||
s := add(x, 0x20)
|
s := add(x, 0x20)
|
||||||
|
|
||||||
// return(x, add(strL, 0x40))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
@ -112,19 +110,9 @@ library EternallyPersistentLib {
|
|||||||
|
|
||||||
// Array
|
// Array
|
||||||
|
|
||||||
// function stgCollectionAddItem(bytes32 idArray, bytes32 idItem) internal returns (uint64) {
|
|
||||||
function stgCollectionAddItem(EternalStorage _storage, bytes32 idArray) internal returns (uint) {
|
function stgCollectionAddItem(EternalStorage _storage, bytes32 idArray) internal returns (uint) {
|
||||||
|
|
||||||
uint length = _storage.getUIntValue(keccak256(idArray, "length"));
|
uint length = _storage.getUIntValue(keccak256(idArray, "length"));
|
||||||
|
|
||||||
|
|
||||||
// Set the position in the array as a field so it can be deleted
|
|
||||||
// _storage.setUIntValue(keccak256(idArray, idItem, "_idx"), length);
|
|
||||||
|
|
||||||
// Add the object to the array
|
|
||||||
// _storage.setBytes32Value(keccak256(idArray, length), idItem);
|
|
||||||
|
|
||||||
|
|
||||||
// Increment the size of the array
|
// Increment the size of the array
|
||||||
length++;
|
length++;
|
||||||
_storage.setUIntValue(keccak256(idArray, "length"), length);
|
_storage.setUIntValue(keccak256(idArray, "length"), length);
|
||||||
@ -132,27 +120,6 @@ library EternallyPersistentLib {
|
|||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// function stgCollectionRemoveItem(EternalStorage _storage, bytes32 idArray, bytes32 idItem) internal {
|
|
||||||
// uint idx = _storage.getUIntValue(keccak256(idArray, idItem, "_idx"));
|
|
||||||
//
|
|
||||||
// uint length = _storage.getUIntValue(keccak256(idArray, "length"));
|
|
||||||
// length --;
|
|
||||||
//
|
|
||||||
// // Move the last element ot the array to this place
|
|
||||||
// bytes32 lastId = _storage.getBytes32Value(keccak256(idArray, length));
|
|
||||||
// _storage.setBytes32Value(keccak256(idArray, idx), lastId);
|
|
||||||
// _storage.setUIntValue(keccak256(idArray, lastId, "_idx"), idx);
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// // Decrement the length
|
|
||||||
// _storage.setUIntValue(keccak256(idArray, "length"), length);
|
|
||||||
//
|
|
||||||
// // Cleanup the last element of the array
|
|
||||||
// _storage.setBytes32Value(keccak256(idArray, length), 0);
|
|
||||||
//
|
|
||||||
// _storage.setUIntValue(keccak256(idArray, idItem, "_idx"), 0);
|
|
||||||
// }
|
|
||||||
|
|
||||||
function stgCollectionLength(EternalStorage _storage, bytes32 idArray) internal view returns (uint) {
|
function stgCollectionLength(EternalStorage _storage, bytes32 idArray) internal view returns (uint) {
|
||||||
return _storage.getUIntValue(keccak256(idArray, "length"));
|
return _storage.getUIntValue(keccak256(idArray, "length"));
|
||||||
}
|
}
|
||||||
@ -161,16 +128,7 @@ library EternallyPersistentLib {
|
|||||||
return _storage.getBytes32Value(keccak256(idArray, idx));
|
return _storage.getBytes32Value(keccak256(idArray, idx));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// bytes32 lastId;
|
|
||||||
|
|
||||||
// function stgGetNewId() internal returns (bytes32) {
|
|
||||||
// lastId = keccak256(lastId, now);
|
|
||||||
// return lastId;
|
|
||||||
// }
|
|
||||||
|
|
||||||
function stgUpgrade(EternalStorage _storage, address newContract) internal {
|
function stgUpgrade(EternalStorage _storage, address newContract) internal {
|
||||||
_storage.changeOwnership(newContract);
|
_storage.changeOwnership(newContract);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user