Fix the last test
This commit is contained in:
parent
3e945ff349
commit
75bb05769b
|
@ -3,4 +3,4 @@
|
|||
exports.ILiquidPledgingPluginAbi = [{"constant":false,"inputs":[{"name":"noteManager","type":"uint64"},{"name":"noteFrom","type":"uint64"},{"name":"noteTo","type":"uint64"},{"name":"context","type":"uint64"},{"name":"amount","type":"uint256"}],"name":"afterTransfer","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"noteManager","type":"uint64"},{"name":"noteFrom","type":"uint64"},{"name":"noteTo","type":"uint64"},{"name":"context","type":"uint64"},{"name":"amount","type":"uint256"}],"name":"beforeTransfer","outputs":[{"name":"maxAllowed","type":"uint256"}],"payable":false,"type":"function"}]
|
||||
exports.ILiquidPledgingPluginByteCode = "0x"
|
||||
exports._solcVersion = "0.4.15+commit.bbb8e64f.Emscripten.clang"
|
||||
exports._sha256 = "0x0b78eb5f7fc9ad0a36150ca9c8750a9d2e1fc98fa75dbf9627f3abdd201119c4"
|
||||
exports._sha256 = "0xb71d787e74b5f7556b28ef7760fdad95c17568c094a14665d6f394726d5b22c8"
|
||||
|
|
|
@ -3,19 +3,32 @@
|
|||
pragma solidity ^0.4.11;
|
||||
|
||||
contract ILiquidPledgingPlugin {
|
||||
|
||||
/// @param context In which context it is affected.
|
||||
/// 0 -> owner from
|
||||
/// 1 -> First delegate from
|
||||
/// 2 -> Second delegate from
|
||||
/// @notice Plugins are used (much like web hooks) to initiate an action
|
||||
/// upon any donation, delegation, or transfer; this is an optional feature
|
||||
/// and allows for extreme customization of the contract
|
||||
/// @param context The situation that is triggering the plugin:
|
||||
/// 0 -> Plugin for the owner transferring pledge to another party
|
||||
/// 1 -> Plugin for the first delegate transferring pledge to another party
|
||||
/// 2 -> Plugin for the second delegate transferring pledge to another party
|
||||
/// ...
|
||||
/// 255 -> proposedProject from
|
||||
/// 255 -> Plugin for the proposedProject transferring pledge to another party
|
||||
///
|
||||
/// 256 -> owner to
|
||||
/// 257 -> First delegate to
|
||||
/// 258 -> Second delegate to
|
||||
/// 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 -> proposedProject to
|
||||
function beforeTransfer(uint64 noteManager, uint64 noteFrom, uint64 noteTo, uint64 context, uint amount) returns (uint maxAllowed);
|
||||
function afterTransfer(uint64 noteManager, uint64 noteFrom, uint64 noteTo, uint64 context, uint amount);
|
||||
/// 511 -> Plugin for the proposedProject receiving pledge to another party
|
||||
function beforeTransfer(
|
||||
uint64 noteManager,
|
||||
uint64 noteFrom,
|
||||
uint64 noteTo,
|
||||
uint64 context,
|
||||
uint amount
|
||||
) returns (uint maxAllowed);
|
||||
function afterTransfer(
|
||||
uint64 noteManager,
|
||||
uint64 noteFrom,
|
||||
uint64 noteTo,
|
||||
uint64 context,
|
||||
uint amount);
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -3,21 +3,34 @@
|
|||
pragma solidity ^0.4.11;
|
||||
|
||||
contract ILiquidPledgingPlugin {
|
||||
|
||||
/// @param context In which context it is affected.
|
||||
/// 0 -> owner from
|
||||
/// 1 -> First delegate from
|
||||
/// 2 -> Second delegate from
|
||||
/// @notice Plugins are used (much like web hooks) to initiate an action
|
||||
/// upon any donation, delegation, or transfer; this is an optional feature
|
||||
/// and allows for extreme customization of the contract
|
||||
/// @param context The situation that is triggering the plugin:
|
||||
/// 0 -> Plugin for the owner transferring pledge to another party
|
||||
/// 1 -> Plugin for the first delegate transferring pledge to another party
|
||||
/// 2 -> Plugin for the second delegate transferring pledge to another party
|
||||
/// ...
|
||||
/// 255 -> proposedProject from
|
||||
/// 255 -> Plugin for the proposedProject transferring pledge to another party
|
||||
///
|
||||
/// 256 -> owner to
|
||||
/// 257 -> First delegate to
|
||||
/// 258 -> Second delegate to
|
||||
/// 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 -> proposedProject to
|
||||
function beforeTransfer(uint64 noteManager, uint64 noteFrom, uint64 noteTo, uint64 context, uint amount) returns (uint maxAllowed);
|
||||
function afterTransfer(uint64 noteManager, uint64 noteFrom, uint64 noteTo, uint64 context, uint amount);
|
||||
/// 511 -> Plugin for the proposedProject receiving pledge to another party
|
||||
function beforeTransfer(
|
||||
uint64 noteManager,
|
||||
uint64 noteFrom,
|
||||
uint64 noteTo,
|
||||
uint64 context,
|
||||
uint amount
|
||||
) returns (uint maxAllowed);
|
||||
function afterTransfer(
|
||||
uint64 noteManager,
|
||||
uint64 noteFrom,
|
||||
uint64 noteTo,
|
||||
uint64 context,
|
||||
uint amount);
|
||||
}
|
||||
|
||||
//File: ./contracts/LiquidPledgingBase.sol
|
||||
|
@ -25,43 +38,46 @@ pragma solidity ^0.4.11;
|
|||
|
||||
|
||||
|
||||
/// @dev This is declares a few functions from `Vault` so that the
|
||||
/// `LiquidPledgingBase` contract can interface with the `Vault` contract
|
||||
contract Vault {
|
||||
function authorizePayment(bytes32 _ref, address _dest, uint _amount);
|
||||
function () payable;
|
||||
}
|
||||
|
||||
contract LiquidPledgingBase {
|
||||
|
||||
// Limits inserted to prevent large loops that could prevent canceling
|
||||
uint constant MAX_DELEGATES = 20;
|
||||
uint constant MAX_SUBPROJECT_LEVEL = 20;
|
||||
uint constant MAX_INTERPROJECT_LEVEL = 20;
|
||||
|
||||
enum NoteManagerType { Donor, Delegate, Project }// todo change name
|
||||
enum PaymentState { NotPaid, Paying, Paid }
|
||||
enum NoteManagerType { Donor, Delegate, Project } // todo change name Donor Project
|
||||
enum PaymentState { NotPaid, Paying, Paid } // TODO name change NotPaid
|
||||
|
||||
// This struct defines the details of each the NoteManager, these NoteManagers can create
|
||||
struct NoteManager {// change manager
|
||||
NoteManagerType managerType;
|
||||
address addr;
|
||||
string name;
|
||||
uint64 commitTime; // Only used in donors and projects, its the precommitment time
|
||||
uint64 parentProject; // Only for projects
|
||||
bool canceled; // Only for project
|
||||
ILiquidPledgingPlugin plugin; // Handler that is called when one call is affected.
|
||||
/// @dev This struct defines the details of each the NoteManager, these
|
||||
/// NoteManagers can own notes and act as delegates
|
||||
struct NoteManager { // TODO name change NoteManager
|
||||
NoteManagerType managerType; // Giver, Delegate or Campaign
|
||||
address addr; // account or contract address for admin
|
||||
string name;
|
||||
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
|
||||
uint64 parentProject; // Only for campaigns
|
||||
bool canceled; //Always false except for canceled campaigns
|
||||
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
|
||||
}
|
||||
|
||||
struct Note {
|
||||
uint amount;
|
||||
uint64 owner;
|
||||
uint64[] delegationChain; //index numbers!!!!!
|
||||
uint64 owner; //NoteManager
|
||||
uint64[] delegationChain; // list of index numbers
|
||||
uint64 proposedProject; // TODO change the name only used for when delegates are precommiting to a project
|
||||
uint64 commitTime; // At what time the upcoming time will become an owner.
|
||||
uint64 commitTime; // When the proposedProject will become the owner
|
||||
uint64 oldNote; // this points to the Note[] index that the Note was derived from
|
||||
PaymentState paymentState;
|
||||
}
|
||||
|
||||
Note[] notes;
|
||||
NoteManager[] managers; // the list of all the note managers 0 is reserved for no manager
|
||||
NoteManager[] managers; //The list of noteManagers 0 means there is no manager
|
||||
Vault public vault;
|
||||
|
||||
// this mapping allows you to search for a specific note's index number by the hash of that note
|
||||
|
@ -82,6 +98,8 @@ contract LiquidPledgingBase {
|
|||
// Constructor
|
||||
//////
|
||||
|
||||
/// @notice The Constructor creates the `LiquidPledgingBase` on the blockchain
|
||||
/// @param _vault Where the ETH is stored that the pledges represent
|
||||
function LiquidPledgingBase(address _vault) {
|
||||
managers.length = 1; // we reserve the 0 manager
|
||||
notes.length = 1; // we reserve the 0 note
|
||||
|
@ -93,7 +111,9 @@ contract LiquidPledgingBase {
|
|||
// Managers functions
|
||||
//////
|
||||
|
||||
function addDonor(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDonor) {//Todo return idManager
|
||||
/// @notice Creates a donor.
|
||||
function addDonor(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idDonor) {
|
||||
|
||||
idDonor = uint64(managers.length);
|
||||
|
||||
|
@ -111,6 +131,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
event DonorAdded(uint64 indexed idDonor);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific donor
|
||||
function updateDonor(
|
||||
uint64 idDonor,
|
||||
address newAddr,
|
||||
|
@ -118,8 +139,8 @@ contract LiquidPledgingBase {
|
|||
uint64 newCommitTime)
|
||||
{
|
||||
NoteManager storage donor = findManager(idDonor);
|
||||
require(donor.managerType == NoteManagerType.Donor);
|
||||
require(donor.addr == msg.sender);
|
||||
require(donor.managerType == NoteManagerType.Donor);//Must be a Giver
|
||||
require(donor.addr == msg.sender);//current addr had to originate this tx
|
||||
donor.addr = newAddr;
|
||||
donor.name = newName;
|
||||
donor.commitTime = newCommitTime;
|
||||
|
@ -128,6 +149,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
event DonorUpdated(uint64 indexed idDonor);
|
||||
|
||||
/// @notice Creates a new Delegate
|
||||
function addDelegate(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDelegate) { //TODO return index number
|
||||
|
||||
idDelegate = uint64(managers.length);
|
||||
|
@ -141,11 +163,12 @@ contract LiquidPledgingBase {
|
|||
false,
|
||||
plugin));
|
||||
|
||||
DeegateAdded(idDelegate);
|
||||
DelegateAdded(idDelegate);
|
||||
}
|
||||
|
||||
event DeegateAdded(uint64 indexed idDelegate);
|
||||
event DelegateAdded(uint64 indexed idDelegate);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific delegate
|
||||
function updateDelegate(
|
||||
uint64 idDelegate,
|
||||
address newAddr,
|
||||
|
@ -162,6 +185,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
event DelegateUpdated(uint64 indexed idDelegate);
|
||||
|
||||
/// @notice Creates a new Campaign
|
||||
function addProject(string name, address projectManager, uint64 parentProject, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idProject) {
|
||||
if (parentProject != 0) {
|
||||
NoteManager storage pm = findManager(parentProject);
|
||||
|
@ -187,6 +211,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
event ProjectAdded(uint64 indexed idProject);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific Campaign
|
||||
function updateProject(
|
||||
uint64 idProject,
|
||||
address newAddr,
|
||||
|
@ -209,11 +234,11 @@ contract LiquidPledgingBase {
|
|||
// Public constant functions
|
||||
//////////
|
||||
|
||||
|
||||
/// @notice Public constant that states how many notes are in the system
|
||||
function numberOfNotes() constant returns (uint) {
|
||||
return notes.length - 1;
|
||||
}
|
||||
|
||||
/// @notice Public constant that states the details of the specified Note
|
||||
function getNote(uint64 idNote) constant returns(
|
||||
uint amount,
|
||||
uint64 owner,
|
||||
|
@ -232,7 +257,8 @@ contract LiquidPledgingBase {
|
|||
oldNote = n.oldNote;
|
||||
paymentState = n.paymentState;
|
||||
}
|
||||
// This is to return the delegates one by one, because you can not return an array
|
||||
/// @notice Public constant that states the delegates one by one, because
|
||||
/// an array cannot be returned
|
||||
function getNoteDelegate(uint64 idNote, uint idxDelegate) constant returns(
|
||||
uint64 idDelegate,
|
||||
address addr,
|
||||
|
@ -244,18 +270,19 @@ contract LiquidPledgingBase {
|
|||
addr = delegate.addr;
|
||||
name = delegate.name;
|
||||
}
|
||||
|
||||
/// @notice Public constant that states the number of admins in the system
|
||||
function numberOfNoteManagers() constant returns(uint) {
|
||||
return managers.length - 1;
|
||||
}
|
||||
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
function getNoteManager(uint64 idManager) constant returns (
|
||||
NoteManagerType managerType,
|
||||
address addr,
|
||||
string name,
|
||||
uint64 commitTime,
|
||||
uint64 parentProject,
|
||||
bool canceled)
|
||||
bool canceled,
|
||||
address plugin)
|
||||
{
|
||||
NoteManager storage m = findManager(idManager);
|
||||
managerType = m.managerType;
|
||||
|
@ -264,15 +291,17 @@ contract LiquidPledgingBase {
|
|||
commitTime = m.commitTime;
|
||||
parentProject = m.parentProject;
|
||||
canceled = m.canceled;
|
||||
plugin = address(m.plugin);
|
||||
}
|
||||
|
||||
////////
|
||||
// Private methods
|
||||
///////
|
||||
|
||||
// All notes exist... but if the note hasn't been created in this system yet then it wouldn't
|
||||
// be in the hash array hNoteddx[]
|
||||
// this function creates a balloon if one is not created already... this ballon has 0 for the amount
|
||||
/// @notice All notes technically exist... but if the note hasn't been
|
||||
/// created in this system yet then it wouldn't be in the hash array
|
||||
/// hNoteddx[]; this creates a Pledge with and amount of 0 if one is not
|
||||
/// created already...
|
||||
function findNote(
|
||||
uint64 owner,
|
||||
uint64[] delegationChain,
|
||||
|
@ -305,7 +334,7 @@ contract LiquidPledgingBase {
|
|||
uint64 constant NOTFOUND = 0xFFFFFFFFFFFFFFFF;
|
||||
|
||||
// helper function that searches the delegationChain fro a specific delegate and
|
||||
// level of delegation returns their idx in the delegation cahin which reflect their level of authority
|
||||
// level of delegation returns their idx in the delegation chain which reflect their level of authority
|
||||
function getDelegateIdx(Note n, uint64 idDelegate) internal returns(uint64) {
|
||||
for (uint i=0; i<n.delegationChain.length; i++) {
|
||||
if (n.delegationChain[i] == idDelegate) return uint64(i);
|
||||
|
@ -361,8 +390,8 @@ contract LiquidPledgingBase {
|
|||
return isProjectCanceled2(m.parentProject);
|
||||
}
|
||||
|
||||
// this makes it easy to cancel projects
|
||||
// @param idNote the note that may or may not be cancelled
|
||||
// @notice A helper function for canceling projects
|
||||
// @param idNote the note that may or may not be canceled
|
||||
function getOldestNoteNotCanceled(uint64 idNote) internal constant returns(uint64) { //todo rename
|
||||
if (idNote == 0) return 0;
|
||||
Note storage n = findNote(idNote);
|
||||
|
@ -379,8 +408,4 @@ contract LiquidPledgingBase {
|
|||
function checkManagerOwner(NoteManager m) internal constant {
|
||||
require((msg.sender == m.addr) || (msg.sender == address(m.plugin)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -3,21 +3,34 @@
|
|||
pragma solidity ^0.4.11;
|
||||
|
||||
contract ILiquidPledgingPlugin {
|
||||
|
||||
/// @param context In which context it is affected.
|
||||
/// 0 -> owner from
|
||||
/// 1 -> First delegate from
|
||||
/// 2 -> Second delegate from
|
||||
/// @notice Plugins are used (much like web hooks) to initiate an action
|
||||
/// upon any donation, delegation, or transfer; this is an optional feature
|
||||
/// and allows for extreme customization of the contract
|
||||
/// @param context The situation that is triggering the plugin:
|
||||
/// 0 -> Plugin for the owner transferring pledge to another party
|
||||
/// 1 -> Plugin for the first delegate transferring pledge to another party
|
||||
/// 2 -> Plugin for the second delegate transferring pledge to another party
|
||||
/// ...
|
||||
/// 255 -> proposedProject from
|
||||
/// 255 -> Plugin for the proposedProject transferring pledge to another party
|
||||
///
|
||||
/// 256 -> owner to
|
||||
/// 257 -> First delegate to
|
||||
/// 258 -> Second delegate to
|
||||
/// 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 -> proposedProject to
|
||||
function beforeTransfer(uint64 noteManager, uint64 noteFrom, uint64 noteTo, uint64 context, uint amount) returns (uint maxAllowed);
|
||||
function afterTransfer(uint64 noteManager, uint64 noteFrom, uint64 noteTo, uint64 context, uint amount);
|
||||
/// 511 -> Plugin for the proposedProject receiving pledge to another party
|
||||
function beforeTransfer(
|
||||
uint64 noteManager,
|
||||
uint64 noteFrom,
|
||||
uint64 noteTo,
|
||||
uint64 context,
|
||||
uint amount
|
||||
) returns (uint maxAllowed);
|
||||
function afterTransfer(
|
||||
uint64 noteManager,
|
||||
uint64 noteFrom,
|
||||
uint64 noteTo,
|
||||
uint64 context,
|
||||
uint amount);
|
||||
}
|
||||
|
||||
//File: contracts/LiquidPledgingBase.sol
|
||||
|
@ -25,43 +38,46 @@ pragma solidity ^0.4.11;
|
|||
|
||||
|
||||
|
||||
/// @dev This is declares a few functions from `Vault` so that the
|
||||
/// `LiquidPledgingBase` contract can interface with the `Vault` contract
|
||||
contract Vault {
|
||||
function authorizePayment(bytes32 _ref, address _dest, uint _amount);
|
||||
function () payable;
|
||||
}
|
||||
|
||||
contract LiquidPledgingBase {
|
||||
|
||||
// Limits inserted to prevent large loops that could prevent canceling
|
||||
uint constant MAX_DELEGATES = 20;
|
||||
uint constant MAX_SUBPROJECT_LEVEL = 20;
|
||||
uint constant MAX_INTERPROJECT_LEVEL = 20;
|
||||
|
||||
enum NoteManagerType { Donor, Delegate, Project }// todo change name
|
||||
enum PaymentState { NotPaid, Paying, Paid }
|
||||
enum NoteManagerType { Donor, Delegate, Project } // todo change name Donor Project
|
||||
enum PaymentState { NotPaid, Paying, Paid } // TODO name change NotPaid
|
||||
|
||||
// This struct defines the details of each the NoteManager, these NoteManagers can create
|
||||
struct NoteManager {// change manager
|
||||
NoteManagerType managerType;
|
||||
address addr;
|
||||
string name;
|
||||
uint64 commitTime; // Only used in donors and projects, its the precommitment time
|
||||
uint64 parentProject; // Only for projects
|
||||
bool canceled; // Only for project
|
||||
ILiquidPledgingPlugin plugin; // Handler that is called when one call is affected.
|
||||
/// @dev This struct defines the details of each the NoteManager, these
|
||||
/// NoteManagers can own notes and act as delegates
|
||||
struct NoteManager { // TODO name change NoteManager
|
||||
NoteManagerType managerType; // Giver, Delegate or Campaign
|
||||
address addr; // account or contract address for admin
|
||||
string name;
|
||||
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
|
||||
uint64 parentProject; // Only for campaigns
|
||||
bool canceled; //Always false except for canceled campaigns
|
||||
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
|
||||
}
|
||||
|
||||
struct Note {
|
||||
uint amount;
|
||||
uint64 owner;
|
||||
uint64[] delegationChain; //index numbers!!!!!
|
||||
uint64 owner; //NoteManager
|
||||
uint64[] delegationChain; // list of index numbers
|
||||
uint64 proposedProject; // TODO change the name only used for when delegates are precommiting to a project
|
||||
uint64 commitTime; // At what time the upcoming time will become an owner.
|
||||
uint64 commitTime; // When the proposedProject will become the owner
|
||||
uint64 oldNote; // this points to the Note[] index that the Note was derived from
|
||||
PaymentState paymentState;
|
||||
}
|
||||
|
||||
Note[] notes;
|
||||
NoteManager[] managers; // the list of all the note managers 0 is reserved for no manager
|
||||
NoteManager[] managers; //The list of noteManagers 0 means there is no manager
|
||||
Vault public vault;
|
||||
|
||||
// this mapping allows you to search for a specific note's index number by the hash of that note
|
||||
|
@ -82,6 +98,8 @@ contract LiquidPledgingBase {
|
|||
// Constructor
|
||||
//////
|
||||
|
||||
/// @notice The Constructor creates the `LiquidPledgingBase` on the blockchain
|
||||
/// @param _vault Where the ETH is stored that the pledges represent
|
||||
function LiquidPledgingBase(address _vault) {
|
||||
managers.length = 1; // we reserve the 0 manager
|
||||
notes.length = 1; // we reserve the 0 note
|
||||
|
@ -93,7 +111,9 @@ contract LiquidPledgingBase {
|
|||
// Managers functions
|
||||
//////
|
||||
|
||||
function addDonor(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDonor) {//Todo return idManager
|
||||
/// @notice Creates a donor.
|
||||
function addDonor(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idDonor) {
|
||||
|
||||
idDonor = uint64(managers.length);
|
||||
|
||||
|
@ -111,6 +131,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
event DonorAdded(uint64 indexed idDonor);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific donor
|
||||
function updateDonor(
|
||||
uint64 idDonor,
|
||||
address newAddr,
|
||||
|
@ -118,8 +139,8 @@ contract LiquidPledgingBase {
|
|||
uint64 newCommitTime)
|
||||
{
|
||||
NoteManager storage donor = findManager(idDonor);
|
||||
require(donor.managerType == NoteManagerType.Donor);
|
||||
require(donor.addr == msg.sender);
|
||||
require(donor.managerType == NoteManagerType.Donor);//Must be a Giver
|
||||
require(donor.addr == msg.sender);//current addr had to originate this tx
|
||||
donor.addr = newAddr;
|
||||
donor.name = newName;
|
||||
donor.commitTime = newCommitTime;
|
||||
|
@ -128,6 +149,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
event DonorUpdated(uint64 indexed idDonor);
|
||||
|
||||
/// @notice Creates a new Delegate
|
||||
function addDelegate(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDelegate) { //TODO return index number
|
||||
|
||||
idDelegate = uint64(managers.length);
|
||||
|
@ -141,11 +163,12 @@ contract LiquidPledgingBase {
|
|||
false,
|
||||
plugin));
|
||||
|
||||
DeegateAdded(idDelegate);
|
||||
DelegateAdded(idDelegate);
|
||||
}
|
||||
|
||||
event DeegateAdded(uint64 indexed idDelegate);
|
||||
event DelegateAdded(uint64 indexed idDelegate);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific delegate
|
||||
function updateDelegate(
|
||||
uint64 idDelegate,
|
||||
address newAddr,
|
||||
|
@ -162,6 +185,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
event DelegateUpdated(uint64 indexed idDelegate);
|
||||
|
||||
/// @notice Creates a new Campaign
|
||||
function addProject(string name, address projectManager, uint64 parentProject, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idProject) {
|
||||
if (parentProject != 0) {
|
||||
NoteManager storage pm = findManager(parentProject);
|
||||
|
@ -187,6 +211,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
event ProjectAdded(uint64 indexed idProject);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific Campaign
|
||||
function updateProject(
|
||||
uint64 idProject,
|
||||
address newAddr,
|
||||
|
@ -209,11 +234,11 @@ contract LiquidPledgingBase {
|
|||
// Public constant functions
|
||||
//////////
|
||||
|
||||
|
||||
/// @notice Public constant that states how many notes are in the system
|
||||
function numberOfNotes() constant returns (uint) {
|
||||
return notes.length - 1;
|
||||
}
|
||||
|
||||
/// @notice Public constant that states the details of the specified Note
|
||||
function getNote(uint64 idNote) constant returns(
|
||||
uint amount,
|
||||
uint64 owner,
|
||||
|
@ -232,7 +257,8 @@ contract LiquidPledgingBase {
|
|||
oldNote = n.oldNote;
|
||||
paymentState = n.paymentState;
|
||||
}
|
||||
// This is to return the delegates one by one, because you can not return an array
|
||||
/// @notice Public constant that states the delegates one by one, because
|
||||
/// an array cannot be returned
|
||||
function getNoteDelegate(uint64 idNote, uint idxDelegate) constant returns(
|
||||
uint64 idDelegate,
|
||||
address addr,
|
||||
|
@ -244,18 +270,19 @@ contract LiquidPledgingBase {
|
|||
addr = delegate.addr;
|
||||
name = delegate.name;
|
||||
}
|
||||
|
||||
/// @notice Public constant that states the number of admins in the system
|
||||
function numberOfNoteManagers() constant returns(uint) {
|
||||
return managers.length - 1;
|
||||
}
|
||||
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
function getNoteManager(uint64 idManager) constant returns (
|
||||
NoteManagerType managerType,
|
||||
address addr,
|
||||
string name,
|
||||
uint64 commitTime,
|
||||
uint64 parentProject,
|
||||
bool canceled)
|
||||
bool canceled,
|
||||
address plugin)
|
||||
{
|
||||
NoteManager storage m = findManager(idManager);
|
||||
managerType = m.managerType;
|
||||
|
@ -264,15 +291,17 @@ contract LiquidPledgingBase {
|
|||
commitTime = m.commitTime;
|
||||
parentProject = m.parentProject;
|
||||
canceled = m.canceled;
|
||||
plugin = address(m.plugin);
|
||||
}
|
||||
|
||||
////////
|
||||
// Private methods
|
||||
///////
|
||||
|
||||
// All notes exist... but if the note hasn't been created in this system yet then it wouldn't
|
||||
// be in the hash array hNoteddx[]
|
||||
// this function creates a balloon if one is not created already... this ballon has 0 for the amount
|
||||
/// @notice All notes technically exist... but if the note hasn't been
|
||||
/// created in this system yet then it wouldn't be in the hash array
|
||||
/// hNoteddx[]; this creates a Pledge with and amount of 0 if one is not
|
||||
/// created already...
|
||||
function findNote(
|
||||
uint64 owner,
|
||||
uint64[] delegationChain,
|
||||
|
@ -305,7 +334,7 @@ contract LiquidPledgingBase {
|
|||
uint64 constant NOTFOUND = 0xFFFFFFFFFFFFFFFF;
|
||||
|
||||
// helper function that searches the delegationChain fro a specific delegate and
|
||||
// level of delegation returns their idx in the delegation cahin which reflect their level of authority
|
||||
// level of delegation returns their idx in the delegation chain which reflect their level of authority
|
||||
function getDelegateIdx(Note n, uint64 idDelegate) internal returns(uint64) {
|
||||
for (uint i=0; i<n.delegationChain.length; i++) {
|
||||
if (n.delegationChain[i] == idDelegate) return uint64(i);
|
||||
|
@ -361,8 +390,8 @@ contract LiquidPledgingBase {
|
|||
return isProjectCanceled2(m.parentProject);
|
||||
}
|
||||
|
||||
// this makes it easy to cancel projects
|
||||
// @param idNote the note that may or may not be cancelled
|
||||
// @notice A helper function for canceling projects
|
||||
// @param idNote the note that may or may not be canceled
|
||||
function getOldestNoteNotCanceled(uint64 idNote) internal constant returns(uint64) { //todo rename
|
||||
if (idNote == 0) return 0;
|
||||
Note storage n = findNote(idNote);
|
||||
|
@ -379,10 +408,6 @@ contract LiquidPledgingBase {
|
|||
function checkManagerOwner(NoteManager m) internal constant {
|
||||
require((msg.sender == m.addr) || (msg.sender == address(m.plugin)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//File: contracts/LiquidPledging.sol
|
||||
|
@ -398,19 +423,23 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
// Constructor
|
||||
//////
|
||||
|
||||
// This constructor actualy also calls the constructor for the
|
||||
// `LiquidPledgingBase` contract
|
||||
// This constructor also calls the constructor for `LiquidPledgingBase`
|
||||
function LiquidPledging(address _vault) LiquidPledgingBase(_vault) {
|
||||
}
|
||||
|
||||
/// @notice This is how value enters into the system which creates notes. The
|
||||
/// token of value goes into the vault and then the amount in the Note
|
||||
/// relevant to this donor without delegates is increased.
|
||||
/// After that, a normal transfer is done to the idReceiver.
|
||||
/// @notice This is how value enters into the system which creates pledges;
|
||||
/// the token of value goes into the vault and the amount in the pledge
|
||||
/// relevant to this Giver without delegates is increased, and a normal
|
||||
/// transfer is done to the idReceiver
|
||||
/// @param idDonor Identifier of the donor thats donating.
|
||||
/// @param idReceiver To whom it's transfered. Can be the same donor, another
|
||||
/// donor, a delegate or a project
|
||||
function donate(uint64 idDonor, uint64 idReceiver) payable {// TODO change to `pledge()`
|
||||
|
||||
function donate(uint64 idDonor, uint64 idReceiver) payable {
|
||||
if (idDonor == 0) {
|
||||
idDonor = addDonor('', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
|
||||
}
|
||||
|
||||
NoteManager storage sender = findManager(idDonor);
|
||||
|
||||
checkManagerOwner(sender);
|
||||
|
@ -424,7 +453,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
vault.transfer(amount); // transfers the baseToken to the Vault
|
||||
uint64 idNote = findNote(
|
||||
idDonor,
|
||||
new uint64[](0), //what is new
|
||||
new uint64[](0), //what is new?
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -440,9 +469,9 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
}
|
||||
|
||||
|
||||
/// @notice This is the main function to move value from one Note to the other
|
||||
/// @param idSender ID of the donor, delegate or project manager that is transfering
|
||||
/// the funds from Note to Note. This manager must have permisions to move the value
|
||||
/// @notice Moves value between notes
|
||||
/// @param idSender ID of the donor, delegate or project manager that is transferring
|
||||
/// the funds from Note to Note. This manager must have permissions to move the value
|
||||
/// @param idNote Id of the note that's moving the value
|
||||
/// @param amount Quantity of value that's being moved
|
||||
/// @param idReceiver Destination of the value, can be a donor sending to a donor or
|
||||
|
@ -526,8 +555,8 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
/// @notice This method is used to withdraw value from the system. This can be used
|
||||
/// by the donors to avoid committing the donation or by project manager to use
|
||||
/// the Ether.
|
||||
/// @param idNote Id of the note that wants to be withdrawed.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawed.
|
||||
/// @param idNote Id of the note that wants to be withdrawn.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawn.
|
||||
function withdraw(uint64 idNote, uint amount) {
|
||||
|
||||
idNote = normalizeNote(idNote);
|
||||
|
@ -555,8 +584,8 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
}
|
||||
|
||||
/// @notice Method called by the vault to confirm a payment.
|
||||
/// @param idNote Id of the note that wants to be withdrawed.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawed.
|
||||
/// @param idNote Id of the note that wants to be withdrawn.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawn.
|
||||
function confirmPayment(uint64 idNote, uint amount) onlyVault {
|
||||
Note storage n = findNote(idNote);
|
||||
|
||||
|
@ -585,7 +614,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
|
||||
require(n.paymentState == PaymentState.Paying); //TODO change to revert
|
||||
|
||||
// When a payment is cacnceled, never is assigned to a project.
|
||||
// When a payment is canceled, never is assigned to a project.
|
||||
uint64 oldNote = findNote(
|
||||
n.owner,
|
||||
n.delegationChain,
|
||||
|
@ -606,6 +635,8 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
NoteManager storage project = findManager(idProject);
|
||||
checkManagerOwner(project);
|
||||
project.canceled = true;
|
||||
|
||||
CancelProject(idProject);
|
||||
}
|
||||
|
||||
|
||||
|
@ -677,7 +708,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
///////
|
||||
|
||||
// this function is obvious, but it can also be called to undelegate everyone
|
||||
// by setting your self as teh idReceiver
|
||||
// by setting yourself as the idReceiver
|
||||
function transferOwnershipToProject(uint64 idNote, uint amount, uint64 idReceiver) internal {
|
||||
Note storage n = findNote(idNote);
|
||||
|
||||
|
@ -732,7 +763,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
doTransfer(idNote, toNote, amount);
|
||||
}
|
||||
|
||||
/// @param q Unmber of undelegations
|
||||
/// @param q Number of undelegations
|
||||
function undelegate(uint64 idNote, uint amount, uint q) internal {
|
||||
Note storage n = findNote(idNote);
|
||||
uint64[] memory newDelegationChain = new uint64[](n.delegationChain.length - q);
|
||||
|
@ -780,13 +811,13 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
}
|
||||
|
||||
// This function does 2 things, #1: it checks to make sure that the pledges are correct
|
||||
// if the a pledged project has already been commited then it changes the owner
|
||||
// if the a pledged project has already been committed then it changes the owner
|
||||
// to be the proposed project (Note that the UI will have to read the commit time and manually
|
||||
// do what this function does to the note for the end user at the expiration of the committime)
|
||||
// do what this function does to the note 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 projects,
|
||||
// then it adjusts the note's owner appropriately.
|
||||
// This call can be called from any body at any time on any node. In general it can be called
|
||||
// to froce the calls of the affected plugins.
|
||||
// to force the calls of the affected plugins, which also need to be predicted by the UI
|
||||
function normalizeNote(uint64 idNote) returns(uint64) {
|
||||
Note storage n = findNote(idNote);
|
||||
|
||||
|
@ -873,6 +904,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
}
|
||||
|
||||
event Transfer(uint64 indexed from, uint64 indexed to, uint amount);
|
||||
event CancelProject(uint64 indexed idProject);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3,21 +3,34 @@
|
|||
pragma solidity ^0.4.11;
|
||||
|
||||
contract ILiquidPledgingPlugin {
|
||||
|
||||
/// @param context In which context it is affected.
|
||||
/// 0 -> owner from
|
||||
/// 1 -> First delegate from
|
||||
/// 2 -> Second delegate from
|
||||
/// @notice Plugins are used (much like web hooks) to initiate an action
|
||||
/// upon any donation, delegation, or transfer; this is an optional feature
|
||||
/// and allows for extreme customization of the contract
|
||||
/// @param context The situation that is triggering the plugin:
|
||||
/// 0 -> Plugin for the owner transferring pledge to another party
|
||||
/// 1 -> Plugin for the first delegate transferring pledge to another party
|
||||
/// 2 -> Plugin for the second delegate transferring pledge to another party
|
||||
/// ...
|
||||
/// 255 -> proposedProject from
|
||||
/// 255 -> Plugin for the proposedProject transferring pledge to another party
|
||||
///
|
||||
/// 256 -> owner to
|
||||
/// 257 -> First delegate to
|
||||
/// 258 -> Second delegate to
|
||||
/// 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 -> proposedProject to
|
||||
function beforeTransfer(uint64 noteManager, uint64 noteFrom, uint64 noteTo, uint64 context, uint amount) returns (uint maxAllowed);
|
||||
function afterTransfer(uint64 noteManager, uint64 noteFrom, uint64 noteTo, uint64 context, uint amount);
|
||||
/// 511 -> Plugin for the proposedProject receiving pledge to another party
|
||||
function beforeTransfer(
|
||||
uint64 noteManager,
|
||||
uint64 noteFrom,
|
||||
uint64 noteTo,
|
||||
uint64 context,
|
||||
uint amount
|
||||
) returns (uint maxAllowed);
|
||||
function afterTransfer(
|
||||
uint64 noteManager,
|
||||
uint64 noteFrom,
|
||||
uint64 noteTo,
|
||||
uint64 context,
|
||||
uint amount);
|
||||
}
|
||||
|
||||
//File: contracts/LiquidPledgingBase.sol
|
||||
|
@ -25,43 +38,46 @@ pragma solidity ^0.4.11;
|
|||
|
||||
|
||||
|
||||
/// @dev This is declares a few functions from `Vault` so that the
|
||||
/// `LiquidPledgingBase` contract can interface with the `Vault` contract
|
||||
contract Vault {
|
||||
function authorizePayment(bytes32 _ref, address _dest, uint _amount);
|
||||
function () payable;
|
||||
}
|
||||
|
||||
contract LiquidPledgingBase {
|
||||
|
||||
// Limits inserted to prevent large loops that could prevent canceling
|
||||
uint constant MAX_DELEGATES = 20;
|
||||
uint constant MAX_SUBPROJECT_LEVEL = 20;
|
||||
uint constant MAX_INTERPROJECT_LEVEL = 20;
|
||||
|
||||
enum NoteManagerType { Donor, Delegate, Project }// todo change name
|
||||
enum PaymentState { NotPaid, Paying, Paid }
|
||||
enum NoteManagerType { Donor, Delegate, Project } // todo change name Donor Project
|
||||
enum PaymentState { NotPaid, Paying, Paid } // TODO name change NotPaid
|
||||
|
||||
// This struct defines the details of each the NoteManager, these NoteManagers can create
|
||||
struct NoteManager {// change manager
|
||||
NoteManagerType managerType;
|
||||
address addr;
|
||||
string name;
|
||||
uint64 commitTime; // Only used in donors and projects, its the precommitment time
|
||||
uint64 parentProject; // Only for projects
|
||||
bool canceled; // Only for project
|
||||
ILiquidPledgingPlugin plugin; // Handler that is called when one call is affected.
|
||||
/// @dev This struct defines the details of each the NoteManager, these
|
||||
/// NoteManagers can own notes and act as delegates
|
||||
struct NoteManager { // TODO name change NoteManager
|
||||
NoteManagerType managerType; // Giver, Delegate or Campaign
|
||||
address addr; // account or contract address for admin
|
||||
string name;
|
||||
uint64 commitTime; // In seconds, used for Givers' & Delegates' vetos
|
||||
uint64 parentProject; // Only for campaigns
|
||||
bool canceled; //Always false except for canceled campaigns
|
||||
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
|
||||
}
|
||||
|
||||
struct Note {
|
||||
uint amount;
|
||||
uint64 owner;
|
||||
uint64[] delegationChain; //index numbers!!!!!
|
||||
uint64 owner; //NoteManager
|
||||
uint64[] delegationChain; // list of index numbers
|
||||
uint64 proposedProject; // TODO change the name only used for when delegates are precommiting to a project
|
||||
uint64 commitTime; // At what time the upcoming time will become an owner.
|
||||
uint64 commitTime; // When the proposedProject will become the owner
|
||||
uint64 oldNote; // this points to the Note[] index that the Note was derived from
|
||||
PaymentState paymentState;
|
||||
}
|
||||
|
||||
Note[] notes;
|
||||
NoteManager[] managers; // the list of all the note managers 0 is reserved for no manager
|
||||
NoteManager[] managers; //The list of noteManagers 0 means there is no manager
|
||||
Vault public vault;
|
||||
|
||||
// this mapping allows you to search for a specific note's index number by the hash of that note
|
||||
|
@ -82,6 +98,8 @@ contract LiquidPledgingBase {
|
|||
// Constructor
|
||||
//////
|
||||
|
||||
/// @notice The Constructor creates the `LiquidPledgingBase` on the blockchain
|
||||
/// @param _vault Where the ETH is stored that the pledges represent
|
||||
function LiquidPledgingBase(address _vault) {
|
||||
managers.length = 1; // we reserve the 0 manager
|
||||
notes.length = 1; // we reserve the 0 note
|
||||
|
@ -93,7 +111,9 @@ contract LiquidPledgingBase {
|
|||
// Managers functions
|
||||
//////
|
||||
|
||||
function addDonor(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDonor) {//Todo return idManager
|
||||
/// @notice Creates a donor.
|
||||
function addDonor(string name, uint64 commitTime, ILiquidPledgingPlugin plugin
|
||||
) returns (uint64 idDonor) {
|
||||
|
||||
idDonor = uint64(managers.length);
|
||||
|
||||
|
@ -111,6 +131,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
event DonorAdded(uint64 indexed idDonor);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific donor
|
||||
function updateDonor(
|
||||
uint64 idDonor,
|
||||
address newAddr,
|
||||
|
@ -118,8 +139,8 @@ contract LiquidPledgingBase {
|
|||
uint64 newCommitTime)
|
||||
{
|
||||
NoteManager storage donor = findManager(idDonor);
|
||||
require(donor.managerType == NoteManagerType.Donor);
|
||||
require(donor.addr == msg.sender);
|
||||
require(donor.managerType == NoteManagerType.Donor);//Must be a Giver
|
||||
require(donor.addr == msg.sender);//current addr had to originate this tx
|
||||
donor.addr = newAddr;
|
||||
donor.name = newName;
|
||||
donor.commitTime = newCommitTime;
|
||||
|
@ -128,6 +149,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
event DonorUpdated(uint64 indexed idDonor);
|
||||
|
||||
/// @notice Creates a new Delegate
|
||||
function addDelegate(string name, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idDelegate) { //TODO return index number
|
||||
|
||||
idDelegate = uint64(managers.length);
|
||||
|
@ -141,11 +163,12 @@ contract LiquidPledgingBase {
|
|||
false,
|
||||
plugin));
|
||||
|
||||
DeegateAdded(idDelegate);
|
||||
DelegateAdded(idDelegate);
|
||||
}
|
||||
|
||||
event DeegateAdded(uint64 indexed idDelegate);
|
||||
event DelegateAdded(uint64 indexed idDelegate);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific delegate
|
||||
function updateDelegate(
|
||||
uint64 idDelegate,
|
||||
address newAddr,
|
||||
|
@ -162,6 +185,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
event DelegateUpdated(uint64 indexed idDelegate);
|
||||
|
||||
/// @notice Creates a new Campaign
|
||||
function addProject(string name, address projectManager, uint64 parentProject, uint64 commitTime, ILiquidPledgingPlugin plugin) returns (uint64 idProject) {
|
||||
if (parentProject != 0) {
|
||||
NoteManager storage pm = findManager(parentProject);
|
||||
|
@ -187,6 +211,7 @@ contract LiquidPledgingBase {
|
|||
|
||||
event ProjectAdded(uint64 indexed idProject);
|
||||
|
||||
///@notice Changes the address, name or commitTime associated with a specific Campaign
|
||||
function updateProject(
|
||||
uint64 idProject,
|
||||
address newAddr,
|
||||
|
@ -209,11 +234,11 @@ contract LiquidPledgingBase {
|
|||
// Public constant functions
|
||||
//////////
|
||||
|
||||
|
||||
/// @notice Public constant that states how many notes are in the system
|
||||
function numberOfNotes() constant returns (uint) {
|
||||
return notes.length - 1;
|
||||
}
|
||||
|
||||
/// @notice Public constant that states the details of the specified Note
|
||||
function getNote(uint64 idNote) constant returns(
|
||||
uint amount,
|
||||
uint64 owner,
|
||||
|
@ -232,7 +257,8 @@ contract LiquidPledgingBase {
|
|||
oldNote = n.oldNote;
|
||||
paymentState = n.paymentState;
|
||||
}
|
||||
// This is to return the delegates one by one, because you can not return an array
|
||||
/// @notice Public constant that states the delegates one by one, because
|
||||
/// an array cannot be returned
|
||||
function getNoteDelegate(uint64 idNote, uint idxDelegate) constant returns(
|
||||
uint64 idDelegate,
|
||||
address addr,
|
||||
|
@ -244,18 +270,19 @@ contract LiquidPledgingBase {
|
|||
addr = delegate.addr;
|
||||
name = delegate.name;
|
||||
}
|
||||
|
||||
/// @notice Public constant that states the number of admins in the system
|
||||
function numberOfNoteManagers() constant returns(uint) {
|
||||
return managers.length - 1;
|
||||
}
|
||||
|
||||
/// @notice Public constant that states the details of the specified admin
|
||||
function getNoteManager(uint64 idManager) constant returns (
|
||||
NoteManagerType managerType,
|
||||
address addr,
|
||||
string name,
|
||||
uint64 commitTime,
|
||||
uint64 parentProject,
|
||||
bool canceled)
|
||||
bool canceled,
|
||||
address plugin)
|
||||
{
|
||||
NoteManager storage m = findManager(idManager);
|
||||
managerType = m.managerType;
|
||||
|
@ -264,15 +291,17 @@ contract LiquidPledgingBase {
|
|||
commitTime = m.commitTime;
|
||||
parentProject = m.parentProject;
|
||||
canceled = m.canceled;
|
||||
plugin = address(m.plugin);
|
||||
}
|
||||
|
||||
////////
|
||||
// Private methods
|
||||
///////
|
||||
|
||||
// All notes exist... but if the note hasn't been created in this system yet then it wouldn't
|
||||
// be in the hash array hNoteddx[]
|
||||
// this function creates a balloon if one is not created already... this ballon has 0 for the amount
|
||||
/// @notice All notes technically exist... but if the note hasn't been
|
||||
/// created in this system yet then it wouldn't be in the hash array
|
||||
/// hNoteddx[]; this creates a Pledge with and amount of 0 if one is not
|
||||
/// created already...
|
||||
function findNote(
|
||||
uint64 owner,
|
||||
uint64[] delegationChain,
|
||||
|
@ -305,7 +334,7 @@ contract LiquidPledgingBase {
|
|||
uint64 constant NOTFOUND = 0xFFFFFFFFFFFFFFFF;
|
||||
|
||||
// helper function that searches the delegationChain fro a specific delegate and
|
||||
// level of delegation returns their idx in the delegation cahin which reflect their level of authority
|
||||
// level of delegation returns their idx in the delegation chain which reflect their level of authority
|
||||
function getDelegateIdx(Note n, uint64 idDelegate) internal returns(uint64) {
|
||||
for (uint i=0; i<n.delegationChain.length; i++) {
|
||||
if (n.delegationChain[i] == idDelegate) return uint64(i);
|
||||
|
@ -361,8 +390,8 @@ contract LiquidPledgingBase {
|
|||
return isProjectCanceled2(m.parentProject);
|
||||
}
|
||||
|
||||
// this makes it easy to cancel projects
|
||||
// @param idNote the note that may or may not be cancelled
|
||||
// @notice A helper function for canceling projects
|
||||
// @param idNote the note that may or may not be canceled
|
||||
function getOldestNoteNotCanceled(uint64 idNote) internal constant returns(uint64) { //todo rename
|
||||
if (idNote == 0) return 0;
|
||||
Note storage n = findNote(idNote);
|
||||
|
@ -379,10 +408,6 @@ contract LiquidPledgingBase {
|
|||
function checkManagerOwner(NoteManager m) internal constant {
|
||||
require((msg.sender == m.addr) || (msg.sender == address(m.plugin)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//File: ./contracts/LiquidPledging.sol
|
||||
|
@ -398,19 +423,23 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
// Constructor
|
||||
//////
|
||||
|
||||
// This constructor actualy also calls the constructor for the
|
||||
// `LiquidPledgingBase` contract
|
||||
// This constructor also calls the constructor for `LiquidPledgingBase`
|
||||
function LiquidPledging(address _vault) LiquidPledgingBase(_vault) {
|
||||
}
|
||||
|
||||
/// @notice This is how value enters into the system which creates notes. The
|
||||
/// token of value goes into the vault and then the amount in the Note
|
||||
/// relevant to this donor without delegates is increased.
|
||||
/// After that, a normal transfer is done to the idReceiver.
|
||||
/// @notice This is how value enters into the system which creates pledges;
|
||||
/// the token of value goes into the vault and the amount in the pledge
|
||||
/// relevant to this Giver without delegates is increased, and a normal
|
||||
/// transfer is done to the idReceiver
|
||||
/// @param idDonor Identifier of the donor thats donating.
|
||||
/// @param idReceiver To whom it's transfered. Can be the same donor, another
|
||||
/// donor, a delegate or a project
|
||||
function donate(uint64 idDonor, uint64 idReceiver) payable {// TODO change to `pledge()`
|
||||
|
||||
function donate(uint64 idDonor, uint64 idReceiver) payable {
|
||||
if (idDonor == 0) {
|
||||
idDonor = addDonor('', 259200, ILiquidPledgingPlugin(0x0)); // default to 3 day commitTime
|
||||
}
|
||||
|
||||
NoteManager storage sender = findManager(idDonor);
|
||||
|
||||
checkManagerOwner(sender);
|
||||
|
@ -424,7 +453,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
vault.transfer(amount); // transfers the baseToken to the Vault
|
||||
uint64 idNote = findNote(
|
||||
idDonor,
|
||||
new uint64[](0), //what is new
|
||||
new uint64[](0), //what is new?
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
|
@ -440,9 +469,9 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
}
|
||||
|
||||
|
||||
/// @notice This is the main function to move value from one Note to the other
|
||||
/// @param idSender ID of the donor, delegate or project manager that is transfering
|
||||
/// the funds from Note to Note. This manager must have permisions to move the value
|
||||
/// @notice Moves value between notes
|
||||
/// @param idSender ID of the donor, delegate or project manager that is transferring
|
||||
/// the funds from Note to Note. This manager must have permissions to move the value
|
||||
/// @param idNote Id of the note that's moving the value
|
||||
/// @param amount Quantity of value that's being moved
|
||||
/// @param idReceiver Destination of the value, can be a donor sending to a donor or
|
||||
|
@ -526,8 +555,8 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
/// @notice This method is used to withdraw value from the system. This can be used
|
||||
/// by the donors to avoid committing the donation or by project manager to use
|
||||
/// the Ether.
|
||||
/// @param idNote Id of the note that wants to be withdrawed.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawed.
|
||||
/// @param idNote Id of the note that wants to be withdrawn.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawn.
|
||||
function withdraw(uint64 idNote, uint amount) {
|
||||
|
||||
idNote = normalizeNote(idNote);
|
||||
|
@ -555,8 +584,8 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
}
|
||||
|
||||
/// @notice Method called by the vault to confirm a payment.
|
||||
/// @param idNote Id of the note that wants to be withdrawed.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawed.
|
||||
/// @param idNote Id of the note that wants to be withdrawn.
|
||||
/// @param amount Quantity of Ether that wants to be withdrawn.
|
||||
function confirmPayment(uint64 idNote, uint amount) onlyVault {
|
||||
Note storage n = findNote(idNote);
|
||||
|
||||
|
@ -585,7 +614,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
|
||||
require(n.paymentState == PaymentState.Paying); //TODO change to revert
|
||||
|
||||
// When a payment is cacnceled, never is assigned to a project.
|
||||
// When a payment is canceled, never is assigned to a project.
|
||||
uint64 oldNote = findNote(
|
||||
n.owner,
|
||||
n.delegationChain,
|
||||
|
@ -606,6 +635,8 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
NoteManager storage project = findManager(idProject);
|
||||
checkManagerOwner(project);
|
||||
project.canceled = true;
|
||||
|
||||
CancelProject(idProject);
|
||||
}
|
||||
|
||||
|
||||
|
@ -677,7 +708,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
///////
|
||||
|
||||
// this function is obvious, but it can also be called to undelegate everyone
|
||||
// by setting your self as teh idReceiver
|
||||
// by setting yourself as the idReceiver
|
||||
function transferOwnershipToProject(uint64 idNote, uint amount, uint64 idReceiver) internal {
|
||||
Note storage n = findNote(idNote);
|
||||
|
||||
|
@ -732,7 +763,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
doTransfer(idNote, toNote, amount);
|
||||
}
|
||||
|
||||
/// @param q Unmber of undelegations
|
||||
/// @param q Number of undelegations
|
||||
function undelegate(uint64 idNote, uint amount, uint q) internal {
|
||||
Note storage n = findNote(idNote);
|
||||
uint64[] memory newDelegationChain = new uint64[](n.delegationChain.length - q);
|
||||
|
@ -780,13 +811,13 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
}
|
||||
|
||||
// This function does 2 things, #1: it checks to make sure that the pledges are correct
|
||||
// if the a pledged project has already been commited then it changes the owner
|
||||
// if the a pledged project has already been committed then it changes the owner
|
||||
// to be the proposed project (Note that the UI will have to read the commit time and manually
|
||||
// do what this function does to the note for the end user at the expiration of the committime)
|
||||
// do what this function does to the note 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 projects,
|
||||
// then it adjusts the note's owner appropriately.
|
||||
// This call can be called from any body at any time on any node. In general it can be called
|
||||
// to froce the calls of the affected plugins.
|
||||
// to force the calls of the affected plugins, which also need to be predicted by the UI
|
||||
function normalizeNote(uint64 idNote) returns(uint64) {
|
||||
Note storage n = findNote(idNote);
|
||||
|
||||
|
@ -873,5 +904,6 @@ contract LiquidPledging is LiquidPledgingBase {
|
|||
}
|
||||
|
||||
event Transfer(uint64 indexed from, uint64 indexed to, uint amount);
|
||||
event CancelProject(uint64 indexed idProject);
|
||||
|
||||
}
|
||||
|
|
|
@ -303,12 +303,14 @@ describe('LiquidPledging test', () => {
|
|||
assert.equal(collected, 0.95);
|
||||
}).timeout(8000);
|
||||
it('Should make a donation and create donor', async () => {
|
||||
const oldNNotes = await liquidPledging.numberOfNotes();
|
||||
const oldNManagers = await liquidPledging.numberOfNoteManagers();
|
||||
await liquidPledging.donate(0, 1, { from: donor2, value: web3.toWei(1) });
|
||||
const nNotes = await liquidPledging.numberOfNotes();
|
||||
assert.equal(nNotes.toNumber(), 14);
|
||||
assert.equal(nNotes.toNumber(), oldNNotes.toNumber() + 1);
|
||||
const nManagers = await liquidPledging.numberOfNoteManagers();
|
||||
assert.equal(nManagers.toNumber(), 7);
|
||||
const res = await liquidPledging.getNoteManager(7);
|
||||
assert.equal(nManagers.toNumber(), oldNManagers.toNumber() + 1);
|
||||
const res = await liquidPledging.getNoteManager(nManagers);
|
||||
assert.equal(res[0], 0); // Donor
|
||||
assert.equal(res[1], donor2);
|
||||
assert.equal(res[2], '');
|
||||
|
|
Loading…
Reference in New Issue