Some functions commented

This commit is contained in:
Jordi Baylina 2017-07-04 16:13:24 -07:00
parent 75904fb3af
commit 849f9e5c96
No known key found for this signature in database
GPG Key ID: 7480C80C1BE43112
3 changed files with 97 additions and 4 deletions

View File

@ -5,6 +5,8 @@ import "./LiquidPledgingBase.sol";
contract LiquidPledging is LiquidPledgingBase { contract LiquidPledging is LiquidPledgingBase {
uint constant MAX_DELEGATES = 20;
uint constant MAX_SUBPROJECT_LEVEL = 20;
////// //////
// Constructor // Constructor
////// //////
@ -12,6 +14,12 @@ contract LiquidPledging is LiquidPledgingBase {
function LiquidPledging(address _vault) LiquidPledgingBase(_vault) { function LiquidPledging(address _vault) LiquidPledgingBase(_vault) {
} }
/// @notice This is the main entry of Ether to the system. Ethether goes to
/// the vault and then the Note for the donor withou delegates is increased.
/// After that, a normal transfer is done to the idReceiver.
/// @param idDonor Id of the donor thats donating.
/// @param idReceiver To who it's transfered. Can ve the same donnor, another
/// donor, a delegate or a project
function donate(uint64 idDonor, uint64 idReceiver) payable { function donate(uint64 idDonor, uint64 idReceiver) payable {
NoteManager sender = findManager(idDonor); NoteManager sender = findManager(idDonor);
@ -40,6 +48,14 @@ contract LiquidPledging is LiquidPledgingBase {
transfer(idDonor, idNote, amount, idReceiver); transfer(idDonor, idNote, amount, idReceiver);
} }
/// @notice This is the main function to move Ether from one Note to the other
/// @param idSender Id of the donor, delegate or project manager that is transferin
/// the funds from Note to note. This manager must have permisions to move the Ether
/// @param idNote Id of the note that's moving the Ether.
/// @param amount Quantity of Ether that's moving.
/// @param idReceiver Destination of the Ether, can be a donor to move Ether between donors,
/// A delegate to delegate that Ether, or a project to commit or precommit it to that project.
function transfer(uint64 idSender, uint64 idNote, uint amount, uint64 idReceiver) { function transfer(uint64 idSender, uint64 idNote, uint amount, uint64 idReceiver) {
idNote = normalizeNote(idNote); idNote = normalizeNote(idNote);
@ -53,9 +69,10 @@ contract LiquidPledging is LiquidPledgingBase {
// If the sender is the owner // If the sender is the owner
if (n.owner == idSender) { if (n.owner == idSender) {
if ((receiver.managerType == NoteManagerType.Donor) || if (receiver.managerType == NoteManagerType.Donor) {
(receiver.managerType == NoteManagerType.Project)) { transferOwnershipToDonor(idNote, amount, idReceiver);
transferOwnership(idNote, amount, idReceiver); } else if (receiver.managerType == NoteManagerType.Project) {
transferOwnershipToProject(idNote, amount, idReceiver);
} else if (receiver.managerType == NoteManagerType.Delegate) { } else if (receiver.managerType == NoteManagerType.Delegate) {
appendDelegate(idNote, amount, idReceiver); appendDelegate(idNote, amount, idReceiver);
} else { } else {
@ -108,6 +125,12 @@ contract LiquidPledging is LiquidPledgingBase {
throw; // It is not the owner nor any delegate. throw; // It is not the owner nor any delegate.
} }
/// @notice This method is used to withdraw Ether from the system. This can be used
/// from the doonurs to rollback a not commited 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.
function withdraw(uint64 idNote, uint amount) { function withdraw(uint64 idNote, uint amount) {
idNote = normalizeNote(idNote); idNote = normalizeNote(idNote);
@ -134,6 +157,9 @@ contract LiquidPledging is LiquidPledgingBase {
vault.authorizePayment(bytes32(idNewNote), owner.addr, amount); vault.authorizePayment(bytes32(idNewNote), owner.addr, amount);
} }
/// @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.
function confirmPayment(uint64 idNote, uint amount) onlyVault { function confirmPayment(uint64 idNote, uint amount) onlyVault {
Note n = findNote(idNote); Note n = findNote(idNote);
@ -154,6 +180,9 @@ contract LiquidPledging is LiquidPledgingBase {
doTransfer(idNote, idNewNote, amount); doTransfer(idNote, idNewNote, amount);
} }
/// @notice Method called by the vault to cancel a payment.
/// @param idNote Id of the note that wants to be canceled for withdraw.
/// @param amount Quantity of Ether that wants to be rolled back.
function cancelPayment(uint64 idNote, uint amount) onlyVault { function cancelPayment(uint64 idNote, uint amount) onlyVault {
Note n = findNote(idNote); Note n = findNote(idNote);
@ -174,6 +203,8 @@ contract LiquidPledging is LiquidPledgingBase {
doTransfer(idNote, oldNote, amount); doTransfer(idNote, oldNote, amount);
} }
/// @notice Method called by the reviewer of a project to cancel this project.
/// @param idProject Id of the projct that wants to be canceled.
function cancelProject(uint64 idProject) { function cancelProject(uint64 idProject) {
NoteManager project = findManager(idProject); NoteManager project = findManager(idProject);
require((project.reviewer == msg.sender) || (project.addr == msg.sender)); require((project.reviewer == msg.sender) || (project.addr == msg.sender));
@ -226,8 +257,10 @@ contract LiquidPledging is LiquidPledgingBase {
/////// ///////
function transferOwnership(uint64 idNote, uint amount, uint64 idReceiver) internal { function transferOwnershipToProject(uint64 idNote, uint amount, uint64 idReceiver) internal {
Note n = findNote(idNote); Note n = findNote(idNote);
if (getProjectLevel(n) >= MAX_SUBPROJECT_LEVEL) throw;
uint64 oldNote = findNote( uint64 oldNote = findNote(
n.owner, n.owner,
n.delegationChain, n.delegationChain,
@ -248,8 +281,25 @@ contract LiquidPledging is LiquidPledgingBase {
doTransfer(idNote, toNote, amount); doTransfer(idNote, toNote, amount);
} }
function transferOwnershipToDonor(uint64 idNote, uint amount, uint64 idReceiver) internal {
// If the owner does not change, then just let it this way.
Note n = findNote(idNote);
if (n.owner == idReceiver) return;
uint64 toNote = findNote(
idReceiver,
new uint64[](0),
0,
0,
0,
PaymentState.NotPaid);
doTransfer(idNote, toNote, amount);
}
function appendDelegate(uint64 idNote, uint amount, uint64 idReceiver) internal { function appendDelegate(uint64 idNote, uint amount, uint64 idReceiver) internal {
Note n = findNote(idNote); Note n = findNote(idNote);
if (n.delegationChain.length >= MAX_DELEGATES) throw;
uint64[] memory newDelegationChain = new uint64[](n.delegationChain.length + 1); uint64[] memory newDelegationChain = new uint64[](n.delegationChain.length + 1);
for (uint i=0; i<n.delegationChain.length; i++) { for (uint i=0; i<n.delegationChain.length; i++) {
newDelegationChain[i] = n.delegationChain[i]; newDelegationChain[i] = n.delegationChain[i];
@ -285,6 +335,9 @@ contract LiquidPledging is LiquidPledgingBase {
function proposeAssignProject(uint64 idNote, uint amount, uint64 idReceiver) internal { function proposeAssignProject(uint64 idNote, uint amount, uint64 idReceiver) internal {
Note n = findNote(idNote); Note n = findNote(idNote);
if (getProjectLevel(n) >= MAX_SUBPROJECT_LEVEL) throw;
NoteManager owner = findManager(n.owner); NoteManager owner = findManager(n.owner);
uint64 toNote = findNote( uint64 toNote = findNote(
n.owner, n.owner,

View File

@ -268,4 +268,10 @@ contract LiquidPledgingBase {
return NOTFOUND; return NOTFOUND;
} }
function getProjectLevel(Note n) internal returns(uint) {
if (n.oldNote == 0) return 1;
Note oldN = findNote(n.oldNote);
return getProjectLevel(oldN) + 1;
}
} }

34
js/liquidPladging.js Normal file
View File

@ -0,0 +1,34 @@
const LiquidPledgingAbi = require("../build/contracts/LiquidPledging.json").abi;
module.exports = class LiquidPledging {
constructor(web3, address) {
this.notes = [];
this.managers = [];
}
getDonorInfo(idDonor) {
const st = {};
return st;
}
}
/*
managers = []
donors = [
"donor"/idDonor(d1,d2)/"NotAssigned"/idDelegate1/idDelegate2
/"PreAssigned"/idProject1
/"Assigned"/idProject1/idProject2
/"Spended"/idProject1/idProject2
donor(d1,d2)/project1(d3,d4)/idProject2(d5, d6)/["Paying,Paid"]
["Preassigned: IDTIME"]
/"Assigned"/donor(d1,d2)/project1(d3,d4)
/"Spent"/idProject1/idProject2/idProject(da,db)
]
console.log(JSON.stringify(LiquidPledgingAbi));
*/