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