Merge pull request #21 from Giveth/campaign_to_project

refactor campaign -> project
This commit is contained in:
Jordi Baylina 2017-10-06 11:05:25 +02:00 committed by GitHub
commit b4b79671ce
18 changed files with 446 additions and 525 deletions

3
.gitignore vendored
View File

@ -3,3 +3,6 @@ node_modules/
.mypy_cache
__pycache__
.idea
*.iml

View File

@ -1,6 +0,0 @@
/* This is an autogenerated file. DO NOT EDIT MANUALLY */
exports.ILiquidPledgingAbi = [{"constant":false,"inputs":[{"name":"idProject","type":"uint64"},{"name":"newCanceler","type":"address"}],"name":"updateProjectCanceler","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"idNote","type":"uint64"},{"name":"amount","type":"uint256"}],"name":"confirmPayment","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"idDelegate","type":"uint64"},{"name":"newAddr","type":"address"},{"name":"newName","type":"string"}],"name":"updateDelegate","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"name","type":"string"}],"name":"addDelegate","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"idDonor","type":"uint64"},{"name":"newAddr","type":"address"},{"name":"newName","type":"string"},{"name":"newCommitTime","type":"uint64"}],"name":"updateDonor","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"idSender","type":"uint64"},{"name":"note","type":"uint64"},{"name":"amount","type":"uint256"},{"name":"idReceiver","type":"uint64"}],"name":"transfer","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"notesAmounts","type":"uint256[]"},{"name":"concept","type":"string"}],"name":"mWithdraw","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"numberOfNotes","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"note","type":"uint64"},{"name":"amount","type":"uint256"},{"name":"concept","type":"string"}],"name":"withdraw","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"idNote","type":"uint64"},{"name":"idxDelegate","type":"uint256"}],"name":"getNoteDelegate","outputs":[{"name":"idDelegate","type":"uint64"},{"name":"addr","type":"address"},{"name":"name","type":"string"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"notesAmounts","type":"uint256[]"}],"name":"mConfirmPayment","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"idManager","type":"uint64"}],"name":"getNoteManager","outputs":[{"name":"managerType","type":"uint8"},{"name":"addr","type":"address"},{"name":"name","type":"string"},{"name":"commitTime","type":"uint64"},{"name":"reviewer","type":"address"},{"name":"canceled","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"name","type":"string"},{"name":"commitTime","type":"uint64"}],"name":"addDonor","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"idProject","type":"uint64"},{"name":"newAddr","type":"address"},{"name":"newName","type":"string"},{"name":"newCommitTime","type":"uint64"}],"name":"updateProject","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"idDonor","type":"uint64"},{"name":"idReceiver","type":"uint64"}],"name":"donate","outputs":[],"payable":true,"type":"function"},{"constant":true,"inputs":[],"name":"numberOfNoteManagers","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"idNote","type":"uint64"}],"name":"getNote","outputs":[{"name":"amount","type":"uint256"},{"name":"owner","type":"uint64"},{"name":"nDelegates","type":"uint64"},{"name":"proposedProject","type":"uint64"},{"name":"commmitTime","type":"uint64"},{"name":"oldNote","type":"uint64"},{"name":"paymentState","type":"uint8"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"idSender","type":"uint64"},{"name":"notesAmounts","type":"uint256[]"},{"name":"idReceiver","type":"uint64"}],"name":"mTransfer","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"idNote","type":"uint64"},{"name":"amount","type":"uint256"}],"name":"cancelPayment","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"name","type":"string"},{"name":"canceler","type":"address"},{"name":"commitTime","type":"uint64"}],"name":"addProject","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"notesAmounts","type":"uint256[]"}],"name":"mCancelPayment","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"idCampaign","type":"int64"}],"name":"cancelProject","outputs":[],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"idMember","type":"uint64"}],"name":"DonorAdded","type":"event"}]
exports.ILiquidPledgingByteCode = "0x"
exports._solcVersion = "0.4.15+commit.bbb8e64f.Emscripten.clang"
exports._sha256 = "0xd8d7025a36f767f7f6d2a238200fde7ddd5aa8e35884215aa8ea7b63a1aeaa5e"

View File

@ -1,6 +1,6 @@
/* This is an autogenerated file. DO NOT EDIT MANUALLY */
exports.ILiquidPledgingPluginAbi = [{"constant":false,"inputs":[{"name":"pledgeManager","type":"uint64"},{"name":"pledgeFrom","type":"uint64"},{"name":"pledgeTo","type":"uint64"},{"name":"context","type":"uint64"},{"name":"amount","type":"uint256"}],"name":"afterTransfer","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"pledgeManager","type":"uint64"},{"name":"pledgeFrom","type":"uint64"},{"name":"pledgeTo","type":"uint64"},{"name":"context","type":"uint64"},{"name":"amount","type":"uint256"}],"name":"beforeTransfer","outputs":[{"name":"maxAllowed","type":"uint256"}],"payable":false,"type":"function"}]
exports.ILiquidPledgingPluginAbi = [{"constant":false,"inputs":[{"name":"pledgeManager","type":"uint64"},{"name":"pledgeFrom","type":"uint64"},{"name":"pledgeTo","type":"uint64"},{"name":"context","type":"uint64"},{"name":"amount","type":"uint256"}],"name":"afterTransfer","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"pledgeManager","type":"uint64"},{"name":"pledgeFrom","type":"uint64"},{"name":"pledgeTo","type":"uint64"},{"name":"context","type":"uint64"},{"name":"amount","type":"uint256"}],"name":"beforeTransfer","outputs":[{"name":"maxAllowed","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"function"}]
exports.ILiquidPledgingPluginByteCode = "0x"
exports._solcVersion = "0.4.15+commit.bbb8e64f.Emscripten.clang"
exports._sha256 = "0x459746b8fd9702f2cc9d65c3f59f37610e76e6ec5739d5bd5ba1c694dba94edd"
exports._solcVersion = "0.4.17+commit.bdeb9e52.Emscripten.clang"
exports._sha256 = "0xdca1f6e8e45033d2b165904df14f39c39500c42395eabcc79e156346438f3259"

View File

@ -11,13 +11,13 @@ contract ILiquidPledgingPlugin {
/// 1 -> Plugin for the first delegate transferring pledge to another party
/// 2 -> Plugin for the second delegate transferring pledge to another party
/// ...
/// 255 -> Plugin for the intendedCampaign transferring pledge to another party
/// 255 -> Plugin for the intendedProject transferring pledge to another party
///
/// 256 -> Plugin for the owner receiving pledge to another party
/// 257 -> Plugin for the first delegate receiving pledge to another party
/// 258 -> Plugin for the second delegate receiving pledge to another party
/// ...
/// 511 -> Plugin for the intendedCampaign receiving pledge to another party
/// 511 -> Plugin for the intendedProject receiving pledge to another party
function beforeTransfer(
uint64 pledgeManager,
uint64 pledgeFrom,

View File

@ -1,76 +0,0 @@
//File: ./contracts/ILiquidPledging.sol
pragma solidity ^0.4.11;
contract ILiquidPledging {
// TODO: make this enum its own contract... or at least make it so that an owner
// can add a new NoteManagerType
enum NoteManagerType { Donor, Delegate, Project}
enum PaymentState {NotPaid, Paying, Paid}
function numberOfNotes() constant returns (uint);
function getNote(uint64 idNote) constant returns(
uint amount,
uint64 owner,
uint64 nDelegates,
uint64 proposedProject,
uint64 commmitTime,
uint64 oldNote,
PaymentState paymentState
);
function getNoteDelegate(uint64 idNote, uint idxDelegate) constant returns(
uint64 idDelegate,
address addr,
string name
);
function numberOfNoteManagers() constant returns(uint);
function getNoteManager(uint64 idManager) constant returns (
NoteManagerType managerType,
address addr,
string name,
uint64 commitTime,
address reviewer,
bool canceled);
event DonorAdded(uint64 indexed idMember);
function addDonor(string name, uint64 commitTime);
function updateDonor(
uint64 idDonor,
address newAddr,
string newName,
uint64 newCommitTime);
function addDelegate(string name);
function updateDelegate(uint64 idDelegate, address newAddr, string newName);
function addProject(string name, address canceler, uint64 commitTime) ;
function updateProject(uint64 idProject, address newAddr, string newName, uint64 newCommitTime);
function updateProjectCanceler(uint64 idProject, address newCanceler);
function donate(uint64 idDonor, uint64 idReceiver) payable;
/// @param idSender idDonor or idDelegate that executes the action
/// @param idReceiver idDonor or idCampaign that wants to be transfered.
/// @param note piece That wants to be transfered.
/// @param amount quantity of the state that wants to be transfered.
function transfer(uint64 idSender, uint64 note, uint amount, uint64 idReceiver);
function mTransfer(uint64 idSender, uint[] notesAmounts, uint64 idReceiver);
function withdraw(uint64 note, uint amount, string concept);
function mWithdraw(uint[] notesAmounts, string concept);
function confirmPayment(uint64 idNote, uint amount);
function mConfirmPayment(uint[] notesAmounts);
function cancelPayment(uint64 idNote, uint amount);
function mCancelPayment(uint[] notesAmounts);
function cancelProject(int64 idCampaign);
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -11,13 +11,13 @@ contract ILiquidPledgingPlugin {
/// 1 -> Plugin for the first delegate transferring pledge to another party
/// 2 -> Plugin for the second delegate transferring pledge to another party
/// ...
/// 255 -> Plugin for the intendedCampaign transferring pledge to another party
/// 255 -> Plugin for the intendedProject transferring pledge to another party
///
/// 256 -> Plugin for the owner receiving pledge to another party
/// 257 -> Plugin for the first delegate receiving pledge to another party
/// 258 -> Plugin for the second delegate receiving pledge to another party
/// ...
/// 511 -> Plugin for the intendedCampaign receiving pledge to another party
/// 511 -> Plugin for the intendedProject receiving pledge to another party
function beforeTransfer(
uint64 pledgeManager,
uint64 pledgeFrom,
@ -48,22 +48,22 @@ contract Vault {
contract LiquidPledgingBase {
// Limits inserted to prevent large loops that could prevent canceling
uint constant MAX_DELEGATES = 20;
uint constant MAX_SUBCAMPAIGN_LEVEL = 20;
uint constant MAX_INTERCAMPAIGN_LEVEL = 20;
uint constant MAX_SUBPROJECT_LEVEL = 20;
uint constant MAX_INTERPROJECT_LEVEL = 20;
enum PledgeAdminType { Giver, Delegate, Campaign }
enum PledgeAdminType { Giver, Delegate, Project }
enum PaymentState { Pledged, Paying, Paid } // TODO name change Pledged
/// @dev This struct defines the details of each the PledgeAdmin, these
/// PledgeAdmins can own pledges and act as delegates
struct PledgeAdmin { // TODO name change PledgeAdmin
PledgeAdminType adminType; // Giver, Delegate or Campaign
PledgeAdminType adminType; // Giver, Delegate or Project
address addr; // account or contract address for admin
string name;
string url;
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
uint64 parentCampaign; // Only for campaigns
bool canceled; //Always false except for canceled campaigns
uint64 parentProject; // Only for projects
bool canceled; //Always false except for canceled projects
ILiquidPledgingPlugin plugin; // if the plugin is 0x0 then nothing happens if its a contract address than that smart contract is called via the milestone contract
}
@ -71,8 +71,8 @@ contract LiquidPledgingBase {
uint amount;
uint64 owner; // PledgeAdmin
uint64[] delegationChain; // list of index numbers
uint64 intendedCampaign; // TODO change the name only used for when delegates are precommiting to a campaign
uint64 commitTime; // When the intendedCampaign will become the owner
uint64 intendedProject; // TODO change the name only used for when delegates are precommiting to a project
uint64 commitTime; // When the intendedProject will become the owner
uint64 oldPledge; // this points to the Pledge[] index that the Pledge was derived from
PaymentState paymentState;
}
@ -192,52 +192,52 @@ contract LiquidPledgingBase {
event DelegateUpdated(uint64 indexed idDelegate);
/// @notice Creates a new Campaign
function addCampaign(string name, string url, address campaignAdmin, uint64 parentCampaign, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idCampaign) {
if (parentCampaign != 0) {
PledgeAdmin storage pa = findAdmin(parentCampaign);
require(pa.adminType == PledgeAdminType.Campaign);
/// @notice Creates a new Project
function addProject(string name, string url, address projectAdmin, uint64 parentProject, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idProject) {
if (parentProject != 0) {
PledgeAdmin storage pa = findAdmin(parentProject);
require(pa.adminType == PledgeAdminType.Project);
require(pa.addr == msg.sender);
require(getCampaignLevel(pa) < MAX_SUBCAMPAIGN_LEVEL);
require(getProjectLevel(pa) < MAX_SUBPROJECT_LEVEL);
}
idCampaign = uint64(admins.length);
idProject = uint64(admins.length);
admins.push(PledgeAdmin(
PledgeAdminType.Campaign,
campaignAdmin,
PledgeAdminType.Project,
projectAdmin,
name,
url,
commitTime,
parentCampaign,
parentProject,
false,
plugin));
CampaignAdded(idCampaign);
ProjectAdded(idProject);
}
event CampaignAdded(uint64 indexed idCampaign);
event ProjectAdded(uint64 indexed idProject);
///@notice Changes the address, name or commitTime associated with a specific Campaign
function updateCampaign(
uint64 idCampaign,
///@notice Changes the address, name or commitTime associated with a specific Project
function updateProject(
uint64 idProject,
address newAddr,
string newName,
string newUrl,
uint64 newCommitTime)
{
PledgeAdmin storage campaign = findAdmin(idCampaign);
require(campaign.adminType == PledgeAdminType.Campaign);
require(campaign.addr == msg.sender);
campaign.addr = newAddr;
campaign.name = newName;
campaign.url = newUrl;
campaign.commitTime = newCommitTime;
CampaignUpdated(idCampaign);
PledgeAdmin storage project = findAdmin(idProject);
require(project.adminType == PledgeAdminType.Project);
require(project.addr == msg.sender);
project.addr = newAddr;
project.name = newName;
project.url = newUrl;
project.commitTime = newCommitTime;
ProjectUpdated(idProject);
}
event CampaignUpdated(uint64 indexed idAdmin);
event ProjectUpdated(uint64 indexed idAdmin);
//////////
@ -253,7 +253,7 @@ contract LiquidPledgingBase {
uint amount,
uint64 owner,
uint64 nDelegates,
uint64 intendedCampaign,
uint64 intendedProject,
uint64 commitTime,
uint64 oldPledge,
PaymentState paymentState
@ -262,7 +262,7 @@ contract LiquidPledgingBase {
amount = n.amount;
owner = n.owner;
nDelegates = uint64(n.delegationChain.length);
intendedCampaign = n.intendedCampaign;
intendedProject = n.intendedProject;
commitTime = n.commitTime;
oldPledge = n.oldPledge;
paymentState = n.paymentState;
@ -291,7 +291,7 @@ contract LiquidPledgingBase {
string name,
string url,
uint64 commitTime,
uint64 parentCampaign,
uint64 parentProject,
bool canceled,
address plugin)
{
@ -301,7 +301,7 @@ contract LiquidPledgingBase {
name = m.name;
url = m.url;
commitTime = m.commitTime;
parentCampaign = m.parentCampaign;
parentProject = m.parentProject;
canceled = m.canceled;
plugin = address(m.plugin);
}
@ -317,18 +317,18 @@ contract LiquidPledgingBase {
function findOrCreatePledge(
uint64 owner,
uint64[] delegationChain,
uint64 intendedCampaign,
uint64 intendedProject,
uint64 commitTime,
uint64 oldPledge,
PaymentState paid
) internal returns (uint64)
{
bytes32 hPledge = sha3(owner, delegationChain, intendedCampaign, commitTime, oldPledge, paid);
bytes32 hPledge = sha3(owner, delegationChain, intendedProject, commitTime, oldPledge, paid);
uint64 idx = hPledge2idx[hPledge];
if (idx > 0) return idx;
idx = uint64(pledges.length);
hPledge2idx[hPledge] = idx;
pledges.push(Pledge(0, owner, delegationChain, intendedCampaign, commitTime, oldPledge, paid));
pledges.push(Pledge(0, owner, delegationChain, intendedProject, commitTime, oldPledge, paid));
return idx;
}
@ -355,7 +355,7 @@ contract LiquidPledgingBase {
}
// helper function that returns the pledge level solely to check that transfers
// between Campaigns not violate MAX_INTERCAMPAIGN_LEVEL
// between Projects not violate MAX_INTERPROJECT_LEVEL
function getPledgeLevel(Pledge n) internal returns(uint) {
if (n.oldPledge == 0) return 0; //changed
Pledge storage oldN = findPledge(n.oldPledge);
@ -374,25 +374,25 @@ contract LiquidPledgingBase {
}
}
// helper function that returns the campaign level solely to check that there
// are not too many Campaigns that violate MAX_SUBCAMPAIGNS_LEVEL
function getCampaignLevel(PledgeAdmin m) internal returns(uint) {
assert(m.adminType == PledgeAdminType.Campaign);
if (m.parentCampaign == 0) return(1);
PledgeAdmin storage parentNM = findAdmin(m.parentCampaign);
return getCampaignLevel(parentNM);
// helper function that returns the project level solely to check that there
// are not too many Projects that violate MAX_SUBCAMPAIGNS_LEVEL
function getProjectLevel(PledgeAdmin m) internal returns(uint) {
assert(m.adminType == PledgeAdminType.Project);
if (m.parentProject == 0) return(1);
PledgeAdmin storage parentNM = findAdmin(m.parentProject);
return getProjectLevel(parentNM);
}
function isCampaignCanceled(uint64 campaignId) constant returns (bool) {
PledgeAdmin storage m = findAdmin(campaignId);
function isProjectCanceled(uint64 projectId) constant returns (bool) {
PledgeAdmin storage m = findAdmin(projectId);
if (m.adminType == PledgeAdminType.Giver) return false;
assert(m.adminType == PledgeAdminType.Campaign);
assert(m.adminType == PledgeAdminType.Project);
if (m.canceled) return true;
if (m.parentCampaign == 0) return false;
return isCampaignCanceled(m.parentCampaign);
if (m.parentProject == 0) return false;
return isProjectCanceled(m.parentProject);
}
// @notice A helper function for canceling campaigns
// @notice A helper function for canceling projects
// @param idPledge the pledge that may or may not be canceled
function getOldestPledgeNotCanceled(uint64 idPledge) internal constant returns(uint64) { //todo rename
if (idPledge == 0) return 0;
@ -400,9 +400,9 @@ contract LiquidPledgingBase {
PledgeAdmin storage admin = findAdmin(n.owner);
if (admin.adminType == PledgeAdminType.Giver) return idPledge;
assert(admin.adminType == PledgeAdminType.Campaign);
assert(admin.adminType == PledgeAdminType.Project);
if (!isCampaignCanceled(n.owner)) return idPledge;
if (!isProjectCanceled(n.owner)) return idPledge;
return getOldestPledgeNotCanceled(n.oldPledge);
}

File diff suppressed because one or more lines are too long

View File

@ -11,13 +11,13 @@ contract ILiquidPledgingPlugin {
/// 1 -> Plugin for the first delegate transferring pledge to another party
/// 2 -> Plugin for the second delegate transferring pledge to another party
/// ...
/// 255 -> Plugin for the intendedCampaign transferring pledge to another party
/// 255 -> Plugin for the intendedProject transferring pledge to another party
///
/// 256 -> Plugin for the owner receiving pledge to another party
/// 257 -> Plugin for the first delegate receiving pledge to another party
/// 258 -> Plugin for the second delegate receiving pledge to another party
/// ...
/// 511 -> Plugin for the intendedCampaign receiving pledge to another party
/// 511 -> Plugin for the intendedProject receiving pledge to another party
function beforeTransfer(
uint64 pledgeManager,
uint64 pledgeFrom,
@ -48,22 +48,22 @@ contract Vault {
contract LiquidPledgingBase {
// Limits inserted to prevent large loops that could prevent canceling
uint constant MAX_DELEGATES = 20;
uint constant MAX_SUBCAMPAIGN_LEVEL = 20;
uint constant MAX_INTERCAMPAIGN_LEVEL = 20;
uint constant MAX_SUBPROJECT_LEVEL = 20;
uint constant MAX_INTERPROJECT_LEVEL = 20;
enum PledgeAdminType { Giver, Delegate, Campaign }
enum PledgeAdminType { Giver, Delegate, Project }
enum PaymentState { Pledged, Paying, Paid } // TODO name change Pledged
/// @dev This struct defines the details of each the PledgeAdmin, these
/// PledgeAdmins can own pledges and act as delegates
struct PledgeAdmin { // TODO name change PledgeAdmin
PledgeAdminType adminType; // Giver, Delegate or Campaign
PledgeAdminType adminType; // Giver, Delegate or Project
address addr; // account or contract address for admin
string name;
string url;
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
uint64 parentCampaign; // Only for campaigns
bool canceled; //Always false except for canceled campaigns
uint64 parentProject; // Only for projects
bool canceled; //Always false except for canceled projects
ILiquidPledgingPlugin plugin; // if the plugin is 0x0 then nothing happens if its a contract address than that smart contract is called via the milestone contract
}
@ -71,8 +71,8 @@ contract LiquidPledgingBase {
uint amount;
uint64 owner; // PledgeAdmin
uint64[] delegationChain; // list of index numbers
uint64 intendedCampaign; // TODO change the name only used for when delegates are precommiting to a campaign
uint64 commitTime; // When the intendedCampaign will become the owner
uint64 intendedProject; // TODO change the name only used for when delegates are precommiting to a project
uint64 commitTime; // When the intendedProject will become the owner
uint64 oldPledge; // this points to the Pledge[] index that the Pledge was derived from
PaymentState paymentState;
}
@ -192,52 +192,52 @@ contract LiquidPledgingBase {
event DelegateUpdated(uint64 indexed idDelegate);
/// @notice Creates a new Campaign
function addCampaign(string name, string url, address campaignAdmin, uint64 parentCampaign, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idCampaign) {
if (parentCampaign != 0) {
PledgeAdmin storage pa = findAdmin(parentCampaign);
require(pa.adminType == PledgeAdminType.Campaign);
/// @notice Creates a new Project
function addProject(string name, string url, address projectAdmin, uint64 parentProject, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idProject) {
if (parentProject != 0) {
PledgeAdmin storage pa = findAdmin(parentProject);
require(pa.adminType == PledgeAdminType.Project);
require(pa.addr == msg.sender);
require(getCampaignLevel(pa) < MAX_SUBCAMPAIGN_LEVEL);
require(getProjectLevel(pa) < MAX_SUBPROJECT_LEVEL);
}
idCampaign = uint64(admins.length);
idProject = uint64(admins.length);
admins.push(PledgeAdmin(
PledgeAdminType.Campaign,
campaignAdmin,
PledgeAdminType.Project,
projectAdmin,
name,
url,
commitTime,
parentCampaign,
parentProject,
false,
plugin));
CampaignAdded(idCampaign);
ProjectAdded(idProject);
}
event CampaignAdded(uint64 indexed idCampaign);
event ProjectAdded(uint64 indexed idProject);
///@notice Changes the address, name or commitTime associated with a specific Campaign
function updateCampaign(
uint64 idCampaign,
///@notice Changes the address, name or commitTime associated with a specific Project
function updateProject(
uint64 idProject,
address newAddr,
string newName,
string newUrl,
uint64 newCommitTime)
{
PledgeAdmin storage campaign = findAdmin(idCampaign);
require(campaign.adminType == PledgeAdminType.Campaign);
require(campaign.addr == msg.sender);
campaign.addr = newAddr;
campaign.name = newName;
campaign.url = newUrl;
campaign.commitTime = newCommitTime;
CampaignUpdated(idCampaign);
PledgeAdmin storage project = findAdmin(idProject);
require(project.adminType == PledgeAdminType.Project);
require(project.addr == msg.sender);
project.addr = newAddr;
project.name = newName;
project.url = newUrl;
project.commitTime = newCommitTime;
ProjectUpdated(idProject);
}
event CampaignUpdated(uint64 indexed idAdmin);
event ProjectUpdated(uint64 indexed idAdmin);
//////////
@ -253,7 +253,7 @@ contract LiquidPledgingBase {
uint amount,
uint64 owner,
uint64 nDelegates,
uint64 intendedCampaign,
uint64 intendedProject,
uint64 commitTime,
uint64 oldPledge,
PaymentState paymentState
@ -262,7 +262,7 @@ contract LiquidPledgingBase {
amount = n.amount;
owner = n.owner;
nDelegates = uint64(n.delegationChain.length);
intendedCampaign = n.intendedCampaign;
intendedProject = n.intendedProject;
commitTime = n.commitTime;
oldPledge = n.oldPledge;
paymentState = n.paymentState;
@ -291,7 +291,7 @@ contract LiquidPledgingBase {
string name,
string url,
uint64 commitTime,
uint64 parentCampaign,
uint64 parentProject,
bool canceled,
address plugin)
{
@ -301,7 +301,7 @@ contract LiquidPledgingBase {
name = m.name;
url = m.url;
commitTime = m.commitTime;
parentCampaign = m.parentCampaign;
parentProject = m.parentProject;
canceled = m.canceled;
plugin = address(m.plugin);
}
@ -317,18 +317,18 @@ contract LiquidPledgingBase {
function findOrCreatePledge(
uint64 owner,
uint64[] delegationChain,
uint64 intendedCampaign,
uint64 intendedProject,
uint64 commitTime,
uint64 oldPledge,
PaymentState paid
) internal returns (uint64)
{
bytes32 hPledge = sha3(owner, delegationChain, intendedCampaign, commitTime, oldPledge, paid);
bytes32 hPledge = sha3(owner, delegationChain, intendedProject, commitTime, oldPledge, paid);
uint64 idx = hPledge2idx[hPledge];
if (idx > 0) return idx;
idx = uint64(pledges.length);
hPledge2idx[hPledge] = idx;
pledges.push(Pledge(0, owner, delegationChain, intendedCampaign, commitTime, oldPledge, paid));
pledges.push(Pledge(0, owner, delegationChain, intendedProject, commitTime, oldPledge, paid));
return idx;
}
@ -355,7 +355,7 @@ contract LiquidPledgingBase {
}
// helper function that returns the pledge level solely to check that transfers
// between Campaigns not violate MAX_INTERCAMPAIGN_LEVEL
// between Projects not violate MAX_INTERPROJECT_LEVEL
function getPledgeLevel(Pledge n) internal returns(uint) {
if (n.oldPledge == 0) return 0; //changed
Pledge storage oldN = findPledge(n.oldPledge);
@ -374,25 +374,25 @@ contract LiquidPledgingBase {
}
}
// helper function that returns the campaign level solely to check that there
// are not too many Campaigns that violate MAX_SUBCAMPAIGNS_LEVEL
function getCampaignLevel(PledgeAdmin m) internal returns(uint) {
assert(m.adminType == PledgeAdminType.Campaign);
if (m.parentCampaign == 0) return(1);
PledgeAdmin storage parentNM = findAdmin(m.parentCampaign);
return getCampaignLevel(parentNM);
// helper function that returns the project level solely to check that there
// are not too many Projects that violate MAX_SUBCAMPAIGNS_LEVEL
function getProjectLevel(PledgeAdmin m) internal returns(uint) {
assert(m.adminType == PledgeAdminType.Project);
if (m.parentProject == 0) return(1);
PledgeAdmin storage parentNM = findAdmin(m.parentProject);
return getProjectLevel(parentNM);
}
function isCampaignCanceled(uint64 campaignId) constant returns (bool) {
PledgeAdmin storage m = findAdmin(campaignId);
function isProjectCanceled(uint64 projectId) constant returns (bool) {
PledgeAdmin storage m = findAdmin(projectId);
if (m.adminType == PledgeAdminType.Giver) return false;
assert(m.adminType == PledgeAdminType.Campaign);
assert(m.adminType == PledgeAdminType.Project);
if (m.canceled) return true;
if (m.parentCampaign == 0) return false;
return isCampaignCanceled(m.parentCampaign);
if (m.parentProject == 0) return false;
return isProjectCanceled(m.parentProject);
}
// @notice A helper function for canceling campaigns
// @notice A helper function for canceling projects
// @param idPledge the pledge that may or may not be canceled
function getOldestPledgeNotCanceled(uint64 idPledge) internal constant returns(uint64) { //todo rename
if (idPledge == 0) return 0;
@ -400,9 +400,9 @@ contract LiquidPledgingBase {
PledgeAdmin storage admin = findAdmin(n.owner);
if (admin.adminType == PledgeAdminType.Giver) return idPledge;
assert(admin.adminType == PledgeAdminType.Campaign);
assert(admin.adminType == PledgeAdminType.Project);
if (!isCampaignCanceled(n.owner)) return idPledge;
if (!isProjectCanceled(n.owner)) return idPledge;
return getOldestPledgeNotCanceled(n.oldPledge);
}
@ -435,7 +435,7 @@ contract LiquidPledging is LiquidPledgingBase {
/// transfer is done to the idReceiver
/// @param idGiver Identifier of the giver thats donating.
/// @param idReceiver To whom it's transfered. Can be the same giver, another
/// giver, a delegate or a campaign
/// giver, a delegate or a project
function donate(uint64 idGiver, uint64 idReceiver) payable {
if (idGiver == 0) {
@ -472,12 +472,12 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
/// @notice Moves value between pledges
/// @param idSender ID of the giver, delegate or campaign admin that is transferring
/// @param idSender ID of the giver, delegate or project admin that is transferring
/// the funds from Pledge to Pledge. This admin must have permissions to move the value
/// @param idPledge Id of the pledge that's moving the value
/// @param amount Quantity of value that's being moved
/// @param idReceiver Destination of the value, can be a giver sending to a giver or
/// a delegate, a delegate to another delegate or a campaign to precommit it to that campaign
/// a delegate, a delegate to another delegate or a project to precommit it to that project
function transfer(uint64 idSender, uint64 idPledge, uint amount, uint64 idReceiver) {
idPledge = normalizePledge(idPledge);
@ -493,8 +493,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
if (n.owner == idSender) {
if (receiver.adminType == PledgeAdminType.Giver) {
transferOwnershipToGiver(idPledge, amount, idReceiver);
} else if (receiver.adminType == PledgeAdminType.Campaign) {
transferOwnershipToCampaign(idPledge, amount, idReceiver);
} else if (receiver.adminType == PledgeAdminType.Project) {
transferOwnershipToProject(idPledge, amount, idReceiver);
} else if (receiver.adminType == PledgeAdminType.Delegate) {
appendDelegate(idPledge, amount, idReceiver);
} else {
@ -542,11 +542,11 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
return;
}
// If the delegate wants to support a campaign, they undelegate all
// the delegates after them in the chain and choose a campaign
if (receiver.adminType == PledgeAdminType.Campaign) {
// If the delegate wants to support a project, they undelegate all
// the delegates after them in the chain and choose a project
if (receiver.adminType == PledgeAdminType.Project) {
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
proposeAssignCampaign(idPledge, amount, idReceiver);
proposeAssignProject(idPledge, amount, idReceiver);
return;
}
}
@ -555,7 +555,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
/// @notice This method is used to withdraw value from the system. This can be used
/// by the givers to avoid committing the donation or by campaign admin to use
/// by the givers to avoid committing the donation or by project admin to use
/// the Ether.
/// @param idPledge Id of the pledge that wants to be withdrawn.
/// @param amount Quantity of Ether that wants to be withdrawn.
@ -593,7 +593,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
require(n.paymentState == PaymentState.Paying);
// Check the campaign is not canceled in the while.
// Check the project is not canceled in the while.
require(getOldestPledgeNotCanceled(idPledge) == idPledge);
uint64 idNewPledge = findOrCreatePledge(
@ -616,7 +616,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
require(n.paymentState == PaymentState.Paying); //TODO change to revert
// When a payment is canceled, never is assigned to a campaign.
// When a payment is canceled, never is assigned to a project.
uint64 oldPledge = findOrCreatePledge(
n.owner,
n.delegationChain,
@ -631,14 +631,14 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
doTransfer(idPledge, oldPledge, amount);
}
/// @notice Method called to cancel this campaign.
/// @param idCampaign Id of the projct that wants to be canceled.
function cancelCampaign(uint64 idCampaign) {
PledgeAdmin storage campaign = findAdmin(idCampaign);
checkAdminOwner(campaign);
campaign.canceled = true;
/// @notice Method called to cancel this project.
/// @param idProject Id of the projct that wants to be canceled.
function cancelProject(uint64 idProject) {
PledgeAdmin storage project = findAdmin(idProject);
checkAdminOwner(project);
project.canceled = true;
CancelCampaign(idCampaign);
CancelProject(idProject);
}
@ -711,11 +711,11 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
// this function is obvious, but it can also be called to undelegate everyone
// by setting yourself as the idReceiver
function transferOwnershipToCampaign(uint64 idPledge, uint amount, uint64 idReceiver) internal {
function transferOwnershipToProject(uint64 idPledge, uint amount, uint64 idReceiver) internal {
Pledge storage n = findPledge(idPledge);
require(getPledgeLevel(n) < MAX_INTERCAMPAIGN_LEVEL);
require(!isCampaignCanceled(idReceiver));
require(getPledgeLevel(n) < MAX_INTERPROJECT_LEVEL);
require(!isProjectCanceled(idReceiver));
uint64 oldPledge = findOrCreatePledge(
n.owner,
@ -785,11 +785,11 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
}
function proposeAssignCampaign(uint64 idPledge, uint amount, uint64 idReceiver) internal {// Todo rename
function proposeAssignProject(uint64 idPledge, uint amount, uint64 idReceiver) internal {// Todo rename
Pledge storage n = findPledge(idPledge);
require(getPledgeLevel(n) < MAX_SUBCAMPAIGN_LEVEL);
require(!isCampaignCanceled(idReceiver));
require(getPledgeLevel(n) < MAX_SUBPROJECT_LEVEL);
require(!isProjectCanceled(idReceiver));
uint64 toPledge = findOrCreatePledge(
n.owner,
@ -816,10 +816,10 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
}
// This function does 2 things, #1: it checks to make sure that the pledges are correct
// if the a pledged campaign has already been committed then it changes the owner
// to be the proposed campaign (Pledge that the UI will have to read the commit time and manually
// if the a pledged project has already been committed then it changes the owner
// to be the proposed project (Pledge that the UI will have to read the commit time and manually
// do what this function does to the pledge for the end user at the expiration of the commitTime)
// #2: It checks to make sure that if there has been a cancellation in the chain of campaigns,
// #2: It checks to make sure that if there has been a cancellation in the chain of projects,
// then it adjusts the pledge's owner appropriately.
// This call can be called from any body at any time on any pledge. In general it can be called
// to force the calls of the affected plugins, which also need to be predicted by the UI
@ -829,8 +829,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
// Check to make sure this pledge hasnt already been used or is in the process of being used
if (n.paymentState != PaymentState.Pledged) return idPledge;
// First send to a campaign if it's proposed and commited
if ((n.intendedCampaign > 0) && ( getTime() > n.commitTime)) {
// First send to a project if it's proposed and commited
if ((n.intendedProject > 0) && ( getTime() > n.commitTime)) {
uint64 oldPledge = findOrCreatePledge(
n.owner,
n.delegationChain,
@ -839,7 +839,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
n.oldPledge,
PaymentState.Pledged);
uint64 toPledge = findOrCreatePledge(
n.intendedCampaign,
n.intendedProject,
new uint64[](0),
0,
0,
@ -888,8 +888,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
allowedAmount = callPlugin(before, n.delegationChain[i], fromPledge, toPledge, offset + i+1, allowedAmount);
}
if (n.intendedCampaign > 0) {
allowedAmount = callPlugin(before, n.intendedCampaign, fromPledge, toPledge, offset + 255, allowedAmount);
if (n.intendedProject > 0) {
allowedAmount = callPlugin(before, n.intendedProject, fromPledge, toPledge, offset + 255, allowedAmount);
}
}
@ -909,7 +909,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
}
event Transfer(uint64 indexed from, uint64 indexed to, uint amount);
event CancelCampaign(uint64 indexed idCampaign);
event CancelProject(uint64 indexed idProject);
}

View File

@ -11,13 +11,13 @@ contract ILiquidPledgingPlugin {
/// 1 -> Plugin for the first delegate transferring pledge to another party
/// 2 -> Plugin for the second delegate transferring pledge to another party
/// ...
/// 255 -> Plugin for the intendedCampaign transferring pledge to another party
/// 255 -> Plugin for the intendedProject transferring pledge to another party
///
/// 256 -> Plugin for the owner receiving pledge to another party
/// 257 -> Plugin for the first delegate receiving pledge to another party
/// 258 -> Plugin for the second delegate receiving pledge to another party
/// ...
/// 511 -> Plugin for the intendedCampaign receiving pledge to another party
/// 511 -> Plugin for the intendedProject receiving pledge to another party
function beforeTransfer(
uint64 pledgeManager,
uint64 pledgeFrom,
@ -48,22 +48,22 @@ contract Vault {
contract LiquidPledgingBase {
// Limits inserted to prevent large loops that could prevent canceling
uint constant MAX_DELEGATES = 20;
uint constant MAX_SUBCAMPAIGN_LEVEL = 20;
uint constant MAX_INTERCAMPAIGN_LEVEL = 20;
uint constant MAX_SUBPROJECT_LEVEL = 20;
uint constant MAX_INTERPROJECT_LEVEL = 20;
enum PledgeAdminType { Giver, Delegate, Campaign }
enum PledgeAdminType { Giver, Delegate, Project }
enum PaymentState { Pledged, Paying, Paid } // TODO name change Pledged
/// @dev This struct defines the details of each the PledgeAdmin, these
/// PledgeAdmins can own pledges and act as delegates
struct PledgeAdmin { // TODO name change PledgeAdmin
PledgeAdminType adminType; // Giver, Delegate or Campaign
PledgeAdminType adminType; // Giver, Delegate or Project
address addr; // account or contract address for admin
string name;
string url;
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
uint64 parentCampaign; // Only for campaigns
bool canceled; //Always false except for canceled campaigns
uint64 parentProject; // Only for projects
bool canceled; //Always false except for canceled projects
ILiquidPledgingPlugin plugin; // if the plugin is 0x0 then nothing happens if its a contract address than that smart contract is called via the milestone contract
}
@ -71,8 +71,8 @@ contract LiquidPledgingBase {
uint amount;
uint64 owner; // PledgeAdmin
uint64[] delegationChain; // list of index numbers
uint64 intendedCampaign; // TODO change the name only used for when delegates are precommiting to a campaign
uint64 commitTime; // When the intendedCampaign will become the owner
uint64 intendedProject; // TODO change the name only used for when delegates are precommiting to a project
uint64 commitTime; // When the intendedProject will become the owner
uint64 oldPledge; // this points to the Pledge[] index that the Pledge was derived from
PaymentState paymentState;
}
@ -192,52 +192,52 @@ contract LiquidPledgingBase {
event DelegateUpdated(uint64 indexed idDelegate);
/// @notice Creates a new Campaign
function addCampaign(string name, string url, address campaignAdmin, uint64 parentCampaign, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idCampaign) {
if (parentCampaign != 0) {
PledgeAdmin storage pa = findAdmin(parentCampaign);
require(pa.adminType == PledgeAdminType.Campaign);
/// @notice Creates a new Project
function addProject(string name, string url, address projectAdmin, uint64 parentProject, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idProject) {
if (parentProject != 0) {
PledgeAdmin storage pa = findAdmin(parentProject);
require(pa.adminType == PledgeAdminType.Project);
require(pa.addr == msg.sender);
require(getCampaignLevel(pa) < MAX_SUBCAMPAIGN_LEVEL);
require(getProjectLevel(pa) < MAX_SUBPROJECT_LEVEL);
}
idCampaign = uint64(admins.length);
idProject = uint64(admins.length);
admins.push(PledgeAdmin(
PledgeAdminType.Campaign,
campaignAdmin,
PledgeAdminType.Project,
projectAdmin,
name,
url,
commitTime,
parentCampaign,
parentProject,
false,
plugin));
CampaignAdded(idCampaign);
ProjectAdded(idProject);
}
event CampaignAdded(uint64 indexed idCampaign);
event ProjectAdded(uint64 indexed idProject);
///@notice Changes the address, name or commitTime associated with a specific Campaign
function updateCampaign(
uint64 idCampaign,
///@notice Changes the address, name or commitTime associated with a specific Project
function updateProject(
uint64 idProject,
address newAddr,
string newName,
string newUrl,
uint64 newCommitTime)
{
PledgeAdmin storage campaign = findAdmin(idCampaign);
require(campaign.adminType == PledgeAdminType.Campaign);
require(campaign.addr == msg.sender);
campaign.addr = newAddr;
campaign.name = newName;
campaign.url = newUrl;
campaign.commitTime = newCommitTime;
CampaignUpdated(idCampaign);
PledgeAdmin storage project = findAdmin(idProject);
require(project.adminType == PledgeAdminType.Project);
require(project.addr == msg.sender);
project.addr = newAddr;
project.name = newName;
project.url = newUrl;
project.commitTime = newCommitTime;
ProjectUpdated(idProject);
}
event CampaignUpdated(uint64 indexed idAdmin);
event ProjectUpdated(uint64 indexed idAdmin);
//////////
@ -253,7 +253,7 @@ contract LiquidPledgingBase {
uint amount,
uint64 owner,
uint64 nDelegates,
uint64 intendedCampaign,
uint64 intendedProject,
uint64 commitTime,
uint64 oldPledge,
PaymentState paymentState
@ -262,7 +262,7 @@ contract LiquidPledgingBase {
amount = n.amount;
owner = n.owner;
nDelegates = uint64(n.delegationChain.length);
intendedCampaign = n.intendedCampaign;
intendedProject = n.intendedProject;
commitTime = n.commitTime;
oldPledge = n.oldPledge;
paymentState = n.paymentState;
@ -291,7 +291,7 @@ contract LiquidPledgingBase {
string name,
string url,
uint64 commitTime,
uint64 parentCampaign,
uint64 parentProject,
bool canceled,
address plugin)
{
@ -301,7 +301,7 @@ contract LiquidPledgingBase {
name = m.name;
url = m.url;
commitTime = m.commitTime;
parentCampaign = m.parentCampaign;
parentProject = m.parentProject;
canceled = m.canceled;
plugin = address(m.plugin);
}
@ -317,18 +317,18 @@ contract LiquidPledgingBase {
function findOrCreatePledge(
uint64 owner,
uint64[] delegationChain,
uint64 intendedCampaign,
uint64 intendedProject,
uint64 commitTime,
uint64 oldPledge,
PaymentState paid
) internal returns (uint64)
{
bytes32 hPledge = sha3(owner, delegationChain, intendedCampaign, commitTime, oldPledge, paid);
bytes32 hPledge = sha3(owner, delegationChain, intendedProject, commitTime, oldPledge, paid);
uint64 idx = hPledge2idx[hPledge];
if (idx > 0) return idx;
idx = uint64(pledges.length);
hPledge2idx[hPledge] = idx;
pledges.push(Pledge(0, owner, delegationChain, intendedCampaign, commitTime, oldPledge, paid));
pledges.push(Pledge(0, owner, delegationChain, intendedProject, commitTime, oldPledge, paid));
return idx;
}
@ -355,7 +355,7 @@ contract LiquidPledgingBase {
}
// helper function that returns the pledge level solely to check that transfers
// between Campaigns not violate MAX_INTERCAMPAIGN_LEVEL
// between Projects not violate MAX_INTERPROJECT_LEVEL
function getPledgeLevel(Pledge n) internal returns(uint) {
if (n.oldPledge == 0) return 0; //changed
Pledge storage oldN = findPledge(n.oldPledge);
@ -374,25 +374,25 @@ contract LiquidPledgingBase {
}
}
// helper function that returns the campaign level solely to check that there
// are not too many Campaigns that violate MAX_SUBCAMPAIGNS_LEVEL
function getCampaignLevel(PledgeAdmin m) internal returns(uint) {
assert(m.adminType == PledgeAdminType.Campaign);
if (m.parentCampaign == 0) return(1);
PledgeAdmin storage parentNM = findAdmin(m.parentCampaign);
return getCampaignLevel(parentNM);
// helper function that returns the project level solely to check that there
// are not too many Projects that violate MAX_SUBCAMPAIGNS_LEVEL
function getProjectLevel(PledgeAdmin m) internal returns(uint) {
assert(m.adminType == PledgeAdminType.Project);
if (m.parentProject == 0) return(1);
PledgeAdmin storage parentNM = findAdmin(m.parentProject);
return getProjectLevel(parentNM);
}
function isCampaignCanceled(uint64 campaignId) constant returns (bool) {
PledgeAdmin storage m = findAdmin(campaignId);
function isProjectCanceled(uint64 projectId) constant returns (bool) {
PledgeAdmin storage m = findAdmin(projectId);
if (m.adminType == PledgeAdminType.Giver) return false;
assert(m.adminType == PledgeAdminType.Campaign);
assert(m.adminType == PledgeAdminType.Project);
if (m.canceled) return true;
if (m.parentCampaign == 0) return false;
return isCampaignCanceled(m.parentCampaign);
if (m.parentProject == 0) return false;
return isProjectCanceled(m.parentProject);
}
// @notice A helper function for canceling campaigns
// @notice A helper function for canceling projects
// @param idPledge the pledge that may or may not be canceled
function getOldestPledgeNotCanceled(uint64 idPledge) internal constant returns(uint64) { //todo rename
if (idPledge == 0) return 0;
@ -400,9 +400,9 @@ contract LiquidPledgingBase {
PledgeAdmin storage admin = findAdmin(n.owner);
if (admin.adminType == PledgeAdminType.Giver) return idPledge;
assert(admin.adminType == PledgeAdminType.Campaign);
assert(admin.adminType == PledgeAdminType.Project);
if (!isCampaignCanceled(n.owner)) return idPledge;
if (!isProjectCanceled(n.owner)) return idPledge;
return getOldestPledgeNotCanceled(n.oldPledge);
}
@ -435,7 +435,7 @@ contract LiquidPledging is LiquidPledgingBase {
/// transfer is done to the idReceiver
/// @param idGiver Identifier of the giver thats donating.
/// @param idReceiver To whom it's transfered. Can be the same giver, another
/// giver, a delegate or a campaign
/// giver, a delegate or a project
function donate(uint64 idGiver, uint64 idReceiver) payable {
if (idGiver == 0) {
@ -472,12 +472,12 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
/// @notice Moves value between pledges
/// @param idSender ID of the giver, delegate or campaign admin that is transferring
/// @param idSender ID of the giver, delegate or project admin that is transferring
/// the funds from Pledge to Pledge. This admin must have permissions to move the value
/// @param idPledge Id of the pledge that's moving the value
/// @param amount Quantity of value that's being moved
/// @param idReceiver Destination of the value, can be a giver sending to a giver or
/// a delegate, a delegate to another delegate or a campaign to precommit it to that campaign
/// a delegate, a delegate to another delegate or a project to precommit it to that project
function transfer(uint64 idSender, uint64 idPledge, uint amount, uint64 idReceiver) {
idPledge = normalizePledge(idPledge);
@ -493,8 +493,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
if (n.owner == idSender) {
if (receiver.adminType == PledgeAdminType.Giver) {
transferOwnershipToGiver(idPledge, amount, idReceiver);
} else if (receiver.adminType == PledgeAdminType.Campaign) {
transferOwnershipToCampaign(idPledge, amount, idReceiver);
} else if (receiver.adminType == PledgeAdminType.Project) {
transferOwnershipToProject(idPledge, amount, idReceiver);
} else if (receiver.adminType == PledgeAdminType.Delegate) {
appendDelegate(idPledge, amount, idReceiver);
} else {
@ -542,11 +542,11 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
return;
}
// If the delegate wants to support a campaign, they undelegate all
// the delegates after them in the chain and choose a campaign
if (receiver.adminType == PledgeAdminType.Campaign) {
// If the delegate wants to support a project, they undelegate all
// the delegates after them in the chain and choose a project
if (receiver.adminType == PledgeAdminType.Project) {
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
proposeAssignCampaign(idPledge, amount, idReceiver);
proposeAssignProject(idPledge, amount, idReceiver);
return;
}
}
@ -555,7 +555,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
/// @notice This method is used to withdraw value from the system. This can be used
/// by the givers to avoid committing the donation or by campaign admin to use
/// by the givers to avoid committing the donation or by project admin to use
/// the Ether.
/// @param idPledge Id of the pledge that wants to be withdrawn.
/// @param amount Quantity of Ether that wants to be withdrawn.
@ -593,7 +593,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
require(n.paymentState == PaymentState.Paying);
// Check the campaign is not canceled in the while.
// Check the project is not canceled in the while.
require(getOldestPledgeNotCanceled(idPledge) == idPledge);
uint64 idNewPledge = findOrCreatePledge(
@ -616,7 +616,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
require(n.paymentState == PaymentState.Paying); //TODO change to revert
// When a payment is canceled, never is assigned to a campaign.
// When a payment is canceled, never is assigned to a project.
uint64 oldPledge = findOrCreatePledge(
n.owner,
n.delegationChain,
@ -631,14 +631,14 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
doTransfer(idPledge, oldPledge, amount);
}
/// @notice Method called to cancel this campaign.
/// @param idCampaign Id of the projct that wants to be canceled.
function cancelCampaign(uint64 idCampaign) {
PledgeAdmin storage campaign = findAdmin(idCampaign);
checkAdminOwner(campaign);
campaign.canceled = true;
/// @notice Method called to cancel this project.
/// @param idProject Id of the projct that wants to be canceled.
function cancelProject(uint64 idProject) {
PledgeAdmin storage project = findAdmin(idProject);
checkAdminOwner(project);
project.canceled = true;
CancelCampaign(idCampaign);
CancelProject(idProject);
}
@ -711,11 +711,11 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
// this function is obvious, but it can also be called to undelegate everyone
// by setting yourself as the idReceiver
function transferOwnershipToCampaign(uint64 idPledge, uint amount, uint64 idReceiver) internal {
function transferOwnershipToProject(uint64 idPledge, uint amount, uint64 idReceiver) internal {
Pledge storage n = findPledge(idPledge);
require(getPledgeLevel(n) < MAX_INTERCAMPAIGN_LEVEL);
require(!isCampaignCanceled(idReceiver));
require(getPledgeLevel(n) < MAX_INTERPROJECT_LEVEL);
require(!isProjectCanceled(idReceiver));
uint64 oldPledge = findOrCreatePledge(
n.owner,
@ -785,11 +785,11 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
}
function proposeAssignCampaign(uint64 idPledge, uint amount, uint64 idReceiver) internal {// Todo rename
function proposeAssignProject(uint64 idPledge, uint amount, uint64 idReceiver) internal {// Todo rename
Pledge storage n = findPledge(idPledge);
require(getPledgeLevel(n) < MAX_SUBCAMPAIGN_LEVEL);
require(!isCampaignCanceled(idReceiver));
require(getPledgeLevel(n) < MAX_SUBPROJECT_LEVEL);
require(!isProjectCanceled(idReceiver));
uint64 toPledge = findOrCreatePledge(
n.owner,
@ -816,10 +816,10 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
}
// This function does 2 things, #1: it checks to make sure that the pledges are correct
// if the a pledged campaign has already been committed then it changes the owner
// to be the proposed campaign (Pledge that the UI will have to read the commit time and manually
// if the a pledged project has already been committed then it changes the owner
// to be the proposed project (Pledge that the UI will have to read the commit time and manually
// do what this function does to the pledge for the end user at the expiration of the commitTime)
// #2: It checks to make sure that if there has been a cancellation in the chain of campaigns,
// #2: It checks to make sure that if there has been a cancellation in the chain of projects,
// then it adjusts the pledge's owner appropriately.
// This call can be called from any body at any time on any pledge. In general it can be called
// to force the calls of the affected plugins, which also need to be predicted by the UI
@ -829,8 +829,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
// Check to make sure this pledge hasnt already been used or is in the process of being used
if (n.paymentState != PaymentState.Pledged) return idPledge;
// First send to a campaign if it's proposed and commited
if ((n.intendedCampaign > 0) && ( getTime() > n.commitTime)) {
// First send to a project if it's proposed and commited
if ((n.intendedProject > 0) && ( getTime() > n.commitTime)) {
uint64 oldPledge = findOrCreatePledge(
n.owner,
n.delegationChain,
@ -839,7 +839,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
n.oldPledge,
PaymentState.Pledged);
uint64 toPledge = findOrCreatePledge(
n.intendedCampaign,
n.intendedProject,
new uint64[](0),
0,
0,
@ -888,8 +888,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
allowedAmount = callPlugin(before, n.delegationChain[i], fromPledge, toPledge, offset + i+1, allowedAmount);
}
if (n.intendedCampaign > 0) {
allowedAmount = callPlugin(before, n.intendedCampaign, fromPledge, toPledge, offset + 255, allowedAmount);
if (n.intendedProject > 0) {
allowedAmount = callPlugin(before, n.intendedProject, fromPledge, toPledge, offset + 255, allowedAmount);
}
}
@ -909,6 +909,6 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
}
event Transfer(uint64 indexed from, uint64 indexed to, uint amount);
event CancelCampaign(uint64 indexed idCampaign);
event CancelProject(uint64 indexed idProject);
}

View File

@ -1,6 +1,6 @@
/* This is an autogenerated file. DO NOT EDIT MANUALLY */
exports.OwnedAbi = [{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"changeOwner","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"inputs":[],"payable":false,"type":"constructor"}]
exports.OwnedByteCode = "0x6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b6101d18061003c6000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166379ba5097811461005e5780638da5cb5b14610073578063a6f9dae1146100a2578063d4ee1d90146100c3575b600080fd5b341561006957600080fd5b6100716100f2565b005b341561007e57600080fd5b61008661013f565b604051600160a060020a03909116815260200160405180910390f35b34156100ad57600080fd5b610071600160a060020a036004351661014e565b005b34156100ce57600080fd5b610086610196565b604051600160a060020a03909116815260200160405180910390f35b60015433600160a060020a0390811691161461010d57600080fd5b6001546000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a039092169190911790555b565b600054600160a060020a031681565b60005433600160a060020a0390811691161461016957600080fd5b6001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0383161790555b5b50565b600154600160a060020a0316815600a165627a7a72305820e68440031004354b3db9d740fb2b8896f5bedd56653beb65edd62e94e414a7ad0029"
exports._solcVersion = "0.4.15+commit.bbb8e64f.Emscripten.clang"
exports.OwnedAbi = [{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_newOwner","type":"address"}],"name":"changeOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"newOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]
exports.OwnedByteCode = "0x6060604052341561000f57600080fd5b60008054600160a060020a033316600160a060020a03199091161790556101b38061003b6000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166379ba5097811461005d5780638da5cb5b14610072578063a6f9dae1146100a1578063d4ee1d90146100c057600080fd5b341561006857600080fd5b6100706100d3565b005b341561007d57600080fd5b61008561011f565b604051600160a060020a03909116815260200160405180910390f35b34156100ac57600080fd5b610070600160a060020a036004351661012e565b34156100cb57600080fd5b610085610178565b60015433600160a060020a039081169116146100ee57600080fd5b6001546000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a03909216919091179055565b600054600160a060020a031681565b60005433600160a060020a0390811691161461014957600080fd5b6001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b600154600160a060020a0316815600a165627a7a72305820cc9dc6586bdf997796667e5b08982f8474a9ec8a171c6a961d795c3bf5ac144c0029"
exports._solcVersion = "0.4.17+commit.bdeb9e52.Emscripten.clang"
exports._sha256 = "0xf61824cbb7f4765beceba9899e284825b9c60abba4179558d6b40e6976076b6b"

File diff suppressed because one or more lines are too long

View File

@ -9,13 +9,13 @@ contract ILiquidPledgingPlugin {
/// 1 -> Plugin for the first delegate transferring pledge to another party
/// 2 -> Plugin for the second delegate transferring pledge to another party
/// ...
/// 255 -> Plugin for the intendedCampaign transferring pledge to another party
/// 255 -> Plugin for the intendedProject transferring pledge to another party
///
/// 256 -> Plugin for the owner receiving pledge to another party
/// 257 -> Plugin for the first delegate receiving pledge to another party
/// 258 -> Plugin for the second delegate receiving pledge to another party
/// ...
/// 511 -> Plugin for the intendedCampaign receiving pledge to another party
/// 511 -> Plugin for the intendedProject receiving pledge to another party
function beforeTransfer(
uint64 pledgeManager,
uint64 pledgeFrom,

View File

@ -20,7 +20,7 @@ contract LiquidPledging is LiquidPledgingBase {
/// transfer is done to the idReceiver
/// @param idGiver Identifier of the giver thats donating.
/// @param idReceiver To whom it's transfered. Can be the same giver, another
/// giver, a delegate or a campaign
/// giver, a delegate or a project
function donate(uint64 idGiver, uint64 idReceiver) payable {
if (idGiver == 0) {
@ -57,12 +57,12 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
/// @notice Moves value between pledges
/// @param idSender ID of the giver, delegate or campaign admin that is transferring
/// @param idSender ID of the giver, delegate or project admin that is transferring
/// the funds from Pledge to Pledge. This admin must have permissions to move the value
/// @param idPledge Id of the pledge that's moving the value
/// @param amount Quantity of value that's being moved
/// @param idReceiver Destination of the value, can be a giver sending to a giver or
/// a delegate, a delegate to another delegate or a campaign to precommit it to that campaign
/// a delegate, a delegate to another delegate or a project to precommit it to that project
function transfer(uint64 idSender, uint64 idPledge, uint amount, uint64 idReceiver) {
idPledge = normalizePledge(idPledge);
@ -78,8 +78,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
if (n.owner == idSender) {
if (receiver.adminType == PledgeAdminType.Giver) {
transferOwnershipToGiver(idPledge, amount, idReceiver);
} else if (receiver.adminType == PledgeAdminType.Campaign) {
transferOwnershipToCampaign(idPledge, amount, idReceiver);
} else if (receiver.adminType == PledgeAdminType.Project) {
transferOwnershipToProject(idPledge, amount, idReceiver);
} else if (receiver.adminType == PledgeAdminType.Delegate) {
appendDelegate(idPledge, amount, idReceiver);
} else {
@ -127,11 +127,11 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
return;
}
// If the delegate wants to support a campaign, they undelegate all
// the delegates after them in the chain and choose a campaign
if (receiver.adminType == PledgeAdminType.Campaign) {
// If the delegate wants to support a project, they undelegate all
// the delegates after them in the chain and choose a project
if (receiver.adminType == PledgeAdminType.Project) {
undelegate(idPledge, amount, n.delegationChain.length - senderDIdx - 1);
proposeAssignCampaign(idPledge, amount, idReceiver);
proposeAssignProject(idPledge, amount, idReceiver);
return;
}
}
@ -140,7 +140,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
/// @notice This method is used to withdraw value from the system. This can be used
/// by the givers to avoid committing the donation or by campaign admin to use
/// by the givers to avoid committing the donation or by project admin to use
/// the Ether.
/// @param idPledge Id of the pledge that wants to be withdrawn.
/// @param amount Quantity of Ether that wants to be withdrawn.
@ -178,7 +178,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
require(n.paymentState == PaymentState.Paying);
// Check the campaign is not canceled in the while.
// Check the project is not canceled in the while.
require(getOldestPledgeNotCanceled(idPledge) == idPledge);
uint64 idNewPledge = findOrCreatePledge(
@ -201,7 +201,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
require(n.paymentState == PaymentState.Paying); //TODO change to revert
// When a payment is canceled, never is assigned to a campaign.
// When a payment is canceled, never is assigned to a project.
uint64 oldPledge = findOrCreatePledge(
n.owner,
n.delegationChain,
@ -216,14 +216,14 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
doTransfer(idPledge, oldPledge, amount);
}
/// @notice Method called to cancel this campaign.
/// @param idCampaign Id of the projct that wants to be canceled.
function cancelCampaign(uint64 idCampaign) {
PledgeAdmin storage campaign = findAdmin(idCampaign);
checkAdminOwner(campaign);
campaign.canceled = true;
/// @notice Method called to cancel this project.
/// @param idProject Id of the projct that wants to be canceled.
function cancelProject(uint64 idProject) {
PledgeAdmin storage project = findAdmin(idProject);
checkAdminOwner(project);
project.canceled = true;
CancelCampaign(idCampaign);
CancelProject(idProject);
}
@ -296,11 +296,11 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
// this function is obvious, but it can also be called to undelegate everyone
// by setting yourself as the idReceiver
function transferOwnershipToCampaign(uint64 idPledge, uint amount, uint64 idReceiver) internal {
function transferOwnershipToProject(uint64 idPledge, uint amount, uint64 idReceiver) internal {
Pledge storage n = findPledge(idPledge);
require(getPledgeLevel(n) < MAX_INTERCAMPAIGN_LEVEL);
require(!isCampaignCanceled(idReceiver));
require(getPledgeLevel(n) < MAX_INTERPROJECT_LEVEL);
require(!isProjectCanceled(idReceiver));
uint64 oldPledge = findOrCreatePledge(
n.owner,
@ -370,11 +370,11 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
}
function proposeAssignCampaign(uint64 idPledge, uint amount, uint64 idReceiver) internal {// Todo rename
function proposeAssignProject(uint64 idPledge, uint amount, uint64 idReceiver) internal {// Todo rename
Pledge storage n = findPledge(idPledge);
require(getPledgeLevel(n) < MAX_SUBCAMPAIGN_LEVEL);
require(!isCampaignCanceled(idReceiver));
require(getPledgeLevel(n) < MAX_SUBPROJECT_LEVEL);
require(!isProjectCanceled(idReceiver));
uint64 toPledge = findOrCreatePledge(
n.owner,
@ -401,10 +401,10 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
}
// This function does 2 things, #1: it checks to make sure that the pledges are correct
// if the a pledged campaign has already been committed then it changes the owner
// to be the proposed campaign (Pledge that the UI will have to read the commit time and manually
// if the a pledged project has already been committed then it changes the owner
// to be the proposed project (Pledge that the UI will have to read the commit time and manually
// do what this function does to the pledge for the end user at the expiration of the commitTime)
// #2: It checks to make sure that if there has been a cancellation in the chain of campaigns,
// #2: It checks to make sure that if there has been a cancellation in the chain of projects,
// then it adjusts the pledge's owner appropriately.
// This call can be called from any body at any time on any pledge. In general it can be called
// to force the calls of the affected plugins, which also need to be predicted by the UI
@ -414,8 +414,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
// Check to make sure this pledge hasnt already been used or is in the process of being used
if (n.paymentState != PaymentState.Pledged) return idPledge;
// First send to a campaign if it's proposed and commited
if ((n.intendedCampaign > 0) && ( getTime() > n.commitTime)) {
// First send to a project if it's proposed and commited
if ((n.intendedProject > 0) && ( getTime() > n.commitTime)) {
uint64 oldPledge = findOrCreatePledge(
n.owner,
n.delegationChain,
@ -424,7 +424,7 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
n.oldPledge,
PaymentState.Pledged);
uint64 toPledge = findOrCreatePledge(
n.intendedCampaign,
n.intendedProject,
new uint64[](0),
0,
0,
@ -473,8 +473,8 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
allowedAmount = callPlugin(before, n.delegationChain[i], fromPledge, toPledge, offset + i+1, allowedAmount);
}
if (n.intendedCampaign > 0) {
allowedAmount = callPlugin(before, n.intendedCampaign, fromPledge, toPledge, offset + 255, allowedAmount);
if (n.intendedProject > 0) {
allowedAmount = callPlugin(before, n.intendedProject, fromPledge, toPledge, offset + 255, allowedAmount);
}
}
@ -494,6 +494,6 @@ function donate(uint64 idGiver, uint64 idReceiver) payable {
}
event Transfer(uint64 indexed from, uint64 indexed to, uint amount);
event CancelCampaign(uint64 indexed idCampaign);
event CancelProject(uint64 indexed idProject);
}

View File

@ -12,22 +12,22 @@ contract Vault {
contract LiquidPledgingBase {
// Limits inserted to prevent large loops that could prevent canceling
uint constant MAX_DELEGATES = 20;
uint constant MAX_SUBCAMPAIGN_LEVEL = 20;
uint constant MAX_INTERCAMPAIGN_LEVEL = 20;
uint constant MAX_SUBPROJECT_LEVEL = 20;
uint constant MAX_INTERPROJECT_LEVEL = 20;
enum PledgeAdminType { Giver, Delegate, Campaign }
enum PledgeAdminType { Giver, Delegate, Project }
enum PaymentState { Pledged, Paying, Paid } // TODO name change Pledged
/// @dev This struct defines the details of each the PledgeAdmin, these
/// PledgeAdmins can own pledges and act as delegates
struct PledgeAdmin { // TODO name change PledgeAdmin
PledgeAdminType adminType; // Giver, Delegate or Campaign
PledgeAdminType adminType; // Giver, Delegate or Project
address addr; // account or contract address for admin
string name;
string url;
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
uint64 parentCampaign; // Only for campaigns
bool canceled; //Always false except for canceled campaigns
uint64 parentProject; // Only for projects
bool canceled; //Always false except for canceled projects
ILiquidPledgingPlugin plugin; // if the plugin is 0x0 then nothing happens if its a contract address than that smart contract is called via the milestone contract
}
@ -35,8 +35,8 @@ contract LiquidPledgingBase {
uint amount;
uint64 owner; // PledgeAdmin
uint64[] delegationChain; // list of index numbers
uint64 intendedCampaign; // TODO change the name only used for when delegates are precommiting to a campaign
uint64 commitTime; // When the intendedCampaign will become the owner
uint64 intendedProject; // TODO change the name only used for when delegates are precommiting to a project
uint64 commitTime; // When the intendedProject will become the owner
uint64 oldPledge; // this points to the Pledge[] index that the Pledge was derived from
PaymentState paymentState;
}
@ -156,52 +156,52 @@ contract LiquidPledgingBase {
event DelegateUpdated(uint64 indexed idDelegate);
/// @notice Creates a new Campaign
function addCampaign(string name, string url, address campaignAdmin, uint64 parentCampaign, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idCampaign) {
if (parentCampaign != 0) {
PledgeAdmin storage pa = findAdmin(parentCampaign);
require(pa.adminType == PledgeAdminType.Campaign);
/// @notice Creates a new Project
function addProject(string name, string url, address projectAdmin, uint64 parentProject, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idProject) {
if (parentProject != 0) {
PledgeAdmin storage pa = findAdmin(parentProject);
require(pa.adminType == PledgeAdminType.Project);
require(pa.addr == msg.sender);
require(getCampaignLevel(pa) < MAX_SUBCAMPAIGN_LEVEL);
require(getProjectLevel(pa) < MAX_SUBPROJECT_LEVEL);
}
idCampaign = uint64(admins.length);
idProject = uint64(admins.length);
admins.push(PledgeAdmin(
PledgeAdminType.Campaign,
campaignAdmin,
PledgeAdminType.Project,
projectAdmin,
name,
url,
commitTime,
parentCampaign,
parentProject,
false,
plugin));
CampaignAdded(idCampaign);
ProjectAdded(idProject);
}
event CampaignAdded(uint64 indexed idCampaign);
event ProjectAdded(uint64 indexed idProject);
///@notice Changes the address, name or commitTime associated with a specific Campaign
function updateCampaign(
uint64 idCampaign,
///@notice Changes the address, name or commitTime associated with a specific Project
function updateProject(
uint64 idProject,
address newAddr,
string newName,
string newUrl,
uint64 newCommitTime)
{
PledgeAdmin storage campaign = findAdmin(idCampaign);
require(campaign.adminType == PledgeAdminType.Campaign);
require(campaign.addr == msg.sender);
campaign.addr = newAddr;
campaign.name = newName;
campaign.url = newUrl;
campaign.commitTime = newCommitTime;
CampaignUpdated(idCampaign);
PledgeAdmin storage project = findAdmin(idProject);
require(project.adminType == PledgeAdminType.Project);
require(project.addr == msg.sender);
project.addr = newAddr;
project.name = newName;
project.url = newUrl;
project.commitTime = newCommitTime;
ProjectUpdated(idProject);
}
event CampaignUpdated(uint64 indexed idAdmin);
event ProjectUpdated(uint64 indexed idAdmin);
//////////
@ -217,7 +217,7 @@ contract LiquidPledgingBase {
uint amount,
uint64 owner,
uint64 nDelegates,
uint64 intendedCampaign,
uint64 intendedProject,
uint64 commitTime,
uint64 oldPledge,
PaymentState paymentState
@ -226,7 +226,7 @@ contract LiquidPledgingBase {
amount = n.amount;
owner = n.owner;
nDelegates = uint64(n.delegationChain.length);
intendedCampaign = n.intendedCampaign;
intendedProject = n.intendedProject;
commitTime = n.commitTime;
oldPledge = n.oldPledge;
paymentState = n.paymentState;
@ -255,7 +255,7 @@ contract LiquidPledgingBase {
string name,
string url,
uint64 commitTime,
uint64 parentCampaign,
uint64 parentProject,
bool canceled,
address plugin)
{
@ -265,7 +265,7 @@ contract LiquidPledgingBase {
name = m.name;
url = m.url;
commitTime = m.commitTime;
parentCampaign = m.parentCampaign;
parentProject = m.parentProject;
canceled = m.canceled;
plugin = address(m.plugin);
}
@ -281,18 +281,18 @@ contract LiquidPledgingBase {
function findOrCreatePledge(
uint64 owner,
uint64[] delegationChain,
uint64 intendedCampaign,
uint64 intendedProject,
uint64 commitTime,
uint64 oldPledge,
PaymentState paid
) internal returns (uint64)
{
bytes32 hPledge = sha3(owner, delegationChain, intendedCampaign, commitTime, oldPledge, paid);
bytes32 hPledge = sha3(owner, delegationChain, intendedProject, commitTime, oldPledge, paid);
uint64 idx = hPledge2idx[hPledge];
if (idx > 0) return idx;
idx = uint64(pledges.length);
hPledge2idx[hPledge] = idx;
pledges.push(Pledge(0, owner, delegationChain, intendedCampaign, commitTime, oldPledge, paid));
pledges.push(Pledge(0, owner, delegationChain, intendedProject, commitTime, oldPledge, paid));
return idx;
}
@ -319,7 +319,7 @@ contract LiquidPledgingBase {
}
// helper function that returns the pledge level solely to check that transfers
// between Campaigns not violate MAX_INTERCAMPAIGN_LEVEL
// between Projects not violate MAX_INTERPROJECT_LEVEL
function getPledgeLevel(Pledge n) internal returns(uint) {
if (n.oldPledge == 0) return 0; //changed
Pledge storage oldN = findPledge(n.oldPledge);
@ -338,25 +338,25 @@ contract LiquidPledgingBase {
}
}
// helper function that returns the campaign level solely to check that there
// are not too many Campaigns that violate MAX_SUBCAMPAIGNS_LEVEL
function getCampaignLevel(PledgeAdmin m) internal returns(uint) {
assert(m.adminType == PledgeAdminType.Campaign);
if (m.parentCampaign == 0) return(1);
PledgeAdmin storage parentNM = findAdmin(m.parentCampaign);
return getCampaignLevel(parentNM);
// helper function that returns the project level solely to check that there
// are not too many Projects that violate MAX_SUBCAMPAIGNS_LEVEL
function getProjectLevel(PledgeAdmin m) internal returns(uint) {
assert(m.adminType == PledgeAdminType.Project);
if (m.parentProject == 0) return(1);
PledgeAdmin storage parentNM = findAdmin(m.parentProject);
return getProjectLevel(parentNM);
}
function isCampaignCanceled(uint64 campaignId) constant returns (bool) {
PledgeAdmin storage m = findAdmin(campaignId);
function isProjectCanceled(uint64 projectId) constant returns (bool) {
PledgeAdmin storage m = findAdmin(projectId);
if (m.adminType == PledgeAdminType.Giver) return false;
assert(m.adminType == PledgeAdminType.Campaign);
assert(m.adminType == PledgeAdminType.Project);
if (m.canceled) return true;
if (m.parentCampaign == 0) return false;
return isCampaignCanceled(m.parentCampaign);
if (m.parentProject == 0) return false;
return isProjectCanceled(m.parentProject);
}
// @notice A helper function for canceling campaigns
// @notice A helper function for canceling projects
// @param idPledge the pledge that may or may not be canceled
function getOldestPledgeNotCanceled(uint64 idPledge) internal constant returns(uint64) { //todo rename
if (idPledge == 0) return 0;
@ -364,9 +364,9 @@ contract LiquidPledgingBase {
PledgeAdmin storage admin = findAdmin(n.owner);
if (admin.adminType == PledgeAdminType.Giver) return idPledge;
assert(admin.adminType == PledgeAdminType.Campaign);
assert(admin.adminType == PledgeAdminType.Project);
if (!isCampaignCanceled(n.owner)) return idPledge;
if (!isProjectCanceled(n.owner)) return idPledge;
return getOldestPledgeNotCanceled(n.oldPledge);
}

View File

@ -20,8 +20,8 @@ module.exports = (test) => {
pledge.amount = res.amount;
pledge.owner = res.owner;
if (res.intendedCampaign) {
pledge.intendedCampaign = res.intendedCampaign;
if (res.intendedProject) {
pledge.intendedProject = res.intendedProject;
pledge.commmitTime = res.commitTime;
}
if (res.oldPledge) {
@ -67,7 +67,7 @@ module.exports = (test) => {
} else if (res.adminType === '1') {
admin.type = 'Delegate';
} else if (res.adminType === '2') {
admin.type = 'Campaign';
admin.type = 'Project';
} else {
admin.type = 'Unknown';
}
@ -75,8 +75,8 @@ module.exports = (test) => {
admin.name = res.name;
admin.url = res.url;
admin.commitTime = res.commitTime;
if (admin.paymentState === 'Campaign') {
admin.parentCampaign = res.parentCampaign;
if (admin.paymentState === 'Project') {
admin.parentProject = res.parentProject;
admin.canceled = res.canceled;
}
admin.plugin = res.plugin;
@ -131,8 +131,8 @@ module.exports = (test) => {
pledges: [],
delegates: [],
},
precommitedCampaigns: [],
commitedCampaigns: [],
precommitedProjects: [],
commitedProjects: [],
};
}
};
@ -151,18 +151,18 @@ module.exports = (test) => {
}
};
const addCampaign = (_list, idCampaign) => {
const addProject = (_list, idProject) => {
const list = _list;
if (!list[idCampaign]) {
list[idCampaign] = {
idCampaign,
if (!list[idProject]) {
list[idProject] = {
idProject,
pledges: [],
commitedCampaigns: [],
name: this.admins[idCampaign].name,
url: this.admins[idCampaign].url,
commitTime: this.admins[idCampaign].commitTime,
owner: this.admins[idCampaign].owner,
parentCampaign: this.admins[idCampaign].parentCampaign,
commitedProjects: [],
name: this.admins[idProject].name,
url: this.admins[idProject].url,
commitTime: this.admins[idProject].commitTime,
owner: this.admins[idProject].owner,
parentProject: this.admins[idProject].parentProject,
};
}
};
@ -178,21 +178,21 @@ module.exports = (test) => {
}
};
const addCampaignPledge = (stGiver, idPledge) => {
const addProjectPledge = (stGiver, idPledge) => {
const pledge = this.pledges[idPledge];
const campaignList = [];
const crojectList = [];
let n = pledge;
while (n.oldNode) {
campaignList.unshift(n.owner);
crojectList.unshift(n.owner);
n = this.pledges[n.oldNode];
}
let list = stGiver.commitedCampaigns;
for (let j = 0; j < campaignList.length; j += 1) {
addCampaign(list, campaignList[j]);
list[campaignList[j]].pledges.push(idPledge);
list = list[campaignList[j]].commitedCampaigns;
let list = stGiver.commitedProjects;
for (let j = 0; j < crojectList.length; j += 1) {
addProject(list, crojectList[j]);
list[crojectList[j]].pledges.push(idPledge);
list = list[crojectList[j]].commitedProjects;
}
};
@ -202,13 +202,13 @@ module.exports = (test) => {
addGiver(giversState, idGiver);
const stGiver = giversState[idGiver];
const pledge = this.pledges[idPledge];
if ((pledge.owner === idGiver) && (pledge.precommitedCampaign === 0)) {
if ((pledge.owner === idGiver) && (pledge.precommitedProject === 0)) {
addDelegatePledge(stGiver, idPledge);
} else if ((pledge.owner === idGiver) && (pledge.precommitedCampaign !== 0)) {
addCampaign(stGiver.precommitedCampaigns, pledge.precommitedCampaign);
stGiver.precommitedCampaigns[pledge.precommitedCampaign].pledges.push(idPledge);
} else if ((pledge.owner === idGiver) && (pledge.precommitedProject !== 0)) {
addProject(stGiver.precommitedProjects, pledge.precommitedProject);
stGiver.precommitedProjects[pledge.precommitedProject].pledges.push(idPledge);
} else {
addCampaignPledge(stGiver, idPledge);
addProjectPledge(stGiver, idPledge);
}
}

View File

@ -46,9 +46,9 @@ describe('LiquidPledging test', () => {
let giver1;
let giver2;
let delegate1;
let adminCampaign1;
let adminCampaign2;
let adminCampaign2a;
let adminProject1;
let adminProject2;
let adminProject2a;
let delegate2;
before(async () => {
const testrpc = TestRPC.server({
@ -63,9 +63,9 @@ describe('LiquidPledging test', () => {
accounts = await web3.eth.getAccounts();
giver1 = accounts[1];
delegate1 = accounts[2];
adminCampaign1 = accounts[3];
adminCampaign2 = accounts[4];
adminCampaign2a = accounts[5];
adminProject1 = accounts[3];
adminProject2 = accounts[4];
adminProject2a = accounts[5];
delegate2 = accounts[6];
giver2 = accounts[7];
});
@ -117,34 +117,34 @@ describe('LiquidPledging test', () => {
assert.equal(d[1], delegate1);
assert.equal(d[2], 'Delegate1');
}).timeout(6000);
it('Should create a 2 campaigns', async () => {
await liquidPledging.addCampaign('Campaign1', 'URLCampaign1', adminCampaign1, 0, 86400, 0, { from: adminCampaign1 });
it('Should create a 2 projects', async () => {
await liquidPledging.addProject('Project1', 'URLProject1', adminProject1, 0, 86400, 0, { from: adminProject1 });
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
assert.equal(nAdmins, 3);
const res = await liquidPledging.getPledgeAdmin(3);
assert.equal(res[0], 2); // Campaign type
assert.equal(res[1], adminCampaign1);
assert.equal(res[2], 'Campaign1');
assert.equal(res[3], 'URLCampaign1');
assert.equal(res[0], 2); // Project type
assert.equal(res[1], adminProject1);
assert.equal(res[2], 'Project1');
assert.equal(res[3], 'URLProject1');
assert.equal(res[4], 86400);
assert.equal(res[5], 0);
assert.equal(res[6], false);
await liquidPledging.addCampaign('Campaign2', 'URLCampaign2', adminCampaign2, 0, 86400, 0, { from: adminCampaign2 });
await liquidPledging.addProject('Project2', 'URLProject2', adminProject2, 0, 86400, 0, { from: adminProject2 });
const nAdmins2 = await liquidPledging.numberOfPledgeAdmins();
assert.equal(nAdmins2, 4);
const res4 = await liquidPledging.getPledgeAdmin(4);
assert.equal(res4[0], 2); // Campaign type
assert.equal(res4[1], adminCampaign2);
assert.equal(res4[2], 'Campaign2');
assert.equal(res4[3], 'URLCampaign2');
assert.equal(res4[0], 2); // Project type
assert.equal(res4[1], adminProject2);
assert.equal(res4[2], 'Project2');
assert.equal(res4[3], 'URLProject2');
assert.equal(res4[4], 86400);
assert.equal(res4[5], 0);
assert.equal(res4[6], false);
}).timeout(6000);
it('Delegate should assign to campaign1', async () => {
it('Delegate should assign to project1', async () => {
const n = Math.floor(new Date().getTime() / 1000);
await liquidPledging.transfer(2, 2, utils.toWei(0.2), 3, { from: delegate1 });
const nPledges = await liquidPledging.numberOfPledges();
@ -153,12 +153,12 @@ describe('LiquidPledging test', () => {
assert.equal(res3[0], utils.toWei(0.2));
assert.equal(res3[1], 1); // Owner
assert.equal(res3[2], 1); // Delegates
assert.equal(res3[3], 3); // Proposed Campaign
assert.equal(res3[3], 3); // Proposed Project
assert.isAbove(utils.toDecimal(res3[4]), n + 86000);
assert.equal(res3[5], 0); // Old Node
assert.equal(res3[6], 0); // Not Paid
}).timeout(6000);
it('Giver should change his mind and assign half of it to campaign2', async () => {
it('Giver should change his mind and assign half of it to project2', async () => {
await liquidPledging.transfer(1, 3, utils.toWei(0.1), 4, { from: giver1 });
const nPledges = await liquidPledging.numberOfPledges();
assert.equal(nPledges, 4);
@ -167,22 +167,22 @@ describe('LiquidPledging test', () => {
const res4 = await liquidPledging.getPledge(4);
assert.equal(res4[1], 4); // Owner
assert.equal(res4[2], 0); // Delegates
assert.equal(res4[3], 0); // Proposed Campaign
assert.equal(res4[3], 0); // Proposed Project
assert.equal(res4[4], 0);
assert.equal(res4[5], 2); // Old Node
assert.equal(res4[6], 0); // Not Paid
}).timeout(6000);
it('After the time, the campaign1 should be able to spend part of it', async () => {
it('After the time, the project1 should be able to spend part of it', async () => {
const n = Math.floor(new Date().getTime() / 1000);
await liquidPledging.setMockedTime(n + 86401);
await liquidPledging.withdraw(3, utils.toWei(0.05), { from: adminCampaign1 });
await liquidPledging.withdraw(3, utils.toWei(0.05), { from: adminProject1 });
const nPledges = await liquidPledging.numberOfPledges();
assert.equal(nPledges, 6);
const res5 = await liquidPledging.getPledge(5);
assert.equal(res5[0], utils.toWei(0.05));
assert.equal(res5[1], 3); // Owner
assert.equal(res5[2], 0); // Delegates
assert.equal(res5[3], 0); // Proposed Campaign
assert.equal(res5[3], 0); // Proposed Project
assert.equal(res5[4], 0); // commit time
assert.equal(res5[5], 2); // Old Node
assert.equal(res5[6], 0); // Not Paid
@ -190,16 +190,16 @@ describe('LiquidPledging test', () => {
assert.equal(res6[0], utils.toWei(0.05));
assert.equal(res6[1], 3); // Owner
assert.equal(res6[2], 0); // Delegates
assert.equal(res6[3], 0); // Proposed Campaign
assert.equal(res6[3], 0); // Proposed Project
assert.equal(res6[4], 0); // commit time
assert.equal(res6[5], 2); // Old Node
assert.equal(res6[6], 1); // Peinding paid Paid
}).timeout(6000);
it('Should collect the Ether', async () => {
const initialBalance = await web3.eth.getBalance(adminCampaign1);
const initialBalance = await web3.eth.getBalance(adminProject1);
await vault.confirmPayment(0);
const finalBalance = await web3.eth.getBalance(adminCampaign1);
const finalBalance = await web3.eth.getBalance(adminProject1);
const collected = utils.fromWei(utils.toBN(finalBalance).sub(utils.toBN(initialBalance)));
@ -211,24 +211,24 @@ describe('LiquidPledging test', () => {
assert.equal(res7[0], utils.toWei(0.05));
assert.equal(res7[1], 3); // Owner
assert.equal(res7[2], 0); // Delegates
assert.equal(res7[3], 0); // Proposed Campaign
assert.equal(res7[3], 0); // Proposed Project
assert.equal(res7[4], 0); // commit time
assert.equal(res7[5], 2); // Old Node
assert.equal(res7[6], 2); // Peinding paid Paid
}).timeout(6000);
it('Admin of the campaign1 should be able to cancel campaign1', async () => {
await liquidPledging.cancelCampaign(3, { from: adminCampaign1 });
it('Admin of the project1 should be able to cancel project1', async () => {
await liquidPledging.cancelProject(3, { from: adminProject1 });
const st = await liquidPledging.getState(liquidPledging);
assert.equal(st.admins[3].canceled, true);
}).timeout(6000);
it('Should not allow to withdraw from a canceled campaign', async () => {
it('Should not allow to withdraw from a canceled project', async () => {
const st = await liquidPledging.getState(liquidPledging);
assert.equal(utils.fromWei(st.pledges[5].amount), 0.05);
await assertFail(async () => {
await liquidPledging.withdraw(5, utils.toWei(0.01), { from: adminCampaign1 });
await liquidPledging.withdraw(5, utils.toWei(0.01), { from: adminProject1 });
});
}).timeout(6000);
it('Delegate should send part of this ETH to campaign2', async () => {
it('Delegate should send part of this ETH to project2', async () => {
await liquidPledging.transfer(2, 5, utils.toWei(0.03), 4, {
$extraGas: 100000,
from: delegate1,
@ -239,23 +239,23 @@ describe('LiquidPledging test', () => {
assert.equal(st.pledges[8].owner, 1);
assert.equal(st.pledges[8].delegates.length, 1);
assert.equal(st.pledges[8].delegates[0].id, 2);
assert.equal(st.pledges[8].intendedCampaign, 4);
assert.equal(st.pledges[8].intendedProject, 4);
}).timeout(6000);
it('Giver should be able to send the remaining to campaign2', async () => {
it('Giver should be able to send the remaining to project2', async () => {
await liquidPledging.transfer(1, 5, utils.toWei(0.02), 4, { from: giver1, $extraGas: 100000 });
const st = await liquidPledging.getState(liquidPledging);
assert.equal(st.pledges.length, 9);
assert.equal(utils.fromWei(st.pledges[5].amount), 0);
assert.equal(utils.fromWei(st.pledges[4].amount), 0.12);
}).timeout(6000);
it('A subcampaign 2a and a delegate2 is created', async () => {
await liquidPledging.addCampaign('Campaign2a', 'URLCampaign2a', adminCampaign2a, 4, 86400, 0, { from: adminCampaign2 });
it('A subproject 2a and a delegate2 is created', async () => {
await liquidPledging.addProject('Project2a', 'URLProject2a', adminProject2a, 4, 86400, 0, { from: adminProject2 });
await liquidPledging.addDelegate('Delegate2', 'URLDelegate2', 0, 0, { from: delegate2 });
const nAdmins = await liquidPledging.numberOfPledgeAdmins();
assert.equal(nAdmins, 6);
}).timeout(6000);
it('Campaign 2 delegate in delegate2', async () => {
await liquidPledging.transfer(4, 4, utils.toWei(0.02), 6, { from: adminCampaign2 });
it('Project 2 delegate in delegate2', async () => {
await liquidPledging.transfer(4, 4, utils.toWei(0.02), 6, { from: adminProject2 });
const st = await liquidPledging.getState(liquidPledging);
assert.equal(st.pledges.length, 10);
assert.equal(utils.fromWei(st.pledges[9].amount), 0.02);
@ -268,20 +268,20 @@ describe('LiquidPledging test', () => {
assert.equal(utils.fromWei(st.pledges[9].amount), 0.01);
assert.equal(utils.fromWei(st.pledges[10].amount), 0.01);
}).timeout(4000);
it('campaign2a authorize to spend a litle', async () => {
it('project2a authorize to spend a litle', async () => {
const n = Math.floor(new Date().getTime() / 1000);
await liquidPledging.setMockedTime(n + (86401 * 3));
await liquidPledging.withdraw(10, utils.toWei(0.005), { from: adminCampaign2a });
await liquidPledging.withdraw(10, utils.toWei(0.005), { from: adminProject2a });
const st = await liquidPledging.getState(liquidPledging);
assert.equal(st.pledges.length, 13);
assert.equal(utils.fromWei(st.pledges[10].amount), 0);
assert.equal(utils.fromWei(st.pledges[11].amount), 0.005);
assert.equal(utils.fromWei(st.pledges[12].amount), 0.005);
}).timeout(4000);
it('campaign2 is canceled', async () => {
await liquidPledging.cancelCampaign(4, { from: adminCampaign2 });
it('project2 is canceled', async () => {
await liquidPledging.cancelProject(4, { from: adminProject2 });
}).timeout(6000);
it('campaign2 should not be able to confirm payment', async () => {
it('project2 should not be able to confirm payment', async () => {
await assertFail(async () => {
await vault.confirmPayment(1);
});
@ -315,7 +315,7 @@ describe('LiquidPledging test', () => {
const collected = utils.fromWei(utils.toBN(finalBalance).sub(utils.toBN(initialBalance)));
assert.equal(collected, 0.95);
}).timeout(10000);
}).timeout(12000);
it('Should make a donation and create giver', async () => {
const oldNPledges = await liquidPledging.numberOfPledges();
const oldNAdmins = await liquidPledging.numberOfPledgeAdmins();