make library methods internal to save extra delegate calls

This commit is contained in:
perissology 2018-01-18 20:17:17 -08:00
parent 80b8ffc2ef
commit 674397cc80
5 changed files with 20 additions and 65 deletions

View File

@ -6,7 +6,7 @@ library EternallyPersistentLib {
// UInt
function stgObjectGetUInt(EternalStorage _storage, string class, uint id, string fieldName) public view returns (uint) {
function stgObjectGetUInt(EternalStorage _storage, string class, uint id, string fieldName) internal view returns (uint) {
bytes32 record = keccak256(class, id, fieldName);
return _storage.getUIntValue(record);
}
@ -18,7 +18,7 @@ library EternallyPersistentLib {
// Boolean
function stgObjectGetBoolean(EternalStorage _storage, string class, uint id, string fieldName) public view returns (bool) {
function stgObjectGetBoolean(EternalStorage _storage, string class, uint id, string fieldName) internal view returns (bool) {
bytes32 record = keccak256(class, id, fieldName);
return _storage.getBooleanValue(record);
}
@ -88,7 +88,7 @@ library EternallyPersistentLib {
// address
function stgObjectGetAddress(EternalStorage _storage, string class, uint id, string fieldName) public view returns (address) {
function stgObjectGetAddress(EternalStorage _storage, string class, uint id, string fieldName) internal view returns (address) {
bytes32 record = keccak256(class, id, fieldName);
return _storage.getAddressValue(record);
}
@ -100,7 +100,7 @@ library EternallyPersistentLib {
// bytes32
function stgObjectGetBytes32(EternalStorage _storage, string class, uint id, string fieldName) public view returns (bytes32) {
function stgObjectGetBytes32(EternalStorage _storage, string class, uint id, string fieldName) internal view returns (bytes32) {
bytes32 record = keccak256(class, id, fieldName);
return _storage.getBytes32Value(record);
}
@ -153,11 +153,11 @@ library EternallyPersistentLib {
// _storage.setUIntValue(keccak256(idArray, idItem, "_idx"), 0);
// }
function stgCollectionLength(EternalStorage _storage, bytes32 idArray) public view returns (uint) {
function stgCollectionLength(EternalStorage _storage, bytes32 idArray) internal view returns (uint) {
return _storage.getUIntValue(keccak256(idArray, "length"));
}
function stgCollectionIdFromIdx(EternalStorage _storage, bytes32 idArray, uint idx) public view returns (bytes32) {
function stgCollectionIdFromIdx(EternalStorage _storage, bytes32 idArray, uint idx) internal view returns (bytes32) {
return _storage.getBytes32Value(keccak256(idArray, idx));
}

View File

@ -46,7 +46,6 @@ contract LiquidPledging is LiquidPledgingBase {
{
}
event Name(string name);
/// @notice This is how value enters the system and how pledges are created;
/// the ether is sent to the vault, an pledge for the Giver is created (or
/// found), the amount of ETH donated in wei is added to the `amount` in
@ -67,11 +66,6 @@ contract LiquidPledging is LiquidPledgingBase {
PledgeAdmins.PledgeAdminType adminType = _storage.getAdminType(idGiver);
require(adminType == PledgeAdmins.PledgeAdminType.Giver);
Gas(msg.gas);
_storage.getAdmin(idGiver);
Gas(msg.gas);
return;
uint amount = msg.value;
require(amount > 0);
vault.transfer(amount); // Sends the `msg.value` (in wei) to the `vault`

View File

@ -409,11 +409,7 @@ contract LiquidPledgingBase is Escapable {
/// @notice A check to see if the msg.sender is the owner or the
/// plugin contract for a specific Admin
/// @param m The Admin being checked
function checkAdminOwner(PledgeAdmins.PledgeAdmin m) internal constant {
require((msg.sender == m.addr) || (msg.sender == address(m.plugin)));
}
/// @param idAdmin The id of the admin being checked
function checkAdminOwner(uint idAdmin) internal constant {
require((msg.sender == _storage.getAdminPlugin(idAdmin)) || (msg.sender == _storage.getAdminAddr(idAdmin)));
}

View File

@ -30,16 +30,17 @@ contract LiquidPledgingMock is LiquidPledging {
/// instance and sets the mocked time to the current blocktime.
/// @param _vault The vault where ETH backing this pledge is stored
function LiquidPledgingMock(
address _storage,
address _vault,
address _escapeHatchCaller,
address _escapeHatchDestination
) LiquidPledging(_vault, _escapeHatchCaller, _escapeHatchDestination) {
) LiquidPledging(_storage, _vault, _escapeHatchCaller, _escapeHatchDestination) {
mock_time = now;
}
/// @dev `getTime` is a basic getter function for
/// the mock_time parameter
function getTime() internal returns (uint) {
function getTime() internal view returns (uint) {
return mock_time;
}

View File

@ -1,4 +1,4 @@
pragma solidity ^0.4.17;
pragma solidity ^0.4.18;
import "./ILiquidPledgingPlugin.sol";
import "./EternallyPersistentLib.sol";
@ -15,33 +15,6 @@ library PledgeAdmins {
enum PledgeAdminType { Giver, Delegate, Project }
/// @dev This struct defines the details of a `PledgeAdmin` which are
/// commonly referenced by their index in the `admins` array
/// and can own pledges and act as delegates
struct PledgeAdmin {
PledgeAdminType adminType; // Giver, Delegate or Project
address addr; // Account or contract address for admin
string name;
string url; // Can be IPFS hash
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
uint64 parentProject; // Only for projects
bool canceled; //Always false except for canceled projects
/// @dev if the plugin is 0x0 then nothing happens, if its an address
// than that smart contract is called when appropriate
ILiquidPledgingPlugin plugin;
}
// PledgeAdmins[] admins;
// function PledgeAdmins(address _storage) EternallyPersistent(_storage) public {
// function setStorage(address _storage) internal {
// require(address(adminStorage == 0x0));
// adminStorage = EternallyPersistent(_storage);
// TODO maybe make an init method?
// admins.length = 1; // we reserve the 0 admin
// }
/// @notice Creates a Giver Admin with the `msg.sender` as the Admin address
/// @param name The name used to identify the Giver
/// @param url The link to the Giver's profile often an IPFS hash
@ -57,13 +30,6 @@ library PledgeAdmins {
uint commitTime,
ILiquidPledgingPlugin plugin
) internal returns (uint idGiver) {
// bytes32 idGuardian = bytes32(addrGuardian);
//
// if (guardian_exists(addrGuardian)) {
// _storage.stgObjectSetString( "Guardian", idGuardian, "name", name);
// return;
// }
idGiver = _storage.stgCollectionAddItem(admins);//, idGiver);
// Save the fields
@ -260,7 +226,7 @@ library PledgeAdmins {
/// @param projectId The Admin id number used to specify the Project
/// @return True if the Project has been canceled
function isProjectCanceled(EternalStorage _storage, uint projectId)
public constant returns (bool)
internal constant returns (bool)
{
require(pledgeAdminsCount(_storage) >= projectId);
@ -281,9 +247,7 @@ library PledgeAdmins {
/// @notice A constant getter used to check how many total Admins exist
/// @return The total number of admins (Givers, Delegates and Projects) .
//TODO I think using 'size' in both Pledges lib & PledgeAdmins lib will cause a conflict since they use the same storage contract
// function size(EternalStorage _storage) constant returns(uint) {
function pledgeAdminsCount(EternalStorage _storage) public constant returns(uint) {
function pledgeAdminsCount(EternalStorage _storage) internal constant returns(uint) {
return _storage.stgCollectionLength(admins);// - 1;
}
@ -331,7 +295,7 @@ library PledgeAdmins {
/// using a recursive loop
/// @param idProject The id of the Project being queried
/// @return The level of authority a specific Project has
function getProjectLevel(EternalStorage _storage, uint idProject) public returns(uint) {
function getProjectLevel(EternalStorage _storage, uint idProject) internal returns(uint) {
assert(getAdminType(_storage, idProject) == PledgeAdminType.Project);
uint parentProject = getAdminParentProject(_storage, idProject);
if (parentProject == 0) return(1);
@ -349,7 +313,7 @@ library PledgeAdmins {
function getAdminType(
EternalStorage _storage,
uint idAdmin
) public view returns (PledgeAdminType)
) internal view returns (PledgeAdminType)
{
return PledgeAdminType(_storage.stgObjectGetUInt(class, idAdmin, "adminType"));
}
@ -358,7 +322,7 @@ library PledgeAdmins {
function getAdminAddr(
EternalStorage _storage,
uint idAdmin
) public view returns (address)
) internal view returns (address)
{
return _storage.stgObjectGetAddress(class, idAdmin, "addr");
}
@ -376,7 +340,7 @@ library PledgeAdmins {
function getAdminParentProject(
EternalStorage _storage,
uint idAdmin
) public view returns (uint)
) internal view returns (uint)
{
return _storage.stgObjectGetUInt(class, idAdmin, "parentProject");
}
@ -385,7 +349,7 @@ library PledgeAdmins {
function getAdminCanceled(
EternalStorage _storage,
uint idAdmin
) public view returns (bool)
) internal view returns (bool)
{
return _storage.stgObjectGetBoolean(class, idAdmin, "canceled");
}
@ -394,7 +358,7 @@ library PledgeAdmins {
function getAdminPlugin(
EternalStorage _storage,
uint idAdmin
) public view returns (address)
) internal view returns (address)
{
return _storage.stgObjectGetAddress(class, idAdmin, "plugin");
}
@ -403,7 +367,7 @@ library PledgeAdmins {
function getAdminCommitTime(
EternalStorage _storage,
uint idAdmin
) public view returns (uint)
) internal view returns (uint)
{
return _storage.stgObjectGetUInt(class, idAdmin, "commitTime");
}