Manager to Admin refactor
This commit is contained in:
parent
e409e04a85
commit
41154e89d2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -51,13 +51,13 @@ contract LiquidPledgingBase {
|
|||
uint constant MAX_SUBCAMPAIGN_LEVEL = 20;
|
||||
uint constant MAX_INTERCAMPAIGN_LEVEL = 20;
|
||||
|
||||
enum PledgeManagerType { Giver, Delegate, Campaign }
|
||||
enum PledgeAdminType { Giver, Delegate, Campaign }
|
||||
enum PaymentState { NotPaid, Paying, Paid } // TODO name change NotPaid
|
||||
|
||||
/// @dev This struct defines the details of each the PledgeManager, these
|
||||
/// PledgeManagers can own pledges and act as delegates
|
||||
struct PledgeManager { // TODO name change PledgeManager
|
||||
PledgeManagerType managerType; // Giver, Delegate or Campaign
|
||||
/// @dev This struct defines the details of each the PledgeAdmin, these
|
||||
/// PledgeAdmins can own pledges and act as delegates
|
||||
struct PledgeAdmin { // TODO name change PledgeAdmin
|
||||
PledgeAdminType adminType; // Giver, Delegate or Campaign
|
||||
address addr; // account or contract address for admin
|
||||
string name;
|
||||
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
|
||||
|
@ -68,7 +68,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
struct Pledge {
|
||||
uint amount;
|
||||
uint64 owner; // PledgeManager
|
||||
uint64 owner; // PledgeAdmin
|
||||
uint64[] delegationChain; // list of index numbers
|
||||
uint64 proposedCampaign; // TODO change the name only used for when delegates are precommiting to a campaign
|
||||
uint64 commitTime; // When the proposedCampaign will become the owner
|
||||
|
@ -77,7 +77,7 @@ contract LiquidPledgingBase {
|
|||
}
|
||||
|
||||
Pledge[] pledges;
|
||||
PledgeManager[] managers; //The list of pledgeManagers 0 means there is no manager
|
||||
PledgeAdmin[] admins; //The list of pledgeAdmins 0 means there is no admin
|
||||
Vault public vault;
|
||||
|
||||
// this mapping allows you to search for a specific pledge's index number by the hash of that pledge
|
||||
|
@ -101,24 +101,24 @@ contract LiquidPledgingBase {
|
|||
/// @notice The Constructor creates the `LiquidPledgingBase` on the blockchain
|
||||
/// @param _vault Where the ETH is stored that the pledges represent
|
||||
function LiquidPledgingBase(address _vault) {
|
||||
managers.length = 1; // we reserve the 0 manager
|
||||
admins.length = 1; // we reserve the 0 admin
|
||||
pledges.length = 1; // we reserve the 0 pledge
|
||||
vault = Vault(_vault);
|
||||
}
|
||||
|
||||
|
||||
///////
|
||||
// Managers functions
|
||||
// Adminss functions
|
||||
//////
|
||||
|
||||
/// @notice Creates a giver.
|
||||
function addGiver(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idGiver) {
|
||||
|
||||
idGiver = uint64(managers.length);
|
||||
idGiver = uint64(admins.length);
|
||||
|
||||
managers.push(PledgeManager(
|
||||
PledgeManagerType.Giver,
|
||||
admins.push(PledgeAdmin(
|
||||
PledgeAdminType.Giver,
|
||||
msg.sender,
|
||||
name,
|
||||
commitTime,
|
||||
|
@ -138,8 +138,8 @@ contract LiquidPledgingBase {
|
|||
string newName,
|
||||
uint64 newCommitTime)
|
||||
{
|
||||
PledgeManager storage giver = findManager(idGiver);
|
||||
require(giver.managerType == PledgeManagerType.Giver); //Must be a Giver
|
||||
PledgeAdmin storage giver = findAdmin(idGiver);
|
||||
require(giver.adminType == PledgeAdminType.Giver); //Must be a Giver
|
||||
require(giver.addr == msg.sender); //current addr had to originate this tx
|
||||
giver.addr = newAddr;
|
||||
giver.name = newName;
|
||||
|
@ -152,10 +152,10 @@ contract LiquidPledgingBase {
|
|||
/// @notice Creates a new Delegate
|
||||
function addDelegate(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDelegate) { //TODO return index number
|
||||
|
||||
idDelegate = uint64(managers.length);
|
||||
idDelegate = uint64(admins.length);
|
||||
|
||||
managers.push(PledgeManager(
|
||||
PledgeManagerType.Delegate,
|
||||
admins.push(PledgeAdmin(
|
||||
PledgeAdminType.Delegate,
|
||||
msg.sender,
|
||||
name,
|
||||
commitTime,
|
||||
|
@ -174,8 +174,8 @@ contract LiquidPledgingBase {
|
|||
address newAddr,
|
||||
string newName,
|
||||
uint64 newCommitTime) {
|
||||
PledgeManager storage delegate = findManager(idDelegate);
|
||||
require(delegate.managerType == PledgeManagerType.Delegate);
|
||||
PledgeAdmin storage delegate = findAdmin(idDelegate);
|
||||
require(delegate.adminType == PledgeAdminType.Delegate);
|
||||
require(delegate.addr == msg.sender);
|
||||
delegate.addr = newAddr;
|
||||
delegate.name = newName;
|
||||
|
@ -186,19 +186,19 @@ contract LiquidPledgingBase {
|
|||
event DelegateUpdated(uint64 indexed idDelegate);
|
||||
|
||||
/// @notice Creates a new Campaign
|
||||
function addCampaign(string name, address campaignManager, uint64 parentCampaign, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idCampaign) {
|
||||
function addCampaign(string name, address campaignAdmin, uint64 parentCampaign, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idCampaign) {
|
||||
if (parentCampaign != 0) {
|
||||
PledgeManager storage pm = findManager(parentCampaign);
|
||||
require(pm.managerType == PledgeManagerType.Campaign);
|
||||
PledgeAdmin storage pm = findAdmin(parentCampaign);
|
||||
require(pm.adminType == PledgeAdminType.Campaign);
|
||||
require(pm.addr == msg.sender);
|
||||
require(getCampaignLevel(pm) < MAX_SUBCAMPAIGN_LEVEL);
|
||||
}
|
||||
|
||||
idCampaign = uint64(managers.length);
|
||||
idCampaign = uint64(admins.length);
|
||||
|
||||
managers.push(PledgeManager(
|
||||
PledgeManagerType.Campaign,
|
||||
campaignManager,
|
||||
admins.push(PledgeAdmin(
|
||||
PledgeAdminType.Campaign,
|
||||
campaignAdmin,
|
||||
name,
|
||||
commitTime,
|
||||
parentCampaign,
|
||||
|
@ -218,8 +218,8 @@ contract LiquidPledgingBase {
|
|||
string newName,
|
||||
uint64 newCommitTime)
|
||||
{
|
||||
PledgeManager storage campaign = findManager(idCampaign);
|
||||
require(campaign.managerType == PledgeManagerType.Campaign);
|
||||
PledgeAdmin storage campaign = findAdmin(idCampaign);
|
||||
require(campaign.adminType == PledgeAdminType.Campaign);
|
||||
require(campaign.addr == msg.sender);
|
||||
campaign.addr = newAddr;
|
||||
campaign.name = newName;
|
||||
|
@ -227,7 +227,7 @@ contract LiquidPledgingBase {
|
|||
CampaignUpdated(idCampaign);
|
||||
}
|
||||
|
||||
event CampaignUpdated(uint64 indexed idManager);
|
||||
event CampaignUpdated(uint64 indexed idAdmin);
|
||||
|
||||
|
||||
//////////
|
||||
|
@ -266,17 +266,17 @@ contract LiquidPledgingBase {
|
|||
) {
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
idDelegate = n.delegationChain[idxDelegate - 1];
|
||||
PledgeManager storage delegate = findManager(idDelegate);
|
||||
PledgeAdmin storage delegate = findAdmin(idDelegate);
|
||||
addr = delegate.addr;
|
||||
name = delegate.name;
|
||||
}
|
||||
/// @notice Public constant that states the number of admins in the system
|
||||
function numberOfPledgeManagers() constant returns(uint) {
|
||||
return managers.length - 1;
|
||||
function numberOfPledgeAdmins() constant returns(uint) {
|
||||
return admins.length - 1;
|
||||
}
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
function getPledgeManager(uint64 idManager) constant returns (
|
||||
PledgeManagerType managerType,
|
||||
function getPledgeAdmin(uint64 idAdmin) constant returns (
|
||||
PledgeAdminType adminType,
|
||||
address addr,
|
||||
string name,
|
||||
uint64 commitTime,
|
||||
|
@ -284,8 +284,8 @@ contract LiquidPledgingBase {
|
|||
bool canceled,
|
||||
address plugin)
|
||||
{
|
||||
PledgeManager storage m = findManager(idManager);
|
||||
managerType = m.managerType;
|
||||
PledgeAdmin storage m = findAdmin(idAdmin);
|
||||
adminType = m.adminType;
|
||||
addr = m.addr;
|
||||
name = m.name;
|
||||
commitTime = m.commitTime;
|
||||
|
@ -320,9 +320,9 @@ contract LiquidPledgingBase {
|
|||
return idx;
|
||||
}
|
||||
|
||||
function findManager(uint64 idManager) internal returns (PledgeManager storage) {
|
||||
require(idManager < managers.length);
|
||||
return managers[idManager];
|
||||
function findAdmin(uint64 idAdmin) internal returns (PledgeAdmin storage) {
|
||||
require(idAdmin < admins.length);
|
||||
return admins[idAdmin];
|
||||
}
|
||||
|
||||
function findPledge(uint64 idPledge) internal returns (Pledge storage) {
|
||||
|
@ -353,28 +353,28 @@ contract LiquidPledgingBase {
|
|||
// helper function that returns the max commit time of the owner and all the
|
||||
// delegates
|
||||
function maxCommitTime(Pledge n) internal returns(uint commitTime) {
|
||||
PledgeManager storage m = findManager(n.owner);
|
||||
PledgeAdmin storage m = findAdmin(n.owner);
|
||||
commitTime = m.commitTime;
|
||||
|
||||
for (uint i=0; i<n.delegationChain.length; i++) {
|
||||
m = findManager(n.delegationChain[i]);
|
||||
m = findAdmin(n.delegationChain[i]);
|
||||
if (m.commitTime > commitTime) commitTime = m.commitTime;
|
||||
}
|
||||
}
|
||||
|
||||
// helper function that returns the campaign level solely to check that there
|
||||
// are not too many Campaigns that violate MAX_SUBCAMPAIGNS_LEVEL
|
||||
function getCampaignLevel(PledgeManager m) internal returns(uint) {
|
||||
assert(m.managerType == PledgeManagerType.Campaign);
|
||||
function getCampaignLevel(PledgeAdmin m) internal returns(uint) {
|
||||
assert(m.adminType == PledgeAdminType.Campaign);
|
||||
if (m.parentCampaign == 0) return(1);
|
||||
PledgeManager storage parentNM = findManager(m.parentCampaign);
|
||||
PledgeAdmin storage parentNM = findAdmin(m.parentCampaign);
|
||||
return getCampaignLevel(parentNM);
|
||||
}
|
||||
|
||||
function isCampaignCanceled(uint64 campaignId) constant returns (bool) {
|
||||
PledgeManager storage m = findManager(campaignId);
|
||||
if (m.managerType == PledgeManagerType.Giver) return false;
|
||||
assert(m.managerType == PledgeManagerType.Campaign);
|
||||
PledgeAdmin storage m = findAdmin(campaignId);
|
||||
if (m.adminType == PledgeAdminType.Giver) return false;
|
||||
assert(m.adminType == PledgeAdminType.Campaign);
|
||||
if (m.canceled) return true;
|
||||
if (m.parentCampaign == 0) return false;
|
||||
return isCampaignCanceled(m.parentCampaign);
|
||||
|
@ -385,17 +385,17 @@ contract LiquidPledgingBase {
|
|||
function getOldestPledgeNotCanceled(uint64 idPledge) internal constant returns(uint64) { //todo rename
|
||||
if (idPledge == 0) return 0;
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
PledgeManager storage manager = findManager(n.owner);
|
||||
if (manager.managerType == PledgeManagerType.Giver) return idPledge;
|
||||
PledgeAdmin storage admin = findAdmin(n.owner);
|
||||
if (admin.adminType == PledgeAdminType.Giver) return idPledge;
|
||||
|
||||
assert(manager.managerType == PledgeManagerType.Campaign);
|
||||
assert(admin.adminType == PledgeAdminType.Campaign);
|
||||
|
||||
if (!isCampaignCanceled(n.owner)) return idPledge;
|
||||
|
||||
return getOldestPledgeNotCanceled(n.oldPledge);
|
||||
}
|
||||
|
||||
function checkManagerOwner(PledgeManager m) internal constant {
|
||||
function checkAdminOwner(PledgeAdmin m) internal constant {
|
||||
require((msg.sender == m.addr) || (msg.sender == address(m.plugin)));
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -51,13 +51,13 @@ contract LiquidPledgingBase {
|
|||
uint constant MAX_SUBCAMPAIGN_LEVEL = 20;
|
||||
uint constant MAX_INTERCAMPAIGN_LEVEL = 20;
|
||||
|
||||
enum PledgeManagerType { Giver, Delegate, Campaign }
|
||||
enum PledgeAdminType { Giver, Delegate, Campaign }
|
||||
enum PaymentState { NotPaid, Paying, Paid } // TODO name change NotPaid
|
||||
|
||||
/// @dev This struct defines the details of each the PledgeManager, these
|
||||
/// PledgeManagers can own pledges and act as delegates
|
||||
struct PledgeManager { // TODO name change PledgeManager
|
||||
PledgeManagerType managerType; // Giver, Delegate or Campaign
|
||||
/// @dev This struct defines the details of each the PledgeAdmin, these
|
||||
/// PledgeAdmins can own pledges and act as delegates
|
||||
struct PledgeAdmin { // TODO name change PledgeAdmin
|
||||
PledgeAdminType adminType; // Giver, Delegate or Campaign
|
||||
address addr; // account or contract address for admin
|
||||
string name;
|
||||
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
|
||||
|
@ -68,7 +68,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
struct Pledge {
|
||||
uint amount;
|
||||
uint64 owner; // PledgeManager
|
||||
uint64 owner; // PledgeAdmin
|
||||
uint64[] delegationChain; // list of index numbers
|
||||
uint64 proposedCampaign; // TODO change the name only used for when delegates are precommiting to a campaign
|
||||
uint64 commitTime; // When the proposedCampaign will become the owner
|
||||
|
@ -77,7 +77,7 @@ contract LiquidPledgingBase {
|
|||
}
|
||||
|
||||
Pledge[] pledges;
|
||||
PledgeManager[] managers; //The list of pledgeManagers 0 means there is no manager
|
||||
PledgeAdmin[] admins; //The list of pledgeAdmins 0 means there is no admin
|
||||
Vault public vault;
|
||||
|
||||
// this mapping allows you to search for a specific pledge's index number by the hash of that pledge
|
||||
|
@ -101,24 +101,24 @@ contract LiquidPledgingBase {
|
|||
/// @notice The Constructor creates the `LiquidPledgingBase` on the blockchain
|
||||
/// @param _vault Where the ETH is stored that the pledges represent
|
||||
function LiquidPledgingBase(address _vault) {
|
||||
managers.length = 1; // we reserve the 0 manager
|
||||
admins.length = 1; // we reserve the 0 admin
|
||||
pledges.length = 1; // we reserve the 0 pledge
|
||||
vault = Vault(_vault);
|
||||
}
|
||||
|
||||
|
||||
///////
|
||||
// Managers functions
|
||||
// Adminss functions
|
||||
//////
|
||||
|
||||
/// @notice Creates a giver.
|
||||
function addGiver(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idGiver) {
|
||||
|
||||
idGiver = uint64(managers.length);
|
||||
idGiver = uint64(admins.length);
|
||||
|
||||
managers.push(PledgeManager(
|
||||
PledgeManagerType.Giver,
|
||||
admins.push(PledgeAdmin(
|
||||
PledgeAdminType.Giver,
|
||||
msg.sender,
|
||||
name,
|
||||
commitTime,
|
||||
|
@ -138,8 +138,8 @@ contract LiquidPledgingBase {
|
|||
string newName,
|
||||
uint64 newCommitTime)
|
||||
{
|
||||
PledgeManager storage giver = findManager(idGiver);
|
||||
require(giver.managerType == PledgeManagerType.Giver); //Must be a Giver
|
||||
PledgeAdmin storage giver = findAdmin(idGiver);
|
||||
require(giver.adminType == PledgeAdminType.Giver); //Must be a Giver
|
||||
require(giver.addr == msg.sender); //current addr had to originate this tx
|
||||
giver.addr = newAddr;
|
||||
giver.name = newName;
|
||||
|
@ -152,10 +152,10 @@ contract LiquidPledgingBase {
|
|||
/// @notice Creates a new Delegate
|
||||
function addDelegate(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDelegate) { //TODO return index number
|
||||
|
||||
idDelegate = uint64(managers.length);
|
||||
idDelegate = uint64(admins.length);
|
||||
|
||||
managers.push(PledgeManager(
|
||||
PledgeManagerType.Delegate,
|
||||
admins.push(PledgeAdmin(
|
||||
PledgeAdminType.Delegate,
|
||||
msg.sender,
|
||||
name,
|
||||
commitTime,
|
||||
|
@ -174,8 +174,8 @@ contract LiquidPledgingBase {
|
|||
address newAddr,
|
||||
string newName,
|
||||
uint64 newCommitTime) {
|
||||
PledgeManager storage delegate = findManager(idDelegate);
|
||||
require(delegate.managerType == PledgeManagerType.Delegate);
|
||||
PledgeAdmin storage delegate = findAdmin(idDelegate);
|
||||
require(delegate.adminType == PledgeAdminType.Delegate);
|
||||
require(delegate.addr == msg.sender);
|
||||
delegate.addr = newAddr;
|
||||
delegate.name = newName;
|
||||
|
@ -186,19 +186,19 @@ contract LiquidPledgingBase {
|
|||
event DelegateUpdated(uint64 indexed idDelegate);
|
||||
|
||||
/// @notice Creates a new Campaign
|
||||
function addCampaign(string name, address campaignManager, uint64 parentCampaign, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idCampaign) {
|
||||
function addCampaign(string name, address campaignAdmin, uint64 parentCampaign, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idCampaign) {
|
||||
if (parentCampaign != 0) {
|
||||
PledgeManager storage pm = findManager(parentCampaign);
|
||||
require(pm.managerType == PledgeManagerType.Campaign);
|
||||
PledgeAdmin storage pm = findAdmin(parentCampaign);
|
||||
require(pm.adminType == PledgeAdminType.Campaign);
|
||||
require(pm.addr == msg.sender);
|
||||
require(getCampaignLevel(pm) < MAX_SUBCAMPAIGN_LEVEL);
|
||||
}
|
||||
|
||||
idCampaign = uint64(managers.length);
|
||||
idCampaign = uint64(admins.length);
|
||||
|
||||
managers.push(PledgeManager(
|
||||
PledgeManagerType.Campaign,
|
||||
campaignManager,
|
||||
admins.push(PledgeAdmin(
|
||||
PledgeAdminType.Campaign,
|
||||
campaignAdmin,
|
||||
name,
|
||||
commitTime,
|
||||
parentCampaign,
|
||||
|
@ -218,8 +218,8 @@ contract LiquidPledgingBase {
|
|||
string newName,
|
||||
uint64 newCommitTime)
|
||||
{
|
||||
PledgeManager storage campaign = findManager(idCampaign);
|
||||
require(campaign.managerType == PledgeManagerType.Campaign);
|
||||
PledgeAdmin storage campaign = findAdmin(idCampaign);
|
||||
require(campaign.adminType == PledgeAdminType.Campaign);
|
||||
require(campaign.addr == msg.sender);
|
||||
campaign.addr = newAddr;
|
||||
campaign.name = newName;
|
||||
|
@ -227,7 +227,7 @@ contract LiquidPledgingBase {
|
|||
CampaignUpdated(idCampaign);
|
||||
}
|
||||
|
||||
event CampaignUpdated(uint64 indexed idManager);
|
||||
event CampaignUpdated(uint64 indexed idAdmin);
|
||||
|
||||
|
||||
//////////
|
||||
|
@ -266,17 +266,17 @@ contract LiquidPledgingBase {
|
|||
) {
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
idDelegate = n.delegationChain[idxDelegate - 1];
|
||||
PledgeManager storage delegate = findManager(idDelegate);
|
||||
PledgeAdmin storage delegate = findAdmin(idDelegate);
|
||||
addr = delegate.addr;
|
||||
name = delegate.name;
|
||||
}
|
||||
/// @notice Public constant that states the number of admins in the system
|
||||
function numberOfPledgeManagers() constant returns(uint) {
|
||||
return managers.length - 1;
|
||||
function numberOfPledgeAdmins() constant returns(uint) {
|
||||
return admins.length - 1;
|
||||
}
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
function getPledgeManager(uint64 idManager) constant returns (
|
||||
PledgeManagerType managerType,
|
||||
function getPledgeAdmin(uint64 idAdmin) constant returns (
|
||||
PledgeAdminType adminType,
|
||||
address addr,
|
||||
string name,
|
||||
uint64 commitTime,
|
||||
|
@ -284,8 +284,8 @@ contract LiquidPledgingBase {
|
|||
bool canceled,
|
||||
address plugin)
|
||||
{
|
||||
PledgeManager storage m = findManager(idManager);
|
||||
managerType = m.managerType;
|
||||
PledgeAdmin storage m = findAdmin(idAdmin);
|
||||
adminType = m.adminType;
|
||||
addr = m.addr;
|
||||
name = m.name;
|
||||
commitTime = m.commitTime;
|
||||
|
@ -320,9 +320,9 @@ contract LiquidPledgingBase {
|
|||
return idx;
|
||||
}
|
||||
|
||||
function findManager(uint64 idManager) internal returns (PledgeManager storage) {
|
||||
require(idManager < managers.length);
|
||||
return managers[idManager];
|
||||
function findAdmin(uint64 idAdmin) internal returns (PledgeAdmin storage) {
|
||||
require(idAdmin < admins.length);
|
||||
return admins[idAdmin];
|
||||
}
|
||||
|
||||
function findPledge(uint64 idPledge) internal returns (Pledge storage) {
|
||||
|
@ -353,28 +353,28 @@ contract LiquidPledgingBase {
|
|||
// helper function that returns the max commit time of the owner and all the
|
||||
// delegates
|
||||
function maxCommitTime(Pledge n) internal returns(uint commitTime) {
|
||||
PledgeManager storage m = findManager(n.owner);
|
||||
PledgeAdmin storage m = findAdmin(n.owner);
|
||||
commitTime = m.commitTime;
|
||||
|
||||
for (uint i=0; i<n.delegationChain.length; i++) {
|
||||
m = findManager(n.delegationChain[i]);
|
||||
m = findAdmin(n.delegationChain[i]);
|
||||
if (m.commitTime > commitTime) commitTime = m.commitTime;
|
||||
}
|
||||
}
|
||||
|
||||
// helper function that returns the campaign level solely to check that there
|
||||
// are not too many Campaigns that violate MAX_SUBCAMPAIGNS_LEVEL
|
||||
function getCampaignLevel(PledgeManager m) internal returns(uint) {
|
||||
assert(m.managerType == PledgeManagerType.Campaign);
|
||||
function getCampaignLevel(PledgeAdmin m) internal returns(uint) {
|
||||
assert(m.adminType == PledgeAdminType.Campaign);
|
||||
if (m.parentCampaign == 0) return(1);
|
||||
PledgeManager storage parentNM = findManager(m.parentCampaign);
|
||||
PledgeAdmin storage parentNM = findAdmin(m.parentCampaign);
|
||||
return getCampaignLevel(parentNM);
|
||||
}
|
||||
|
||||
function isCampaignCanceled(uint64 campaignId) constant returns (bool) {
|
||||
PledgeManager storage m = findManager(campaignId);
|
||||
if (m.managerType == PledgeManagerType.Giver) return false;
|
||||
assert(m.managerType == PledgeManagerType.Campaign);
|
||||
PledgeAdmin storage m = findAdmin(campaignId);
|
||||
if (m.adminType == PledgeAdminType.Giver) return false;
|
||||
assert(m.adminType == PledgeAdminType.Campaign);
|
||||
if (m.canceled) return true;
|
||||
if (m.parentCampaign == 0) return false;
|
||||
return isCampaignCanceled(m.parentCampaign);
|
||||
|
@ -385,17 +385,17 @@ contract LiquidPledgingBase {
|
|||
function getOldestPledgeNotCanceled(uint64 idPledge) internal constant returns(uint64) { //todo rename
|
||||
if (idPledge == 0) return 0;
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
PledgeManager storage manager = findManager(n.owner);
|
||||
if (manager.managerType == PledgeManagerType.Giver) return idPledge;
|
||||
PledgeAdmin storage admin = findAdmin(n.owner);
|
||||
if (admin.adminType == PledgeAdminType.Giver) return idPledge;
|
||||
|
||||
assert(manager.managerType == PledgeManagerType.Campaign);
|
||||
assert(admin.adminType == PledgeAdminType.Campaign);
|
||||
|
||||
if (!isCampaignCanceled(n.owner)) return idPledge;
|
||||
|
||||
return getOldestPledgeNotCanceled(n.oldPledge);
|
||||
}
|
||||
|
||||
function checkManagerOwner(PledgeManager m) internal constant {
|
||||
function checkAdminOwner(PledgeAdmin m) internal constant {
|
||||
require((msg.sender == m.addr) || (msg.sender == address(m.plugin)));
|
||||
}
|
||||
}
|
||||
|
@ -430,11 +430,11 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
idGiver = addGiver('', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
|
||||
}
|
||||
|
||||
PledgeManager storage sender = findManager(idGiver);
|
||||
PledgeAdmin storage sender = findAdmin(idGiver);
|
||||
|
||||
checkManagerOwner(sender);
|
||||
checkAdminOwner(sender);
|
||||
|
||||
require(sender.managerType == PledgeManagerType.Giver);
|
||||
require(sender.adminType == PledgeAdminType.Giver);
|
||||
|
||||
uint amount = msg.value;
|
||||
|
||||
|
@ -460,8 +460,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
|
||||
/// @notice Moves value between pledges
|
||||
/// @param idSender ID of the giver, delegate or campaign manager that is transferring
|
||||
/// the funds from Pledge to Pledge. This manager must have permissions to move the value
|
||||
/// @param idSender ID of the giver, delegate or campaign admin that is transferring
|
||||
/// the funds from Pledge to Pledge. This admin must have permissions to move the value
|
||||
/// @param idPledge Id of the pledge that's moving the value
|
||||
/// @param amount Quantity of value that's being moved
|
||||
/// @param idReceiver Destination of the value, can be a giver sending to a giver or
|
||||
|
@ -471,19 +471,19 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
idPledge = normalizePledge(idPledge);
|
||||
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
PledgeManager storage receiver = findManager(idReceiver);
|
||||
PledgeManager storage sender = findManager(idSender);
|
||||
PledgeAdmin storage receiver = findAdmin(idReceiver);
|
||||
PledgeAdmin storage sender = findAdmin(idSender);
|
||||
|
||||
checkManagerOwner(sender);
|
||||
checkAdminOwner(sender);
|
||||
require(n.paymentState == PaymentState.NotPaid);
|
||||
|
||||
// If the sender is the owner
|
||||
if (n.owner == idSender) {
|
||||
if (receiver.managerType == PledgeManagerType.Giver) {
|
||||
if (receiver.adminType == PledgeAdminType.Giver) {
|
||||
transferOwnershipToGiver(idPledge, amount, idReceiver);
|
||||
} else if (receiver.managerType == PledgeManagerType.Campaign) {
|
||||
} else if (receiver.adminType == PledgeAdminType.Campaign) {
|
||||
transferOwnershipToCampaign(idPledge, amount, idReceiver);
|
||||
} else if (receiver.managerType == PledgeManagerType.Delegate) {
|
||||
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||
appendDelegate(idPledge, amount, idReceiver);
|
||||
} else {
|
||||
assert(false);
|
||||
|
@ -496,7 +496,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
if (senderDIdx != NOTFOUND) {
|
||||
|
||||
// If the receiver is another giver
|
||||
if (receiver.managerType == PledgeManagerType.Giver) {
|
||||
if (receiver.adminType == PledgeAdminType.Giver) {
|
||||
// Only accept to change to the original giver to remove all delegates
|
||||
assert(n.owner == idReceiver);
|
||||
undelegate(idPledge, amount, n.delegationChain.length);
|
||||
|
@ -504,7 +504,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
}
|
||||
|
||||
// If the receiver is another delegate
|
||||
if (receiver.managerType == PledgeManagerType.Delegate) {
|
||||
if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||
uint receiverDIdx = getDelegateIdx(n, idReceiver);
|
||||
|
||||
// If the receiver is not in the delegate list
|
||||
|
@ -532,7 +532,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
// If the delegate wants to support a campaign, they undelegate all
|
||||
// the delegates after them in the chain and choose a campaign
|
||||
if (receiver.managerType == PledgeManagerType.Campaign) {
|
||||
if (receiver.adminType == PledgeAdminType.Campaign) {
|
||||
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
||||
proposeAssignCampaign(idPledge, amount, idReceiver);
|
||||
return;
|
||||
|
@ -543,7 +543,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
|
||||
/// @notice This method is used to withdraw value from the system. This can be used
|
||||
/// by the givers to avoid committing the donation or by campaign manager to use
|
||||
/// by the givers to avoid committing the donation or by campaign admin to use
|
||||
/// the Ether.
|
||||
/// @param idPledge Id of the pledge that wants to be withdrawn.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawn.
|
||||
|
@ -555,9 +555,9 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
require(n.paymentState == PaymentState.NotPaid);
|
||||
|
||||
PledgeManager storage owner = findManager(n.owner);
|
||||
PledgeAdmin storage owner = findAdmin(n.owner);
|
||||
|
||||
checkManagerOwner(owner);
|
||||
checkAdminOwner(owner);
|
||||
|
||||
uint64 idNewPledge = findPledge(
|
||||
n.owner,
|
||||
|
@ -622,8 +622,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
/// @notice Method called to cancel this campaign.
|
||||
/// @param idCampaign Id of the projct that wants to be canceled.
|
||||
function cancelCampaign(uint64 idCampaign) {
|
||||
PledgeManager storage campaign = findManager(idCampaign);
|
||||
checkManagerOwner(campaign);
|
||||
PledgeAdmin storage campaign = findAdmin(idCampaign);
|
||||
checkAdminOwner(campaign);
|
||||
campaign.canceled = true;
|
||||
|
||||
CancelCampaign(idCampaign);
|
||||
|
@ -635,8 +635,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
|
||||
PledgeManager storage m = findManager(n.owner);
|
||||
checkManagerOwner(m);
|
||||
PledgeAdmin storage m = findAdmin(n.owner);
|
||||
checkAdminOwner(m);
|
||||
|
||||
doTransfer(idPledge, n.oldPledge, amount);
|
||||
}
|
||||
|
@ -847,17 +847,17 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
// Plugins
|
||||
/////////////
|
||||
|
||||
function callPlugin(bool before, uint64 managerId, uint64 fromPledge, uint64 toPledge, uint64 context, uint amount) internal returns (uint allowedAmount) {
|
||||
function callPlugin(bool before, uint64 adminId, uint64 fromPledge, uint64 toPledge, uint64 context, uint amount) internal returns (uint allowedAmount) {
|
||||
uint newAmount;
|
||||
allowedAmount = amount;
|
||||
PledgeManager storage manager = findManager(managerId);
|
||||
if ((address(manager.plugin) != 0) && (allowedAmount > 0)) {
|
||||
PledgeAdmin storage admin = findAdmin(adminId);
|
||||
if ((address(admin.plugin) != 0) && (allowedAmount > 0)) {
|
||||
if (before) {
|
||||
newAmount = manager.plugin.beforeTransfer(managerId, fromPledge, toPledge, context, amount);
|
||||
newAmount = admin.plugin.beforeTransfer(adminId, fromPledge, toPledge, context, amount);
|
||||
require(newAmount <= allowedAmount);
|
||||
allowedAmount = newAmount;
|
||||
} else {
|
||||
manager.plugin.afterTransfer(managerId, fromPledge, toPledge, context, amount);
|
||||
admin.plugin.afterTransfer(adminId, fromPledge, toPledge, context, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,13 +51,13 @@ contract LiquidPledgingBase {
|
|||
uint constant MAX_SUBCAMPAIGN_LEVEL = 20;
|
||||
uint constant MAX_INTERCAMPAIGN_LEVEL = 20;
|
||||
|
||||
enum PledgeManagerType { Giver, Delegate, Campaign }
|
||||
enum PledgeAdminType { Giver, Delegate, Campaign }
|
||||
enum PaymentState { NotPaid, Paying, Paid } // TODO name change NotPaid
|
||||
|
||||
/// @dev This struct defines the details of each the PledgeManager, these
|
||||
/// PledgeManagers can own pledges and act as delegates
|
||||
struct PledgeManager { // TODO name change PledgeManager
|
||||
PledgeManagerType managerType; // Giver, Delegate or Campaign
|
||||
/// @dev This struct defines the details of each the PledgeAdmin, these
|
||||
/// PledgeAdmins can own pledges and act as delegates
|
||||
struct PledgeAdmin { // TODO name change PledgeAdmin
|
||||
PledgeAdminType adminType; // Giver, Delegate or Campaign
|
||||
address addr; // account or contract address for admin
|
||||
string name;
|
||||
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
|
||||
|
@ -68,7 +68,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
struct Pledge {
|
||||
uint amount;
|
||||
uint64 owner; // PledgeManager
|
||||
uint64 owner; // PledgeAdmin
|
||||
uint64[] delegationChain; // list of index numbers
|
||||
uint64 proposedCampaign; // TODO change the name only used for when delegates are precommiting to a campaign
|
||||
uint64 commitTime; // When the proposedCampaign will become the owner
|
||||
|
@ -77,7 +77,7 @@ contract LiquidPledgingBase {
|
|||
}
|
||||
|
||||
Pledge[] pledges;
|
||||
PledgeManager[] managers; //The list of pledgeManagers 0 means there is no manager
|
||||
PledgeAdmin[] admins; //The list of pledgeAdmins 0 means there is no admin
|
||||
Vault public vault;
|
||||
|
||||
// this mapping allows you to search for a specific pledge's index number by the hash of that pledge
|
||||
|
@ -101,24 +101,24 @@ contract LiquidPledgingBase {
|
|||
/// @notice The Constructor creates the `LiquidPledgingBase` on the blockchain
|
||||
/// @param _vault Where the ETH is stored that the pledges represent
|
||||
function LiquidPledgingBase(address _vault) {
|
||||
managers.length = 1; // we reserve the 0 manager
|
||||
admins.length = 1; // we reserve the 0 admin
|
||||
pledges.length = 1; // we reserve the 0 pledge
|
||||
vault = Vault(_vault);
|
||||
}
|
||||
|
||||
|
||||
///////
|
||||
// Managers functions
|
||||
// Adminss functions
|
||||
//////
|
||||
|
||||
/// @notice Creates a giver.
|
||||
function addGiver(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idGiver) {
|
||||
|
||||
idGiver = uint64(managers.length);
|
||||
idGiver = uint64(admins.length);
|
||||
|
||||
managers.push(PledgeManager(
|
||||
PledgeManagerType.Giver,
|
||||
admins.push(PledgeAdmin(
|
||||
PledgeAdminType.Giver,
|
||||
msg.sender,
|
||||
name,
|
||||
commitTime,
|
||||
|
@ -138,8 +138,8 @@ contract LiquidPledgingBase {
|
|||
string newName,
|
||||
uint64 newCommitTime)
|
||||
{
|
||||
PledgeManager storage giver = findManager(idGiver);
|
||||
require(giver.managerType == PledgeManagerType.Giver); //Must be a Giver
|
||||
PledgeAdmin storage giver = findAdmin(idGiver);
|
||||
require(giver.adminType == PledgeAdminType.Giver); //Must be a Giver
|
||||
require(giver.addr == msg.sender); //current addr had to originate this tx
|
||||
giver.addr = newAddr;
|
||||
giver.name = newName;
|
||||
|
@ -152,10 +152,10 @@ contract LiquidPledgingBase {
|
|||
/// @notice Creates a new Delegate
|
||||
function addDelegate(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDelegate) { //TODO return index number
|
||||
|
||||
idDelegate = uint64(managers.length);
|
||||
idDelegate = uint64(admins.length);
|
||||
|
||||
managers.push(PledgeManager(
|
||||
PledgeManagerType.Delegate,
|
||||
admins.push(PledgeAdmin(
|
||||
PledgeAdminType.Delegate,
|
||||
msg.sender,
|
||||
name,
|
||||
commitTime,
|
||||
|
@ -174,8 +174,8 @@ contract LiquidPledgingBase {
|
|||
address newAddr,
|
||||
string newName,
|
||||
uint64 newCommitTime) {
|
||||
PledgeManager storage delegate = findManager(idDelegate);
|
||||
require(delegate.managerType == PledgeManagerType.Delegate);
|
||||
PledgeAdmin storage delegate = findAdmin(idDelegate);
|
||||
require(delegate.adminType == PledgeAdminType.Delegate);
|
||||
require(delegate.addr == msg.sender);
|
||||
delegate.addr = newAddr;
|
||||
delegate.name = newName;
|
||||
|
@ -186,19 +186,19 @@ contract LiquidPledgingBase {
|
|||
event DelegateUpdated(uint64 indexed idDelegate);
|
||||
|
||||
/// @notice Creates a new Campaign
|
||||
function addCampaign(string name, address campaignManager, uint64 parentCampaign, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idCampaign) {
|
||||
function addCampaign(string name, address campaignAdmin, uint64 parentCampaign, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idCampaign) {
|
||||
if (parentCampaign != 0) {
|
||||
PledgeManager storage pm = findManager(parentCampaign);
|
||||
require(pm.managerType == PledgeManagerType.Campaign);
|
||||
PledgeAdmin storage pm = findAdmin(parentCampaign);
|
||||
require(pm.adminType == PledgeAdminType.Campaign);
|
||||
require(pm.addr == msg.sender);
|
||||
require(getCampaignLevel(pm) < MAX_SUBCAMPAIGN_LEVEL);
|
||||
}
|
||||
|
||||
idCampaign = uint64(managers.length);
|
||||
idCampaign = uint64(admins.length);
|
||||
|
||||
managers.push(PledgeManager(
|
||||
PledgeManagerType.Campaign,
|
||||
campaignManager,
|
||||
admins.push(PledgeAdmin(
|
||||
PledgeAdminType.Campaign,
|
||||
campaignAdmin,
|
||||
name,
|
||||
commitTime,
|
||||
parentCampaign,
|
||||
|
@ -218,8 +218,8 @@ contract LiquidPledgingBase {
|
|||
string newName,
|
||||
uint64 newCommitTime)
|
||||
{
|
||||
PledgeManager storage campaign = findManager(idCampaign);
|
||||
require(campaign.managerType == PledgeManagerType.Campaign);
|
||||
PledgeAdmin storage campaign = findAdmin(idCampaign);
|
||||
require(campaign.adminType == PledgeAdminType.Campaign);
|
||||
require(campaign.addr == msg.sender);
|
||||
campaign.addr = newAddr;
|
||||
campaign.name = newName;
|
||||
|
@ -227,7 +227,7 @@ contract LiquidPledgingBase {
|
|||
CampaignUpdated(idCampaign);
|
||||
}
|
||||
|
||||
event CampaignUpdated(uint64 indexed idManager);
|
||||
event CampaignUpdated(uint64 indexed idAdmin);
|
||||
|
||||
|
||||
//////////
|
||||
|
@ -266,17 +266,17 @@ contract LiquidPledgingBase {
|
|||
) {
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
idDelegate = n.delegationChain[idxDelegate - 1];
|
||||
PledgeManager storage delegate = findManager(idDelegate);
|
||||
PledgeAdmin storage delegate = findAdmin(idDelegate);
|
||||
addr = delegate.addr;
|
||||
name = delegate.name;
|
||||
}
|
||||
/// @notice Public constant that states the number of admins in the system
|
||||
function numberOfPledgeManagers() constant returns(uint) {
|
||||
return managers.length - 1;
|
||||
function numberOfPledgeAdmins() constant returns(uint) {
|
||||
return admins.length - 1;
|
||||
}
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
function getPledgeManager(uint64 idManager) constant returns (
|
||||
PledgeManagerType managerType,
|
||||
function getPledgeAdmin(uint64 idAdmin) constant returns (
|
||||
PledgeAdminType adminType,
|
||||
address addr,
|
||||
string name,
|
||||
uint64 commitTime,
|
||||
|
@ -284,8 +284,8 @@ contract LiquidPledgingBase {
|
|||
bool canceled,
|
||||
address plugin)
|
||||
{
|
||||
PledgeManager storage m = findManager(idManager);
|
||||
managerType = m.managerType;
|
||||
PledgeAdmin storage m = findAdmin(idAdmin);
|
||||
adminType = m.adminType;
|
||||
addr = m.addr;
|
||||
name = m.name;
|
||||
commitTime = m.commitTime;
|
||||
|
@ -320,9 +320,9 @@ contract LiquidPledgingBase {
|
|||
return idx;
|
||||
}
|
||||
|
||||
function findManager(uint64 idManager) internal returns (PledgeManager storage) {
|
||||
require(idManager < managers.length);
|
||||
return managers[idManager];
|
||||
function findAdmin(uint64 idAdmin) internal returns (PledgeAdmin storage) {
|
||||
require(idAdmin < admins.length);
|
||||
return admins[idAdmin];
|
||||
}
|
||||
|
||||
function findPledge(uint64 idPledge) internal returns (Pledge storage) {
|
||||
|
@ -353,28 +353,28 @@ contract LiquidPledgingBase {
|
|||
// helper function that returns the max commit time of the owner and all the
|
||||
// delegates
|
||||
function maxCommitTime(Pledge n) internal returns(uint commitTime) {
|
||||
PledgeManager storage m = findManager(n.owner);
|
||||
PledgeAdmin storage m = findAdmin(n.owner);
|
||||
commitTime = m.commitTime;
|
||||
|
||||
for (uint i=0; i<n.delegationChain.length; i++) {
|
||||
m = findManager(n.delegationChain[i]);
|
||||
m = findAdmin(n.delegationChain[i]);
|
||||
if (m.commitTime > commitTime) commitTime = m.commitTime;
|
||||
}
|
||||
}
|
||||
|
||||
// helper function that returns the campaign level solely to check that there
|
||||
// are not too many Campaigns that violate MAX_SUBCAMPAIGNS_LEVEL
|
||||
function getCampaignLevel(PledgeManager m) internal returns(uint) {
|
||||
assert(m.managerType == PledgeManagerType.Campaign);
|
||||
function getCampaignLevel(PledgeAdmin m) internal returns(uint) {
|
||||
assert(m.adminType == PledgeAdminType.Campaign);
|
||||
if (m.parentCampaign == 0) return(1);
|
||||
PledgeManager storage parentNM = findManager(m.parentCampaign);
|
||||
PledgeAdmin storage parentNM = findAdmin(m.parentCampaign);
|
||||
return getCampaignLevel(parentNM);
|
||||
}
|
||||
|
||||
function isCampaignCanceled(uint64 campaignId) constant returns (bool) {
|
||||
PledgeManager storage m = findManager(campaignId);
|
||||
if (m.managerType == PledgeManagerType.Giver) return false;
|
||||
assert(m.managerType == PledgeManagerType.Campaign);
|
||||
PledgeAdmin storage m = findAdmin(campaignId);
|
||||
if (m.adminType == PledgeAdminType.Giver) return false;
|
||||
assert(m.adminType == PledgeAdminType.Campaign);
|
||||
if (m.canceled) return true;
|
||||
if (m.parentCampaign == 0) return false;
|
||||
return isCampaignCanceled(m.parentCampaign);
|
||||
|
@ -385,17 +385,17 @@ contract LiquidPledgingBase {
|
|||
function getOldestPledgeNotCanceled(uint64 idPledge) internal constant returns(uint64) { //todo rename
|
||||
if (idPledge == 0) return 0;
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
PledgeManager storage manager = findManager(n.owner);
|
||||
if (manager.managerType == PledgeManagerType.Giver) return idPledge;
|
||||
PledgeAdmin storage admin = findAdmin(n.owner);
|
||||
if (admin.adminType == PledgeAdminType.Giver) return idPledge;
|
||||
|
||||
assert(manager.managerType == PledgeManagerType.Campaign);
|
||||
assert(admin.adminType == PledgeAdminType.Campaign);
|
||||
|
||||
if (!isCampaignCanceled(n.owner)) return idPledge;
|
||||
|
||||
return getOldestPledgeNotCanceled(n.oldPledge);
|
||||
}
|
||||
|
||||
function checkManagerOwner(PledgeManager m) internal constant {
|
||||
function checkAdminOwner(PledgeAdmin m) internal constant {
|
||||
require((msg.sender == m.addr) || (msg.sender == address(m.plugin)));
|
||||
}
|
||||
}
|
||||
|
@ -430,11 +430,11 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
idGiver = addGiver('', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
|
||||
}
|
||||
|
||||
PledgeManager storage sender = findManager(idGiver);
|
||||
PledgeAdmin storage sender = findAdmin(idGiver);
|
||||
|
||||
checkManagerOwner(sender);
|
||||
checkAdminOwner(sender);
|
||||
|
||||
require(sender.managerType == PledgeManagerType.Giver);
|
||||
require(sender.adminType == PledgeAdminType.Giver);
|
||||
|
||||
uint amount = msg.value;
|
||||
|
||||
|
@ -460,8 +460,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
|
||||
/// @notice Moves value between pledges
|
||||
/// @param idSender ID of the giver, delegate or campaign manager that is transferring
|
||||
/// the funds from Pledge to Pledge. This manager must have permissions to move the value
|
||||
/// @param idSender ID of the giver, delegate or campaign admin that is transferring
|
||||
/// the funds from Pledge to Pledge. This admin must have permissions to move the value
|
||||
/// @param idPledge Id of the pledge that's moving the value
|
||||
/// @param amount Quantity of value that's being moved
|
||||
/// @param idReceiver Destination of the value, can be a giver sending to a giver or
|
||||
|
@ -471,19 +471,19 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
idPledge = normalizePledge(idPledge);
|
||||
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
PledgeManager storage receiver = findManager(idReceiver);
|
||||
PledgeManager storage sender = findManager(idSender);
|
||||
PledgeAdmin storage receiver = findAdmin(idReceiver);
|
||||
PledgeAdmin storage sender = findAdmin(idSender);
|
||||
|
||||
checkManagerOwner(sender);
|
||||
checkAdminOwner(sender);
|
||||
require(n.paymentState == PaymentState.NotPaid);
|
||||
|
||||
// If the sender is the owner
|
||||
if (n.owner == idSender) {
|
||||
if (receiver.managerType == PledgeManagerType.Giver) {
|
||||
if (receiver.adminType == PledgeAdminType.Giver) {
|
||||
transferOwnershipToGiver(idPledge, amount, idReceiver);
|
||||
} else if (receiver.managerType == PledgeManagerType.Campaign) {
|
||||
} else if (receiver.adminType == PledgeAdminType.Campaign) {
|
||||
transferOwnershipToCampaign(idPledge, amount, idReceiver);
|
||||
} else if (receiver.managerType == PledgeManagerType.Delegate) {
|
||||
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||
appendDelegate(idPledge, amount, idReceiver);
|
||||
} else {
|
||||
assert(false);
|
||||
|
@ -496,7 +496,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
if (senderDIdx != NOTFOUND) {
|
||||
|
||||
// If the receiver is another giver
|
||||
if (receiver.managerType == PledgeManagerType.Giver) {
|
||||
if (receiver.adminType == PledgeAdminType.Giver) {
|
||||
// Only accept to change to the original giver to remove all delegates
|
||||
assert(n.owner == idReceiver);
|
||||
undelegate(idPledge, amount, n.delegationChain.length);
|
||||
|
@ -504,7 +504,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
}
|
||||
|
||||
// If the receiver is another delegate
|
||||
if (receiver.managerType == PledgeManagerType.Delegate) {
|
||||
if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||
uint receiverDIdx = getDelegateIdx(n, idReceiver);
|
||||
|
||||
// If the receiver is not in the delegate list
|
||||
|
@ -532,7 +532,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
// If the delegate wants to support a campaign, they undelegate all
|
||||
// the delegates after them in the chain and choose a campaign
|
||||
if (receiver.managerType == PledgeManagerType.Campaign) {
|
||||
if (receiver.adminType == PledgeAdminType.Campaign) {
|
||||
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
||||
proposeAssignCampaign(idPledge, amount, idReceiver);
|
||||
return;
|
||||
|
@ -543,7 +543,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
|
||||
/// @notice This method is used to withdraw value from the system. This can be used
|
||||
/// by the givers to avoid committing the donation or by campaign manager to use
|
||||
/// by the givers to avoid committing the donation or by campaign admin to use
|
||||
/// the Ether.
|
||||
/// @param idPledge Id of the pledge that wants to be withdrawn.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawn.
|
||||
|
@ -555,9 +555,9 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
require(n.paymentState == PaymentState.NotPaid);
|
||||
|
||||
PledgeManager storage owner = findManager(n.owner);
|
||||
PledgeAdmin storage owner = findAdmin(n.owner);
|
||||
|
||||
checkManagerOwner(owner);
|
||||
checkAdminOwner(owner);
|
||||
|
||||
uint64 idNewPledge = findPledge(
|
||||
n.owner,
|
||||
|
@ -622,8 +622,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
/// @notice Method called to cancel this campaign.
|
||||
/// @param idCampaign Id of the projct that wants to be canceled.
|
||||
function cancelCampaign(uint64 idCampaign) {
|
||||
PledgeManager storage campaign = findManager(idCampaign);
|
||||
checkManagerOwner(campaign);
|
||||
PledgeAdmin storage campaign = findAdmin(idCampaign);
|
||||
checkAdminOwner(campaign);
|
||||
campaign.canceled = true;
|
||||
|
||||
CancelCampaign(idCampaign);
|
||||
|
@ -635,8 +635,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
|
||||
PledgeManager storage m = findManager(n.owner);
|
||||
checkManagerOwner(m);
|
||||
PledgeAdmin storage m = findAdmin(n.owner);
|
||||
checkAdminOwner(m);
|
||||
|
||||
doTransfer(idPledge, n.oldPledge, amount);
|
||||
}
|
||||
|
@ -847,17 +847,17 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
// Plugins
|
||||
/////////////
|
||||
|
||||
function callPlugin(bool before, uint64 managerId, uint64 fromPledge, uint64 toPledge, uint64 context, uint amount) internal returns (uint allowedAmount) {
|
||||
function callPlugin(bool before, uint64 adminId, uint64 fromPledge, uint64 toPledge, uint64 context, uint amount) internal returns (uint allowedAmount) {
|
||||
uint newAmount;
|
||||
allowedAmount = amount;
|
||||
PledgeManager storage manager = findManager(managerId);
|
||||
if ((address(manager.plugin) != 0) && (allowedAmount > 0)) {
|
||||
PledgeAdmin storage admin = findAdmin(adminId);
|
||||
if ((address(admin.plugin) != 0) && (allowedAmount > 0)) {
|
||||
if (before) {
|
||||
newAmount = manager.plugin.beforeTransfer(managerId, fromPledge, toPledge, context, amount);
|
||||
newAmount = admin.plugin.beforeTransfer(adminId, fromPledge, toPledge, context, amount);
|
||||
require(newAmount <= allowedAmount);
|
||||
allowedAmount = newAmount;
|
||||
} else {
|
||||
manager.plugin.afterTransfer(managerId, fromPledge, toPledge, context, amount);
|
||||
admin.plugin.afterTransfer(adminId, fromPledge, toPledge, context, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
idGiver = addGiver('', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
|
||||
}
|
||||
|
||||
PledgeManager storage sender = findManager(idGiver);
|
||||
PledgeAdmin storage sender = findAdmin(idGiver);
|
||||
|
||||
checkManagerOwner(sender);
|
||||
checkAdminOwner(sender);
|
||||
|
||||
require(sender.managerType == PledgeManagerType.Giver);
|
||||
require(sender.adminType == PledgeAdminType.Giver);
|
||||
|
||||
uint amount = msg.value;
|
||||
|
||||
|
@ -57,8 +57,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
|
||||
/// @notice Moves value between pledges
|
||||
/// @param idSender ID of the giver, delegate or campaign manager that is transferring
|
||||
/// the funds from Pledge to Pledge. This manager must have permissions to move the value
|
||||
/// @param idSender ID of the giver, delegate or campaign admin that is transferring
|
||||
/// the funds from Pledge to Pledge. This admin must have permissions to move the value
|
||||
/// @param idPledge Id of the pledge that's moving the value
|
||||
/// @param amount Quantity of value that's being moved
|
||||
/// @param idReceiver Destination of the value, can be a giver sending to a giver or
|
||||
|
@ -68,19 +68,19 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
idPledge = normalizePledge(idPledge);
|
||||
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
PledgeManager storage receiver = findManager(idReceiver);
|
||||
PledgeManager storage sender = findManager(idSender);
|
||||
PledgeAdmin storage receiver = findAdmin(idReceiver);
|
||||
PledgeAdmin storage sender = findAdmin(idSender);
|
||||
|
||||
checkManagerOwner(sender);
|
||||
checkAdminOwner(sender);
|
||||
require(n.paymentState == PaymentState.NotPaid);
|
||||
|
||||
// If the sender is the owner
|
||||
if (n.owner == idSender) {
|
||||
if (receiver.managerType == PledgeManagerType.Giver) {
|
||||
if (receiver.adminType == PledgeAdminType.Giver) {
|
||||
transferOwnershipToGiver(idPledge, amount, idReceiver);
|
||||
} else if (receiver.managerType == PledgeManagerType.Campaign) {
|
||||
} else if (receiver.adminType == PledgeAdminType.Campaign) {
|
||||
transferOwnershipToCampaign(idPledge, amount, idReceiver);
|
||||
} else if (receiver.managerType == PledgeManagerType.Delegate) {
|
||||
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||
appendDelegate(idPledge, amount, idReceiver);
|
||||
} else {
|
||||
assert(false);
|
||||
|
@ -93,7 +93,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
if (senderDIdx != NOTFOUND) {
|
||||
|
||||
// If the receiver is another giver
|
||||
if (receiver.managerType == PledgeManagerType.Giver) {
|
||||
if (receiver.adminType == PledgeAdminType.Giver) {
|
||||
// Only accept to change to the original giver to remove all delegates
|
||||
assert(n.owner == idReceiver);
|
||||
undelegate(idPledge, amount, n.delegationChain.length);
|
||||
|
@ -101,7 +101,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
}
|
||||
|
||||
// If the receiver is another delegate
|
||||
if (receiver.managerType == PledgeManagerType.Delegate) {
|
||||
if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||
uint receiverDIdx = getDelegateIdx(n, idReceiver);
|
||||
|
||||
// If the receiver is not in the delegate list
|
||||
|
@ -129,7 +129,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
// If the delegate wants to support a campaign, they undelegate all
|
||||
// the delegates after them in the chain and choose a campaign
|
||||
if (receiver.managerType == PledgeManagerType.Campaign) {
|
||||
if (receiver.adminType == PledgeAdminType.Campaign) {
|
||||
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
|
||||
proposeAssignCampaign(idPledge, amount, idReceiver);
|
||||
return;
|
||||
|
@ -140,7 +140,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
|
||||
/// @notice This method is used to withdraw value from the system. This can be used
|
||||
/// by the givers to avoid committing the donation or by campaign manager to use
|
||||
/// by the givers to avoid committing the donation or by campaign admin to use
|
||||
/// the Ether.
|
||||
/// @param idPledge Id of the pledge that wants to be withdrawn.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawn.
|
||||
|
@ -152,9 +152,9 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
require(n.paymentState == PaymentState.NotPaid);
|
||||
|
||||
PledgeManager storage owner = findManager(n.owner);
|
||||
PledgeAdmin storage owner = findAdmin(n.owner);
|
||||
|
||||
checkManagerOwner(owner);
|
||||
checkAdminOwner(owner);
|
||||
|
||||
uint64 idNewPledge = findPledge(
|
||||
n.owner,
|
||||
|
@ -219,8 +219,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
/// @notice Method called to cancel this campaign.
|
||||
/// @param idCampaign Id of the projct that wants to be canceled.
|
||||
function cancelCampaign(uint64 idCampaign) {
|
||||
PledgeManager storage campaign = findManager(idCampaign);
|
||||
checkManagerOwner(campaign);
|
||||
PledgeAdmin storage campaign = findAdmin(idCampaign);
|
||||
checkAdminOwner(campaign);
|
||||
campaign.canceled = true;
|
||||
|
||||
CancelCampaign(idCampaign);
|
||||
|
@ -232,8 +232,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
|
||||
PledgeManager storage m = findManager(n.owner);
|
||||
checkManagerOwner(m);
|
||||
PledgeAdmin storage m = findAdmin(n.owner);
|
||||
checkAdminOwner(m);
|
||||
|
||||
doTransfer(idPledge, n.oldPledge, amount);
|
||||
}
|
||||
|
@ -444,17 +444,17 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
|
|||
// Plugins
|
||||
/////////////
|
||||
|
||||
function callPlugin(bool before, uint64 managerId, uint64 fromPledge, uint64 toPledge, uint64 context, uint amount) internal returns (uint allowedAmount) {
|
||||
function callPlugin(bool before, uint64 adminId, uint64 fromPledge, uint64 toPledge, uint64 context, uint amount) internal returns (uint allowedAmount) {
|
||||
uint newAmount;
|
||||
allowedAmount = amount;
|
||||
PledgeManager storage manager = findManager(managerId);
|
||||
if ((address(manager.plugin) != 0) && (allowedAmount > 0)) {
|
||||
PledgeAdmin storage admin = findAdmin(adminId);
|
||||
if ((address(admin.plugin) != 0) && (allowedAmount > 0)) {
|
||||
if (before) {
|
||||
newAmount = manager.plugin.beforeTransfer(managerId, fromPledge, toPledge, context, amount);
|
||||
newAmount = admin.plugin.beforeTransfer(adminId, fromPledge, toPledge, context, amount);
|
||||
require(newAmount <= allowedAmount);
|
||||
allowedAmount = newAmount;
|
||||
} else {
|
||||
manager.plugin.afterTransfer(managerId, fromPledge, toPledge, context, amount);
|
||||
admin.plugin.afterTransfer(adminId, fromPledge, toPledge, context, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,13 @@ contract LiquidPledgingBase {
|
|||
uint constant MAX_SUBCAMPAIGN_LEVEL = 20;
|
||||
uint constant MAX_INTERCAMPAIGN_LEVEL = 20;
|
||||
|
||||
enum PledgeManagerType { Giver, Delegate, Campaign }
|
||||
enum PledgeAdminType { Giver, Delegate, Campaign }
|
||||
enum PaymentState { NotPaid, Paying, Paid } // TODO name change NotPaid
|
||||
|
||||
/// @dev This struct defines the details of each the PledgeManager, these
|
||||
/// PledgeManagers can own pledges and act as delegates
|
||||
struct PledgeManager { // TODO name change PledgeManager
|
||||
PledgeManagerType managerType; // Giver, Delegate or Campaign
|
||||
/// @dev This struct defines the details of each the PledgeAdmin, these
|
||||
/// PledgeAdmins can own pledges and act as delegates
|
||||
struct PledgeAdmin { // TODO name change PledgeAdmin
|
||||
PledgeAdminType adminType; // Giver, Delegate or Campaign
|
||||
address addr; // account or contract address for admin
|
||||
string name;
|
||||
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
|
||||
|
@ -32,7 +32,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
struct Pledge {
|
||||
uint amount;
|
||||
uint64 owner; // PledgeManager
|
||||
uint64 owner; // PledgeAdmin
|
||||
uint64[] delegationChain; // list of index numbers
|
||||
uint64 proposedCampaign; // TODO change the name only used for when delegates are precommiting to a campaign
|
||||
uint64 commitTime; // When the proposedCampaign will become the owner
|
||||
|
@ -41,7 +41,7 @@ contract LiquidPledgingBase {
|
|||
}
|
||||
|
||||
Pledge[] pledges;
|
||||
PledgeManager[] managers; //The list of pledgeManagers 0 means there is no manager
|
||||
PledgeAdmin[] admins; //The list of pledgeAdmins 0 means there is no admin
|
||||
Vault public vault;
|
||||
|
||||
// this mapping allows you to search for a specific pledge's index number by the hash of that pledge
|
||||
|
@ -65,24 +65,24 @@ contract LiquidPledgingBase {
|
|||
/// @notice The Constructor creates the `LiquidPledgingBase` on the blockchain
|
||||
/// @param _vault Where the ETH is stored that the pledges represent
|
||||
function LiquidPledgingBase(address _vault) {
|
||||
managers.length = 1; // we reserve the 0 manager
|
||||
admins.length = 1; // we reserve the 0 admin
|
||||
pledges.length = 1; // we reserve the 0 pledge
|
||||
vault = Vault(_vault);
|
||||
}
|
||||
|
||||
|
||||
///////
|
||||
// Managers functions
|
||||
// Adminss functions
|
||||
//////
|
||||
|
||||
/// @notice Creates a giver.
|
||||
function addGiver(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idGiver) {
|
||||
|
||||
idGiver = uint64(managers.length);
|
||||
idGiver = uint64(admins.length);
|
||||
|
||||
managers.push(PledgeManager(
|
||||
PledgeManagerType.Giver,
|
||||
admins.push(PledgeAdmin(
|
||||
PledgeAdminType.Giver,
|
||||
msg.sender,
|
||||
name,
|
||||
commitTime,
|
||||
|
@ -102,8 +102,8 @@ contract LiquidPledgingBase {
|
|||
string newName,
|
||||
uint64 newCommitTime)
|
||||
{
|
||||
PledgeManager storage giver = findManager(idGiver);
|
||||
require(giver.managerType == PledgeManagerType.Giver); //Must be a Giver
|
||||
PledgeAdmin storage giver = findAdmin(idGiver);
|
||||
require(giver.adminType == PledgeAdminType.Giver); //Must be a Giver
|
||||
require(giver.addr == msg.sender); //current addr had to originate this tx
|
||||
giver.addr = newAddr;
|
||||
giver.name = newName;
|
||||
|
@ -116,10 +116,10 @@ contract LiquidPledgingBase {
|
|||
/// @notice Creates a new Delegate
|
||||
function addDelegate(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDelegate) { //TODO return index number
|
||||
|
||||
idDelegate = uint64(managers.length);
|
||||
idDelegate = uint64(admins.length);
|
||||
|
||||
managers.push(PledgeManager(
|
||||
PledgeManagerType.Delegate,
|
||||
admins.push(PledgeAdmin(
|
||||
PledgeAdminType.Delegate,
|
||||
msg.sender,
|
||||
name,
|
||||
commitTime,
|
||||
|
@ -138,8 +138,8 @@ contract LiquidPledgingBase {
|
|||
address newAddr,
|
||||
string newName,
|
||||
uint64 newCommitTime) {
|
||||
PledgeManager storage delegate = findManager(idDelegate);
|
||||
require(delegate.managerType == PledgeManagerType.Delegate);
|
||||
PledgeAdmin storage delegate = findAdmin(idDelegate);
|
||||
require(delegate.adminType == PledgeAdminType.Delegate);
|
||||
require(delegate.addr == msg.sender);
|
||||
delegate.addr = newAddr;
|
||||
delegate.name = newName;
|
||||
|
@ -150,19 +150,19 @@ contract LiquidPledgingBase {
|
|||
event DelegateUpdated(uint64 indexed idDelegate);
|
||||
|
||||
/// @notice Creates a new Campaign
|
||||
function addCampaign(string name, address campaignManager, uint64 parentCampaign, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idCampaign) {
|
||||
function addCampaign(string name, address campaignAdmin, uint64 parentCampaign, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idCampaign) {
|
||||
if (parentCampaign != 0) {
|
||||
PledgeManager storage pm = findManager(parentCampaign);
|
||||
require(pm.managerType == PledgeManagerType.Campaign);
|
||||
PledgeAdmin storage pm = findAdmin(parentCampaign);
|
||||
require(pm.adminType == PledgeAdminType.Campaign);
|
||||
require(pm.addr == msg.sender);
|
||||
require(getCampaignLevel(pm) < MAX_SUBCAMPAIGN_LEVEL);
|
||||
}
|
||||
|
||||
idCampaign = uint64(managers.length);
|
||||
idCampaign = uint64(admins.length);
|
||||
|
||||
managers.push(PledgeManager(
|
||||
PledgeManagerType.Campaign,
|
||||
campaignManager,
|
||||
admins.push(PledgeAdmin(
|
||||
PledgeAdminType.Campaign,
|
||||
campaignAdmin,
|
||||
name,
|
||||
commitTime,
|
||||
parentCampaign,
|
||||
|
@ -182,8 +182,8 @@ contract LiquidPledgingBase {
|
|||
string newName,
|
||||
uint64 newCommitTime)
|
||||
{
|
||||
PledgeManager storage campaign = findManager(idCampaign);
|
||||
require(campaign.managerType == PledgeManagerType.Campaign);
|
||||
PledgeAdmin storage campaign = findAdmin(idCampaign);
|
||||
require(campaign.adminType == PledgeAdminType.Campaign);
|
||||
require(campaign.addr == msg.sender);
|
||||
campaign.addr = newAddr;
|
||||
campaign.name = newName;
|
||||
|
@ -191,7 +191,7 @@ contract LiquidPledgingBase {
|
|||
CampaignUpdated(idCampaign);
|
||||
}
|
||||
|
||||
event CampaignUpdated(uint64 indexed idManager);
|
||||
event CampaignUpdated(uint64 indexed idAdmin);
|
||||
|
||||
|
||||
//////////
|
||||
|
@ -230,17 +230,17 @@ contract LiquidPledgingBase {
|
|||
) {
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
idDelegate = n.delegationChain[idxDelegate - 1];
|
||||
PledgeManager storage delegate = findManager(idDelegate);
|
||||
PledgeAdmin storage delegate = findAdmin(idDelegate);
|
||||
addr = delegate.addr;
|
||||
name = delegate.name;
|
||||
}
|
||||
/// @notice Public constant that states the number of admins in the system
|
||||
function numberOfPledgeManagers() constant returns(uint) {
|
||||
return managers.length - 1;
|
||||
function numberOfPledgeAdmins() constant returns(uint) {
|
||||
return admins.length - 1;
|
||||
}
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
function getPledgeManager(uint64 idManager) constant returns (
|
||||
PledgeManagerType managerType,
|
||||
function getPledgeAdmin(uint64 idAdmin) constant returns (
|
||||
PledgeAdminType adminType,
|
||||
address addr,
|
||||
string name,
|
||||
uint64 commitTime,
|
||||
|
@ -248,8 +248,8 @@ contract LiquidPledgingBase {
|
|||
bool canceled,
|
||||
address plugin)
|
||||
{
|
||||
PledgeManager storage m = findManager(idManager);
|
||||
managerType = m.managerType;
|
||||
PledgeAdmin storage m = findAdmin(idAdmin);
|
||||
adminType = m.adminType;
|
||||
addr = m.addr;
|
||||
name = m.name;
|
||||
commitTime = m.commitTime;
|
||||
|
@ -284,9 +284,9 @@ contract LiquidPledgingBase {
|
|||
return idx;
|
||||
}
|
||||
|
||||
function findManager(uint64 idManager) internal returns (PledgeManager storage) {
|
||||
require(idManager < managers.length);
|
||||
return managers[idManager];
|
||||
function findAdmin(uint64 idAdmin) internal returns (PledgeAdmin storage) {
|
||||
require(idAdmin < admins.length);
|
||||
return admins[idAdmin];
|
||||
}
|
||||
|
||||
function findPledge(uint64 idPledge) internal returns (Pledge storage) {
|
||||
|
@ -317,28 +317,28 @@ contract LiquidPledgingBase {
|
|||
// helper function that returns the max commit time of the owner and all the
|
||||
// delegates
|
||||
function maxCommitTime(Pledge n) internal returns(uint commitTime) {
|
||||
PledgeManager storage m = findManager(n.owner);
|
||||
PledgeAdmin storage m = findAdmin(n.owner);
|
||||
commitTime = m.commitTime;
|
||||
|
||||
for (uint i=0; i<n.delegationChain.length; i++) {
|
||||
m = findManager(n.delegationChain[i]);
|
||||
m = findAdmin(n.delegationChain[i]);
|
||||
if (m.commitTime > commitTime) commitTime = m.commitTime;
|
||||
}
|
||||
}
|
||||
|
||||
// helper function that returns the campaign level solely to check that there
|
||||
// are not too many Campaigns that violate MAX_SUBCAMPAIGNS_LEVEL
|
||||
function getCampaignLevel(PledgeManager m) internal returns(uint) {
|
||||
assert(m.managerType == PledgeManagerType.Campaign);
|
||||
function getCampaignLevel(PledgeAdmin m) internal returns(uint) {
|
||||
assert(m.adminType == PledgeAdminType.Campaign);
|
||||
if (m.parentCampaign == 0) return(1);
|
||||
PledgeManager storage parentNM = findManager(m.parentCampaign);
|
||||
PledgeAdmin storage parentNM = findAdmin(m.parentCampaign);
|
||||
return getCampaignLevel(parentNM);
|
||||
}
|
||||
|
||||
function isCampaignCanceled(uint64 campaignId) constant returns (bool) {
|
||||
PledgeManager storage m = findManager(campaignId);
|
||||
if (m.managerType == PledgeManagerType.Giver) return false;
|
||||
assert(m.managerType == PledgeManagerType.Campaign);
|
||||
PledgeAdmin storage m = findAdmin(campaignId);
|
||||
if (m.adminType == PledgeAdminType.Giver) return false;
|
||||
assert(m.adminType == PledgeAdminType.Campaign);
|
||||
if (m.canceled) return true;
|
||||
if (m.parentCampaign == 0) return false;
|
||||
return isCampaignCanceled(m.parentCampaign);
|
||||
|
@ -349,17 +349,17 @@ contract LiquidPledgingBase {
|
|||
function getOldestPledgeNotCanceled(uint64 idPledge) internal constant returns(uint64) { //todo rename
|
||||
if (idPledge == 0) return 0;
|
||||
Pledge storage n = findPledge(idPledge);
|
||||
PledgeManager storage manager = findManager(n.owner);
|
||||
if (manager.managerType == PledgeManagerType.Giver) return idPledge;
|
||||
PledgeAdmin storage admin = findAdmin(n.owner);
|
||||
if (admin.adminType == PledgeAdminType.Giver) return idPledge;
|
||||
|
||||
assert(manager.managerType == PledgeManagerType.Campaign);
|
||||
assert(admin.adminType == PledgeAdminType.Campaign);
|
||||
|
||||
if (!isCampaignCanceled(n.owner)) return idPledge;
|
||||
|
||||
return getOldestPledgeNotCanceled(n.oldPledge);
|
||||
}
|
||||
|
||||
function checkManagerOwner(PledgeManager m) internal constant {
|
||||
function checkAdminOwner(PledgeAdmin m) internal constant {
|
||||
require((msg.sender == m.addr) || (msg.sender == address(m.plugin)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,29 +57,29 @@ module.exports = (test) => {
|
|||
});
|
||||
};
|
||||
|
||||
LiquidPledging.prototype.$getManager = function (idManager) {
|
||||
const manager = {};
|
||||
return this.getPledgeManager(idManager)
|
||||
LiquidPledging.prototype.$getAdmin = function (idAdmin) {
|
||||
const admin = {};
|
||||
return this.getPledgeAdmin(idAdmin)
|
||||
.then((res) => {
|
||||
if (res.managerType === '0') {
|
||||
manager.type = 'Giver';
|
||||
} else if (res.managerType === '1') {
|
||||
manager.type = 'Delegate';
|
||||
} else if (res.managerType === '2') {
|
||||
manager.type = 'Campaign';
|
||||
if (res.adminType === '0') {
|
||||
admin.type = 'Giver';
|
||||
} else if (res.adminType === '1') {
|
||||
admin.type = 'Delegate';
|
||||
} else if (res.adminType === '2') {
|
||||
admin.type = 'Campaign';
|
||||
} else {
|
||||
manager.type = 'Unknown';
|
||||
admin.type = 'Unknown';
|
||||
}
|
||||
manager.addr = res.addr;
|
||||
manager.name = res.name;
|
||||
manager.commitTime = res.commitTime;
|
||||
if (manager.paymentState === 'Campaign') {
|
||||
manager.parentCampaign = res.parentCampaign;
|
||||
manager.canceled = res.canceled;
|
||||
admin.addr = res.addr;
|
||||
admin.name = res.name;
|
||||
admin.commitTime = res.commitTime;
|
||||
if (admin.paymentState === 'Campaign') {
|
||||
admin.parentCampaign = res.parentCampaign;
|
||||
admin.canceled = res.canceled;
|
||||
}
|
||||
manager.plugin = res.plugin;
|
||||
manager.canceled = res.canceled;
|
||||
return manager;
|
||||
admin.plugin = res.plugin;
|
||||
admin.canceled = res.canceled;
|
||||
return admin;
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -93,20 +93,20 @@ module.exports = (test) => {
|
|||
return Promise.all(promises);
|
||||
});
|
||||
|
||||
const getManagers = () => this.numberOfPledgeManagers()
|
||||
.then((nManagers) => {
|
||||
const getAdmins = () => this.numberOfPledgeAdmins()
|
||||
.then((nAdmins) => {
|
||||
const promises = [];
|
||||
for (let i = 1; i <= nManagers; i += 1) {
|
||||
promises.push(this.$getManager(i));
|
||||
for (let i = 1; i <= nAdmins; i += 1) {
|
||||
promises.push(this.$getAdmin(i));
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
});
|
||||
|
||||
return Promise.all([getPledges(), getManagers()])
|
||||
.then(([pledges, managers]) => ({
|
||||
return Promise.all([getPledges(), getAdmins()])
|
||||
.then(([pledges, admins]) => ({
|
||||
pledges: [null, ...pledges],
|
||||
managers: [null, ...managers],
|
||||
admins: [null, ...admins],
|
||||
}));
|
||||
};
|
||||
|
||||
|
@ -141,7 +141,7 @@ module.exports = (test) => {
|
|||
if (!list[idDelegate]) {
|
||||
list[idDelegate] = {
|
||||
idDelegate,
|
||||
name: this.managers[idDelegate].name,
|
||||
name: this.admins[idDelegate].name,
|
||||
pledges: [],
|
||||
delegtes: [],
|
||||
};
|
||||
|
@ -155,10 +155,10 @@ module.exports = (test) => {
|
|||
idCampaign,
|
||||
pledges: [],
|
||||
commitedCampaigns: [],
|
||||
name: this.managers[idCampaign].name,
|
||||
commitTime: this.managers[idCampaign].commitTime,
|
||||
owner: this.managers[idCampaign].owner,
|
||||
parentCampaign: this.managers[idCampaign].parentCampaign,
|
||||
name: this.admins[idCampaign].name,
|
||||
commitTime: this.admins[idCampaign].commitTime,
|
||||
owner: this.admins[idCampaign].owner,
|
||||
parentCampaign: this.admins[idCampaign].parentCampaign,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -56,7 +56,7 @@ describe('LiquidPledging test', () => {
|
|||
gasLimit: 5200000,
|
||||
total_accounts: 10,
|
||||
});
|
||||
|
||||
|
||||
testrpc.listen(8546, '127.0.0.1');
|
||||
|
||||
web3 = new Web3('ws://localhost:8546');
|
||||
|
@ -76,9 +76,9 @@ describe('LiquidPledging test', () => {
|
|||
}).timeout(6000);
|
||||
it('Should create a giver', async () => {
|
||||
await liquidPledging.addGiver('Giver1', 86400, 0, { from: giver1 });
|
||||
const nManagers = await liquidPledging.numberOfPledgeManagers();
|
||||
assert.equal(nManagers, 1);
|
||||
const res = await liquidPledging.getPledgeManager(1);
|
||||
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
||||
assert.equal(nAdmins, 1);
|
||||
const res = await liquidPledging.getPledgeAdmin(1);
|
||||
assert.equal(res[0], 0); // Giver
|
||||
assert.equal(res[1], giver1);
|
||||
assert.equal(res[2], 'Giver1');
|
||||
|
@ -92,9 +92,9 @@ describe('LiquidPledging test', () => {
|
|||
}).timeout(6000);
|
||||
it('Should create a delegate', async () => {
|
||||
await liquidPledging.addDelegate('Delegate1', 0, 0, { from: delegate1 });
|
||||
const nManagers = await liquidPledging.numberOfPledgeManagers();
|
||||
assert.equal(nManagers, 2);
|
||||
const res = await liquidPledging.getPledgeManager(2);
|
||||
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
||||
assert.equal(nAdmins, 2);
|
||||
const res = await liquidPledging.getPledgeAdmin(2);
|
||||
assert.equal(res[0], 1); // Giver
|
||||
assert.equal(res[1], delegate1);
|
||||
assert.equal(res[2], 'Delegate1');
|
||||
|
@ -117,9 +117,9 @@ describe('LiquidPledging test', () => {
|
|||
it('Should create a 2 campaigns', async () => {
|
||||
await liquidPledging.addCampaign('Campaign1', adminCampaign1, 0, 86400, 0, { from: adminCampaign1 });
|
||||
|
||||
const nManagers = await liquidPledging.numberOfPledgeManagers();
|
||||
assert.equal(nManagers, 3);
|
||||
const res = await liquidPledging.getPledgeManager(3);
|
||||
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
||||
assert.equal(nAdmins, 3);
|
||||
const res = await liquidPledging.getPledgeAdmin(3);
|
||||
assert.equal(res[0], 2); // Campaign type
|
||||
assert.equal(res[1], adminCampaign1);
|
||||
assert.equal(res[2], 'Campaign1');
|
||||
|
@ -129,9 +129,9 @@ describe('LiquidPledging test', () => {
|
|||
|
||||
await liquidPledging.addCampaign('Campaign2', adminCampaign2, 0, 86400, 0, { from: adminCampaign2 });
|
||||
|
||||
const nManagers2 = await liquidPledging.numberOfPledgeManagers();
|
||||
assert.equal(nManagers2, 4);
|
||||
const res4 = await liquidPledging.getPledgeManager(4);
|
||||
const nAdmins2 = await liquidPledging.numberOfPledgeAdmins();
|
||||
assert.equal(nAdmins2, 4);
|
||||
const res4 = await liquidPledging.getPledgeAdmin(4);
|
||||
assert.equal(res4[0], 2); // Campaign type
|
||||
assert.equal(res4[1], adminCampaign2);
|
||||
assert.equal(res4[2], 'Campaign2');
|
||||
|
@ -214,7 +214,7 @@ describe('LiquidPledging test', () => {
|
|||
it('Admin of the campaign1 should be able to cancel campaign1', async () => {
|
||||
await liquidPledging.cancelCampaign(3, { from: adminCampaign1 });
|
||||
const st = await liquidPledging.getState(liquidPledging);
|
||||
assert.equal(st.managers[3].canceled, true);
|
||||
assert.equal(st.admins[3].canceled, true);
|
||||
}).timeout(6000);
|
||||
it('Should not allow to withdraw from a canceled campaign', async () => {
|
||||
const st = await liquidPledging.getState(liquidPledging);
|
||||
|
@ -246,8 +246,8 @@ describe('LiquidPledging test', () => {
|
|||
it('A subcampaign 2a and a delegate2 is created', async () => {
|
||||
await liquidPledging.addCampaign('Campaign2a', adminCampaign2a, 4, 86400, 0, { from: adminCampaign2 });
|
||||
await liquidPledging.addDelegate('Delegate2', 0, 0, { from: delegate2 });
|
||||
const nManagers = await liquidPledging.numberOfPledgeManagers();
|
||||
assert.equal(nManagers, 6);
|
||||
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
||||
assert.equal(nAdmins, 6);
|
||||
}).timeout(6000);
|
||||
it('Campaign 2 delegate in delegate2', async () => {
|
||||
await liquidPledging.transfer(4, 4, utils.toWei(0.02), 6, { from: adminCampaign2 });
|
||||
|
@ -313,13 +313,13 @@ describe('LiquidPledging test', () => {
|
|||
}).timeout(10000);
|
||||
it('Should make a donation and create giver', async () => {
|
||||
const oldNPledges = await liquidPledging.numberOfPledges();
|
||||
const oldNManagers = await liquidPledging.numberOfPledgeManagers();
|
||||
const oldNAdmins = await liquidPledging.numberOfPledgeAdmins();
|
||||
await liquidPledging.donate(0, 1, { from: giver2, value: utils.toWei(1) });
|
||||
const nPledges = await liquidPledging.numberOfPledges();
|
||||
assert.equal(utils.toDecimal(nPledges), utils.toDecimal(oldNPledges) + 1);
|
||||
const nManagers = await liquidPledging.numberOfPledgeManagers();
|
||||
assert.equal(utils.toDecimal(nManagers), utils.toDecimal(oldNManagers) + 1);
|
||||
const res = await liquidPledging.getPledgeManager(nManagers);
|
||||
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
|
||||
assert.equal(utils.toDecimal(nAdmins), utils.toDecimal(oldNAdmins) + 1);
|
||||
const res = await liquidPledging.getPledgeAdmin(nAdmins);
|
||||
assert.equal(res[0], 0); // Giver
|
||||
assert.equal(res[1], giver2);
|
||||
assert.equal(res[2], '');
|
||||
|
|
Loading…
Reference in New Issue