Merge branch 'master' into veto_delegation
This commit is contained in:
commit
2076a91859
|
@ -2,7 +2,8 @@ pragma solidity ^0.4.11;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright 2017, Jordi Baylina
|
Copyright 2017, Jordi Baylina
|
||||||
Contributor: Adrià Massanet <adria@codecontext.io>
|
Contributors: Adrià Massanet <adria@codecontext.io>, RJ Ewing, Griff
|
||||||
|
Green, Arthur Lunn
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
|
|
@ -12,8 +12,8 @@ import "./Owned.sol";
|
||||||
/// @dev `LiquidPledging` is a basic interface to allow the `LPVault` contract
|
/// @dev `LiquidPledging` is a basic interface to allow the `LPVault` contract
|
||||||
/// to confirm and cancel payments in the `LiquidPledging` contract.
|
/// to confirm and cancel payments in the `LiquidPledging` contract.
|
||||||
contract LiquidPledging {
|
contract LiquidPledging {
|
||||||
function confirmPayment(uint64 idNote, uint amount) public;
|
function confirmPayment(uint64 idPledge, uint amount) public;
|
||||||
function cancelPayment(uint64 idNote, uint amount) public;
|
function cancelPayment(uint64 idPledge, uint amount) public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
PaymentState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,43 +103,47 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
|
|
||||||
idPledge = normalizePledge(idPledge);
|
idPledge = normalizePledge(idPledge);
|
||||||
|
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
PledgeAdmin storage receiver = findAdmin(idReceiver);
|
PledgeAdmin storage receiver = findAdmin(idReceiver);
|
||||||
PledgeAdmin storage sender = findAdmin(idSender);
|
PledgeAdmin storage sender = findAdmin(idSender);
|
||||||
|
|
||||||
checkAdminOwner(sender);
|
checkAdminOwner(sender);
|
||||||
require(n.paymentState == PaymentState.Pledged);
|
require(p.pledgeState == PledgeState.Pledged);
|
||||||
|
|
||||||
// If the sender is the owner
|
// If the sender is the owner
|
||||||
if (n.owner == idSender) {
|
if (p.owner == idSender) {
|
||||||
if (receiver.adminType == PledgeAdminType.Giver) {
|
if (receiver.adminType == PledgeAdminType.Giver) {
|
||||||
transferOwnershipToGiver(idPledge, amount, idReceiver);
|
transferOwnershipToGiver(idPledge, amount, idReceiver);
|
||||||
} else if (receiver.adminType == PledgeAdminType.Project) {
|
} else if (receiver.adminType == PledgeAdminType.Project) {
|
||||||
transferOwnershipToProject(idPledge, amount, idReceiver);
|
transferOwnershipToProject(idPledge, amount, idReceiver);
|
||||||
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
} else if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||||
|
|
||||||
uint recieverDIdx = getDelegateIdx(n, idReceiver);
|
uint recieverDIdx = getDelegateIdx(p, idReceiver);
|
||||||
if (n.intendedProject > 0 && recieverDIdx != NOTFOUND) {
|
if (p.intendedProject > 0 && recieverDIdx != NOTFOUND) {
|
||||||
// if there is an intendedProject and the receiver is in the delegationChain,
|
// if there is an intendedProject and the receiver is in the delegationChain,
|
||||||
// then we want to preserve the delegationChain as this is a veto of the
|
// then we want to preserve the delegationChain as this is a veto of the
|
||||||
// intendedProject by the owner
|
// intendedProject by the owner
|
||||||
|
|
||||||
if (recieverDIdx == n.delegationChain.length - 1) {
|
if (recieverDIdx == p.delegationChain.length - 1) {
|
||||||
uint64 toPledge = findOrCreatePledge(
|
uint64 toPledge = findOrCreatePledge(
|
||||||
n.owner,
|
p.owner,
|
||||||
n.delegationChain,
|
p.delegationChain,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
n.oldPledge,
|
p.oldPledge,
|
||||||
PaymentState.Pledged);
|
PledgeState.Pledged);
|
||||||
doTransfer(idPledge, toPledge, amount);
|
doTransfer(idPledge, toPledge, amount);
|
||||||
} else {
|
} else {
|
||||||
undelegate(idPledge, amount, n.delegationChain.length - receiverDIdx - 1);
|
undelegate(idPledge, amount, p.delegationChain.length - receiverDIdx - 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// owner is not vetoing an intendedProject and is transferring the pledge to a delegate,
|
// owner is not vetoing an intendedProject and is transferring the pledge to a delegate,
|
||||||
// so we want to reset the delegationChain
|
// so we want to reset the delegationChain
|
||||||
idPledge = undelegate(idPledge, amount, n.delegationChain.length);
|
idPledge = undelegate(
|
||||||
|
idPledge,
|
||||||
|
amount,
|
||||||
|
p.delegationChain.length
|
||||||
|
);
|
||||||
appendDelegate(idPledge, amount, idReceiver);
|
appendDelegate(idPledge, amount, idReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,28 +154,28 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the sender is a delegate
|
// If the sender is a delegate
|
||||||
uint senderDIdx = getDelegateIdx(n, idSender);
|
uint senderDIdx = getDelegateIdx(p, idSender);
|
||||||
if (senderDIdx != NOTFOUND) {
|
if (senderDIdx != NOTFOUND) {
|
||||||
|
|
||||||
// If the receiver is another giver
|
// If the receiver is another giver
|
||||||
if (receiver.adminType == PledgeAdminType.Giver) {
|
if (receiver.adminType == PledgeAdminType.Giver) {
|
||||||
// Only accept to change to the original giver to
|
// Only accept to change to the original giver to
|
||||||
// remove all delegates
|
// remove all delegates
|
||||||
assert(n.owner == idReceiver);
|
assert(p.owner == idReceiver);
|
||||||
undelegate(idPledge, amount, n.delegationChain.length);
|
undelegate(idPledge, amount, p.delegationChain.length);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the receiver is another delegate
|
// If the receiver is another delegate
|
||||||
if (receiver.adminType == PledgeAdminType.Delegate) {
|
if (receiver.adminType == PledgeAdminType.Delegate) {
|
||||||
uint receiverDIdx = getDelegateIdx(n, idReceiver);
|
uint receiverDIdx = getDelegateIdx(p, idReceiver);
|
||||||
|
|
||||||
// If the receiver is not in the delegate list
|
// If the receiver is not in the delegate list
|
||||||
if (receiverDIdx == NOTFOUND) {
|
if (receiverDIdx == NOTFOUND) {
|
||||||
idPledge = undelegate(
|
idPledge = undelegate(
|
||||||
idPledge,
|
idPledge,
|
||||||
amount,
|
amount,
|
||||||
n.delegationChain.length - senderDIdx - 1
|
p.delegationChain.length - senderDIdx - 1
|
||||||
);
|
);
|
||||||
appendDelegate(idPledge, amount, idReceiver);
|
appendDelegate(idPledge, amount, idReceiver);
|
||||||
|
|
||||||
|
@ -183,7 +187,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
idPledge = undelegate(
|
idPledge = undelegate(
|
||||||
idPledge,
|
idPledge,
|
||||||
amount,
|
amount,
|
||||||
n.delegationChain.length - senderDIdx - 1
|
p.delegationChain.length - senderDIdx - 1
|
||||||
);
|
);
|
||||||
appendDelegate(idPledge, amount, idReceiver);
|
appendDelegate(idPledge, amount, idReceiver);
|
||||||
|
|
||||||
|
@ -197,7 +201,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
undelegate(
|
undelegate(
|
||||||
idPledge,
|
idPledge,
|
||||||
amount,
|
amount,
|
||||||
n.delegationChain.length - receiverDIdx - 1
|
p.delegationChain.length - receiverDIdx - 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -209,7 +213,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
idPledge = undelegate(
|
idPledge = undelegate(
|
||||||
idPledge,
|
idPledge,
|
||||||
amount,
|
amount,
|
||||||
n.delegationChain.length - senderDIdx - 1
|
p.delegationChain.length - senderDIdx - 1
|
||||||
);
|
);
|
||||||
proposeAssignProject(idPledge, amount, idReceiver);
|
proposeAssignProject(idPledge, amount, idReceiver);
|
||||||
return;
|
return;
|
||||||
|
@ -226,21 +230,21 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
|
|
||||||
idPledge = normalizePledge(idPledge);
|
idPledge = normalizePledge(idPledge);
|
||||||
|
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
|
|
||||||
require(n.paymentState == PaymentState.Pledged);
|
require(p.pledgeState == PledgeState.Pledged);
|
||||||
|
|
||||||
PledgeAdmin storage owner = findAdmin(n.owner);
|
PledgeAdmin storage owner = findAdmin(p.owner);
|
||||||
|
|
||||||
checkAdminOwner(owner);
|
checkAdminOwner(owner);
|
||||||
|
|
||||||
uint64 idNewPledge = findOrCreatePledge(
|
uint64 idNewPledge = findOrCreatePledge(
|
||||||
n.owner,
|
p.owner,
|
||||||
n.delegationChain,
|
p.delegationChain,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
n.oldPledge,
|
p.oldPledge,
|
||||||
PaymentState.Paying
|
PledgeState.Paying
|
||||||
);
|
);
|
||||||
|
|
||||||
doTransfer(idPledge, idNewPledge, amount);
|
doTransfer(idPledge, idNewPledge, amount);
|
||||||
|
@ -252,17 +256,17 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
/// @param idPledge Id of the pledge that wants to be withdrawn.
|
/// @param idPledge Id of the pledge that wants to be withdrawn.
|
||||||
/// @param amount Quantity of Ether that wants to be withdrawn.
|
/// @param amount Quantity of Ether that wants to be withdrawn.
|
||||||
function confirmPayment(uint64 idPledge, uint amount) onlyVault {
|
function confirmPayment(uint64 idPledge, uint amount) onlyVault {
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
|
|
||||||
require(n.paymentState == PaymentState.Paying);
|
require(p.pledgeState == PledgeState.Paying);
|
||||||
|
|
||||||
uint64 idNewPledge = findOrCreatePledge(
|
uint64 idNewPledge = findOrCreatePledge(
|
||||||
n.owner,
|
p.owner,
|
||||||
n.delegationChain,
|
p.delegationChain,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
n.oldPledge,
|
p.oldPledge,
|
||||||
PaymentState.Paid
|
PledgeState.Paid
|
||||||
);
|
);
|
||||||
|
|
||||||
doTransfer(idPledge, idNewPledge, amount);
|
doTransfer(idPledge, idNewPledge, amount);
|
||||||
|
@ -272,18 +276,18 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
/// @param idPledge Id of the pledge that wants to be canceled for withdraw.
|
/// @param idPledge Id of the pledge that wants to be canceled for withdraw.
|
||||||
/// @param amount Quantity of Ether that wants to be rolled back.
|
/// @param amount Quantity of Ether that wants to be rolled back.
|
||||||
function cancelPayment(uint64 idPledge, uint amount) onlyVault {
|
function cancelPayment(uint64 idPledge, uint amount) onlyVault {
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
|
|
||||||
require(n.paymentState == PaymentState.Paying); //TODO change to revert
|
require(p.pledgeState == PledgeState.Paying); //TODO change to revert
|
||||||
|
|
||||||
// When a payment is canceled, never is assigned to a project.
|
// When a payment is canceled, never is assigned to a project.
|
||||||
uint64 oldPledge = findOrCreatePledge(
|
uint64 oldPledge = findOrCreatePledge(
|
||||||
n.owner,
|
p.owner,
|
||||||
n.delegationChain,
|
p.delegationChain,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
n.oldPledge,
|
p.oldPledge,
|
||||||
PaymentState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
|
|
||||||
oldPledge = normalizePledge(oldPledge);
|
oldPledge = normalizePledge(oldPledge);
|
||||||
|
@ -307,13 +311,13 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
function cancelPledge(uint64 idPledge, uint amount) {
|
function cancelPledge(uint64 idPledge, uint amount) {
|
||||||
idPledge = normalizePledge(idPledge);
|
idPledge = normalizePledge(idPledge);
|
||||||
|
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
require(n.oldPledge != 0);
|
require(p.oldPledge != 0);
|
||||||
|
|
||||||
PledgeAdmin storage m = findAdmin(n.owner);
|
PledgeAdmin storage m = findAdmin(p.owner);
|
||||||
checkAdminOwner(m);
|
checkAdminOwner(m);
|
||||||
|
|
||||||
uint64 oldPledge = getOldestPledgeNotCanceled(n.oldPledge);
|
uint64 oldPledge = getOldestPledgeNotCanceled(p.oldPledge);
|
||||||
doTransfer(idPledge, oldPledge, amount);
|
doTransfer(idPledge, oldPledge, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,20 +419,20 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
uint amount,
|
uint amount,
|
||||||
uint64 idReceiver
|
uint64 idReceiver
|
||||||
) internal {
|
) internal {
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
|
|
||||||
// Ensure that the pledge is not already at max pledge depth
|
// Ensure that the pledge is not already at max pledge depth
|
||||||
// and the project has not been canceled
|
// and the project has not been canceled
|
||||||
require(getPledgeLevel(n) < MAX_INTERPROJECT_LEVEL);
|
require(getPledgeLevel(p) < MAX_INTERPROJECT_LEVEL);
|
||||||
require(!isProjectCanceled(idReceiver));
|
require(!isProjectCanceled(idReceiver));
|
||||||
|
|
||||||
uint64 oldPledge = findOrCreatePledge(
|
uint64 oldPledge = findOrCreatePledge(
|
||||||
n.owner,
|
p.owner,
|
||||||
n.delegationChain,
|
p.delegationChain,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
n.oldPledge,
|
p.oldPledge,
|
||||||
PaymentState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
uint64 toPledge = findOrCreatePledge(
|
uint64 toPledge = findOrCreatePledge(
|
||||||
idReceiver, // Set the new owner
|
idReceiver, // Set the new owner
|
||||||
|
@ -436,7 +440,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
oldPledge,
|
oldPledge,
|
||||||
PaymentState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
doTransfer(idPledge, toPledge, amount);
|
doTransfer(idPledge, toPledge, amount);
|
||||||
}
|
}
|
||||||
|
@ -459,7 +463,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
PaymentState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
doTransfer(idPledge, toPledge, amount);
|
doTransfer(idPledge, toPledge, amount);
|
||||||
}
|
}
|
||||||
|
@ -474,26 +478,26 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
uint amount,
|
uint amount,
|
||||||
uint64 idReceiver
|
uint64 idReceiver
|
||||||
) internal {
|
) internal {
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
|
|
||||||
require(n.delegationChain.length < MAX_DELEGATES);
|
require(p.delegationChain.length < MAX_DELEGATES);
|
||||||
uint64[] memory newDelegationChain = new uint64[](
|
uint64[] memory newDelegationChain = new uint64[](
|
||||||
n.delegationChain.length + 1
|
p.delegationChain.length + 1
|
||||||
);
|
);
|
||||||
for (uint i = 0; i<n.delegationChain.length; i++) {
|
for (uint i = 0; i<p.delegationChain.length; i++) {
|
||||||
newDelegationChain[i] = n.delegationChain[i];
|
newDelegationChain[i] = p.delegationChain[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the last item in the array the idReceiver
|
// Make the last item in the array the idReceiver
|
||||||
newDelegationChain[n.delegationChain.length] = idReceiver;
|
newDelegationChain[p.delegationChain.length] = idReceiver;
|
||||||
|
|
||||||
uint64 toPledge = findOrCreatePledge(
|
uint64 toPledge = findOrCreatePledge(
|
||||||
n.owner,
|
p.owner,
|
||||||
newDelegationChain,
|
newDelegationChain,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
n.oldPledge,
|
p.oldPledge,
|
||||||
PaymentState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
doTransfer(idPledge, toPledge, amount);
|
doTransfer(idPledge, toPledge, amount);
|
||||||
}
|
}
|
||||||
|
@ -508,20 +512,20 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
uint amount,
|
uint amount,
|
||||||
uint q
|
uint q
|
||||||
) internal returns (uint64){
|
) internal returns (uint64){
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
uint64[] memory newDelegationChain = new uint64[](
|
uint64[] memory newDelegationChain = new uint64[](
|
||||||
n.delegationChain.length - q
|
p.delegationChain.length - q
|
||||||
);
|
);
|
||||||
for (uint i=0; i<n.delegationChain.length - q; i++) {
|
for (uint i=0; i<p.delegationChain.length - q; i++) {
|
||||||
newDelegationChain[i] = n.delegationChain[i];
|
newDelegationChain[i] = p.delegationChain[i];
|
||||||
}
|
}
|
||||||
uint64 toPledge = findOrCreatePledge(
|
uint64 toPledge = findOrCreatePledge(
|
||||||
n.owner,
|
p.owner,
|
||||||
newDelegationChain,
|
newDelegationChain,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
n.oldPledge,
|
p.oldPledge,
|
||||||
PaymentState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
doTransfer(idPledge, toPledge, amount);
|
doTransfer(idPledge, toPledge, amount);
|
||||||
|
|
||||||
|
@ -540,18 +544,18 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
uint amount,
|
uint amount,
|
||||||
uint64 idReceiver
|
uint64 idReceiver
|
||||||
) internal {
|
) internal {
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
|
|
||||||
require(getPledgeLevel(n) < MAX_SUBPROJECT_LEVEL);
|
require(getPledgeLevel(p) < MAX_SUBPROJECT_LEVEL);
|
||||||
require(!isProjectCanceled(idReceiver));
|
require(!isProjectCanceled(idReceiver));
|
||||||
|
|
||||||
uint64 toPledge = findOrCreatePledge(
|
uint64 toPledge = findOrCreatePledge(
|
||||||
n.owner,
|
p.owner,
|
||||||
n.delegationChain,
|
p.delegationChain,
|
||||||
idReceiver,
|
idReceiver,
|
||||||
uint64(getTime() + maxCommitTime(n)),
|
uint64(getTime() + maxCommitTime(p)),
|
||||||
n.oldPledge,
|
p.oldPledge,
|
||||||
PaymentState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
doTransfer(idPledge, toPledge, amount);
|
doTransfer(idPledge, toPledge, amount);
|
||||||
}
|
}
|
||||||
|
@ -579,7 +583,7 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
callPlugins(false, from, to, amount);
|
callPlugins(false, from, to, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice `normalizePledge` only affects pledges with the Pledged PaymentState
|
/// @notice `normalizePledge` only affects pledges with the Pledged PledgeState
|
||||||
/// and does 2 things:
|
/// and does 2 things:
|
||||||
/// #1: Checks if the pledge should be committed. This means that
|
/// #1: Checks if the pledge should be committed. This means that
|
||||||
/// if the pledge has an intendedProject and it is past the
|
/// if the pledge has an intendedProject and it is past the
|
||||||
|
@ -598,40 +602,40 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
/// @param idPledge This is the id of the pledge that will be normalized
|
/// @param idPledge This is the id of the pledge that will be normalized
|
||||||
function normalizePledge(uint64 idPledge) returns(uint64) {
|
function normalizePledge(uint64 idPledge) returns(uint64) {
|
||||||
|
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
|
|
||||||
// Check to make sure this pledge hasn't already been used
|
// Check to make sure this pledge hasn't already been used
|
||||||
// or is in the process of being used
|
// or is in the process of being used
|
||||||
if (n.paymentState != PaymentState.Pledged) {
|
if (p.pledgeState != PledgeState.Pledged) {
|
||||||
return idPledge;
|
return idPledge;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First send to a project if it's proposed and committed
|
// First send to a project if it's proposed and committed
|
||||||
if ((n.intendedProject > 0) && ( getTime() > n.commitTime)) {
|
if ((p.intendedProject > 0) && ( getTime() > p.commitTime)) {
|
||||||
uint64 oldPledge = findOrCreatePledge(
|
uint64 oldPledge = findOrCreatePledge(
|
||||||
n.owner,
|
p.owner,
|
||||||
n.delegationChain,
|
p.delegationChain,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
n.oldPledge,
|
p.oldPledge,
|
||||||
PaymentState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
uint64 toPledge = findOrCreatePledge(
|
uint64 toPledge = findOrCreatePledge(
|
||||||
n.intendedProject,
|
p.intendedProject,
|
||||||
new uint64[](0),
|
new uint64[](0),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
oldPledge,
|
oldPledge,
|
||||||
PaymentState.Pledged
|
PledgeState.Pledged
|
||||||
);
|
);
|
||||||
doTransfer(idPledge, toPledge, n.amount);
|
doTransfer(idPledge, toPledge, p.amount);
|
||||||
idPledge = toPledge;
|
idPledge = toPledge;
|
||||||
n = findPledge(idPledge);
|
p = findPledge(idPledge);
|
||||||
}
|
}
|
||||||
|
|
||||||
toPledge = getOldestPledgeNotCanceled(idPledge);// TODO toPledge is pledge defined
|
toPledge = getOldestPledgeNotCanceled(idPledge);// TODO toPledge is pledge defined
|
||||||
if (toPledge != idPledge) {
|
if (toPledge != idPledge) {
|
||||||
doTransfer(idPledge, toPledge, n.amount);
|
doTransfer(idPledge, toPledge, p.amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
return toPledge;
|
return toPledge;
|
||||||
|
@ -715,12 +719,12 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
// or transferring context
|
// or transferring context
|
||||||
uint64 offset = idPledge == fromPledge ? 0 : 256;
|
uint64 offset = idPledge == fromPledge ? 0 : 256;
|
||||||
allowedAmount = amount;
|
allowedAmount = amount;
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
|
|
||||||
// Always call the plugin on the owner
|
// Always call the plugin on the owner
|
||||||
allowedAmount = callPlugin(
|
allowedAmount = callPlugin(
|
||||||
before,
|
before,
|
||||||
n.owner,
|
p.owner,
|
||||||
fromPledge,
|
fromPledge,
|
||||||
toPledge,
|
toPledge,
|
||||||
offset,
|
offset,
|
||||||
|
@ -728,10 +732,10 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Apply call plugin to all delegates
|
// Apply call plugin to all delegates
|
||||||
for (uint64 i=0; i<n.delegationChain.length; i++) {
|
for (uint64 i=0; i<p.delegationChain.length; i++) {
|
||||||
allowedAmount = callPlugin(
|
allowedAmount = callPlugin(
|
||||||
before,
|
before,
|
||||||
n.delegationChain[i],
|
p.delegationChain[i],
|
||||||
fromPledge,
|
fromPledge,
|
||||||
toPledge,
|
toPledge,
|
||||||
offset + i+1,
|
offset + i+1,
|
||||||
|
@ -742,10 +746,10 @@ contract LiquidPledging is LiquidPledgingBase {
|
||||||
// If there is an intended project also call the plugin in
|
// If there is an intended project also call the plugin in
|
||||||
// either a transferring or receiving context based on offset
|
// either a transferring or receiving context based on offset
|
||||||
// on the intended project
|
// on the intended project
|
||||||
if (n.intendedProject > 0) {
|
if (p.intendedProject > 0) {
|
||||||
allowedAmount = callPlugin(
|
allowedAmount = callPlugin(
|
||||||
before,
|
before,
|
||||||
n.intendedProject,
|
p.intendedProject,
|
||||||
fromPledge,
|
fromPledge,
|
||||||
toPledge,
|
toPledge,
|
||||||
offset + 255,
|
offset + 255,
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
pragma solidity ^0.4.11;
|
pragma solidity ^0.4.11;
|
||||||
/*
|
/*
|
||||||
Copyright 2017, Jordi Baylina
|
Copyright 2017, Jordi Baylina
|
||||||
Contributor: Adrià Massanet <adria@codecontext.io>
|
Contributors: Adrià Massanet <adria@codecontext.io>, RJ Ewing, Griff
|
||||||
|
Green, Arthur Lunn
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -20,15 +21,16 @@ pragma solidity ^0.4.11;
|
||||||
import "./ILiquidPledgingPlugin.sol";
|
import "./ILiquidPledgingPlugin.sol";
|
||||||
import "../node_modules/giveth-common-contracts/contracts/Owned.sol";
|
import "../node_modules/giveth-common-contracts/contracts/Owned.sol";
|
||||||
|
|
||||||
/// @dev `LPVault` serves as an interface to allow the `LiquidPledgingBase`
|
/// @dev This is an interface for `LPVault` which serves as a secure storage for
|
||||||
/// contract to interface with a `LPVault` contract
|
/// the ETH that backs the Pledges, only after `LiquidPledging` authorizes
|
||||||
contract LPVault {
|
/// payments can Pledges be converted for ETH
|
||||||
|
interface LPVault {
|
||||||
function authorizePayment(bytes32 _ref, address _dest, uint _amount);
|
function authorizePayment(bytes32 _ref, address _dest, uint _amount);
|
||||||
function () payable;
|
function () payable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @dev `LiquidPledgingBase` is the base level contract used to carry out
|
/// @dev `LiquidPledgingBase` is the base level contract used to carry out
|
||||||
/// liquid pledging's most basic functions, mostly handling and searching the
|
/// liquidPledging's most basic functions, mostly handling and searching the
|
||||||
/// data structures
|
/// data structures
|
||||||
contract LiquidPledgingBase is Owned {
|
contract LiquidPledgingBase is Owned {
|
||||||
|
|
||||||
|
@ -38,10 +40,10 @@ contract LiquidPledgingBase is Owned {
|
||||||
uint constant MAX_INTERPROJECT_LEVEL = 20;
|
uint constant MAX_INTERPROJECT_LEVEL = 20;
|
||||||
|
|
||||||
enum PledgeAdminType { Giver, Delegate, Project }
|
enum PledgeAdminType { Giver, Delegate, Project }
|
||||||
enum PaymentState { Pledged, Paying, Paid }
|
enum PledgeState { Pledged, Paying, Paid }
|
||||||
|
|
||||||
/// @dev This struct defines the details of a `PledgeAdmin` which are
|
/// @dev This struct defines the details of a `PledgeAdmin` which are
|
||||||
/// commonly referenced by their index in the `admins` array.
|
/// commonly referenced by their index in the `admins` array
|
||||||
/// and can own pledges and act as delegates
|
/// and can own pledges and act as delegates
|
||||||
struct PledgeAdmin {
|
struct PledgeAdmin {
|
||||||
PledgeAdminType adminType; // Giver, Delegate or Project
|
PledgeAdminType adminType; // Giver, Delegate or Project
|
||||||
|
@ -64,7 +66,7 @@ contract LiquidPledgingBase is Owned {
|
||||||
uint64 intendedProject; // Used when delegates are sending to projects
|
uint64 intendedProject; // Used when delegates are sending to projects
|
||||||
uint64 commitTime; // When the intendedProject will become the owner
|
uint64 commitTime; // When the intendedProject will become the owner
|
||||||
uint64 oldPledge; // Points to the id that this Pledge was derived from
|
uint64 oldPledge; // Points to the id that this Pledge was derived from
|
||||||
PaymentState paymentState; // Pledged, Paying, Paid
|
PledgeState pledgeState; // Pledged, Paying, Paid
|
||||||
}
|
}
|
||||||
|
|
||||||
Pledge[] pledges;
|
Pledge[] pledges;
|
||||||
|
@ -334,16 +336,16 @@ contract LiquidPledgingBase is Owned {
|
||||||
uint64 intendedProject,
|
uint64 intendedProject,
|
||||||
uint64 commitTime,
|
uint64 commitTime,
|
||||||
uint64 oldPledge,
|
uint64 oldPledge,
|
||||||
PaymentState paymentState
|
PledgeState pledgeState
|
||||||
) {
|
) {
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
amount = n.amount;
|
amount = p.amount;
|
||||||
owner = n.owner;
|
owner = p.owner;
|
||||||
nDelegates = uint64(n.delegationChain.length);
|
nDelegates = uint64(p.delegationChain.length);
|
||||||
intendedProject = n.intendedProject;
|
intendedProject = p.intendedProject;
|
||||||
commitTime = n.commitTime;
|
commitTime = p.commitTime;
|
||||||
oldPledge = n.oldPledge;
|
oldPledge = p.oldPledge;
|
||||||
paymentState = n.paymentState;
|
pledgeState = p.pledgeState;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice Getter to find Delegate w/ the Pledge ID & the Delegate index
|
/// @notice Getter to find Delegate w/ the Pledge ID & the Delegate index
|
||||||
|
@ -354,8 +356,8 @@ contract LiquidPledgingBase is Owned {
|
||||||
address addr,
|
address addr,
|
||||||
string name
|
string name
|
||||||
) {
|
) {
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
idDelegate = n.delegationChain[idxDelegate - 1];
|
idDelegate = p.delegationChain[idxDelegate - 1];
|
||||||
PledgeAdmin storage delegate = findAdmin(idDelegate);
|
PledgeAdmin storage delegate = findAdmin(idDelegate);
|
||||||
addr = delegate.addr;
|
addr = delegate.addr;
|
||||||
name = delegate.name;
|
name = delegate.name;
|
||||||
|
@ -419,7 +421,7 @@ contract LiquidPledgingBase is Owned {
|
||||||
/// @param oldPledge This value is used to store the pledge the current
|
/// @param oldPledge This value is used to store the pledge the current
|
||||||
/// pledge was came from, and in the case a Project is canceled, the Pledge
|
/// pledge was came from, and in the case a Project is canceled, the Pledge
|
||||||
/// will revert back to it's previous state
|
/// will revert back to it's previous state
|
||||||
/// @param paid The payment state: Pledged, Paying, or Paid
|
/// @param state The pledge state: Pledged, Paying, or state
|
||||||
/// @return The hPledge2idx index number
|
/// @return The hPledge2idx index number
|
||||||
function findOrCreatePledge(
|
function findOrCreatePledge(
|
||||||
uint64 owner,
|
uint64 owner,
|
||||||
|
@ -427,17 +429,17 @@ contract LiquidPledgingBase is Owned {
|
||||||
uint64 intendedProject,
|
uint64 intendedProject,
|
||||||
uint64 commitTime,
|
uint64 commitTime,
|
||||||
uint64 oldPledge,
|
uint64 oldPledge,
|
||||||
PaymentState paid
|
PledgeState state
|
||||||
) internal returns (uint64)
|
) internal returns (uint64)
|
||||||
{
|
{
|
||||||
bytes32 hPledge = sha3(
|
bytes32 hPledge = sha3(
|
||||||
owner, delegationChain, intendedProject, commitTime, oldPledge, paid);
|
owner, delegationChain, intendedProject, commitTime, oldPledge, state);
|
||||||
uint64 idx = hPledge2idx[hPledge];
|
uint64 idx = hPledge2idx[hPledge];
|
||||||
if (idx > 0) return idx;
|
if (idx > 0) return idx;
|
||||||
idx = uint64(pledges.length);
|
idx = uint64(pledges.length);
|
||||||
hPledge2idx[hPledge] = idx;
|
hPledge2idx[hPledge] = idx;
|
||||||
pledges.push(Pledge(
|
pledges.push(Pledge(
|
||||||
0, owner, delegationChain, intendedProject, commitTime, oldPledge, paid));
|
0, owner, delegationChain, intendedProject, commitTime, oldPledge, state));
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -462,39 +464,39 @@ contract LiquidPledgingBase is Owned {
|
||||||
|
|
||||||
/// @notice A getter that searches the delegationChain for the level of
|
/// @notice A getter that searches the delegationChain for the level of
|
||||||
/// authority a specific delegate has within a Pledge
|
/// authority a specific delegate has within a Pledge
|
||||||
/// @param n The Pledge that will be searched
|
/// @param p The Pledge that will be searched
|
||||||
/// @param idDelegate The specified delegate that's searched for
|
/// @param idDelegate The specified delegate that's searched for
|
||||||
/// @return If the delegate chain contains the delegate with the
|
/// @return If the delegate chain contains the delegate with the
|
||||||
/// `admins` array index `idDelegate` this returns that delegates
|
/// `admins` array index `idDelegate` this returns that delegates
|
||||||
/// corresponding index in the delegationChain. Otherwise it returns
|
/// corresponding index in the delegationChain. Otherwise it returns
|
||||||
/// the NOTFOUND constant
|
/// the NOTFOUND constant
|
||||||
function getDelegateIdx(Pledge n, uint64 idDelegate) internal returns(uint64) {
|
function getDelegateIdx(Pledge p, uint64 idDelegate) internal returns(uint64) {
|
||||||
for (uint i=0; i < n.delegationChain.length; i++) {
|
for (uint i=0; i < p.delegationChain.length; i++) {
|
||||||
if (n.delegationChain[i] == idDelegate) return uint64(i);
|
if (p.delegationChain[i] == idDelegate) return uint64(i);
|
||||||
}
|
}
|
||||||
return NOTFOUND;
|
return NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice A getter to find how many old "parent" pledges a specific Pledge
|
/// @notice A getter to find how many old "parent" pledges a specific Pledge
|
||||||
/// had using a self-referential loop
|
/// had using a self-referential loop
|
||||||
/// @param n The Pledge being queried
|
/// @param p The Pledge being queried
|
||||||
/// @return The number of old "parent" pledges a specific Pledge had
|
/// @return The number of old "parent" pledges a specific Pledge had
|
||||||
function getPledgeLevel(Pledge n) internal returns(uint) {
|
function getPledgeLevel(Pledge p) internal returns(uint) {
|
||||||
if (n.oldPledge == 0) return 0;
|
if (p.oldPledge == 0) return 0;
|
||||||
Pledge storage oldN = findPledge(n.oldPledge);
|
Pledge storage oldN = findPledge(p.oldPledge);
|
||||||
return getPledgeLevel(oldN) + 1; // a loop lookup
|
return getPledgeLevel(oldN) + 1; // a loop lookup
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice A getter to find the longest commitTime out of the owner and all
|
/// @notice A getter to find the longest commitTime out of the owner and all
|
||||||
/// the delegates for a specified pledge
|
/// the delegates for a specified pledge
|
||||||
/// @param n The Pledge being queried
|
/// @param p The Pledge being queried
|
||||||
/// @return The maximum commitTime out of the owner and all the delegates
|
/// @return The maximum commitTime out of the owner and all the delegates
|
||||||
function maxCommitTime(Pledge n) internal returns(uint commitTime) {
|
function maxCommitTime(Pledge p) internal returns(uint commitTime) {
|
||||||
PledgeAdmin storage m = findAdmin(n.owner);
|
PledgeAdmin storage m = findAdmin(p.owner);
|
||||||
commitTime = m.commitTime; // start with the owner's commitTime
|
commitTime = m.commitTime; // start with the owner's commitTime
|
||||||
|
|
||||||
for (uint i=0; i<n.delegationChain.length; i++) {
|
for (uint i=0; i<p.delegationChain.length; i++) {
|
||||||
m = findAdmin(n.delegationChain[i]);
|
m = findAdmin(p.delegationChain[i]);
|
||||||
|
|
||||||
// If a delegate's commitTime is longer, make it the new commitTime
|
// If a delegate's commitTime is longer, make it the new commitTime
|
||||||
if (m.commitTime > commitTime) commitTime = m.commitTime;
|
if (m.commitTime > commitTime) commitTime = m.commitTime;
|
||||||
|
@ -530,15 +532,15 @@ contract LiquidPledgingBase is Owned {
|
||||||
function getOldestPledgeNotCanceled(uint64 idPledge
|
function getOldestPledgeNotCanceled(uint64 idPledge
|
||||||
) internal constant returns(uint64) {
|
) internal constant returns(uint64) {
|
||||||
if (idPledge == 0) return 0;
|
if (idPledge == 0) return 0;
|
||||||
Pledge storage n = findPledge(idPledge);
|
Pledge storage p = findPledge(idPledge);
|
||||||
PledgeAdmin storage admin = findAdmin(n.owner);
|
PledgeAdmin storage admin = findAdmin(p.owner);
|
||||||
if (admin.adminType == PledgeAdminType.Giver) return idPledge;
|
if (admin.adminType == PledgeAdminType.Giver) return idPledge;
|
||||||
|
|
||||||
assert(admin.adminType == PledgeAdminType.Project);
|
assert(admin.adminType == PledgeAdminType.Project);
|
||||||
|
|
||||||
if (!isProjectCanceled(n.owner)) return idPledge;
|
if (!isProjectCanceled(p.owner)) return idPledge;
|
||||||
|
|
||||||
return getOldestPledgeNotCanceled(n.oldPledge);
|
return getOldestPledgeNotCanceled(p.oldPledge);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @notice A check to see if the msg.sender is the owner or the
|
/// @notice A check to see if the msg.sender is the owner or the
|
||||||
|
|
|
@ -20,14 +20,14 @@ class LiquidPledgingState {
|
||||||
if (res.oldPledge) {
|
if (res.oldPledge) {
|
||||||
pledge.oldPledge = res.oldPledge;
|
pledge.oldPledge = res.oldPledge;
|
||||||
}
|
}
|
||||||
if (res.paymentState === '0') {
|
if (res.pledgeState === '0') {
|
||||||
pledge.paymentState = 'Pledged';
|
pledge.pledgeState = 'Pledged';
|
||||||
} else if (res.paymentState === '1') {
|
} else if (res.pledgeState === '1') {
|
||||||
pledge.paymentState = 'Paying';
|
pledge.pledgeState = 'Paying';
|
||||||
} else if (res.paymentState === '2') {
|
} else if (res.pledgeState === '2') {
|
||||||
pledge.paymentState = 'Paid';
|
pledge.pledgeState = 'Paid';
|
||||||
} else {
|
} else {
|
||||||
pledge.paymentState = 'Unknown';
|
pledge.pledgeState = 'Unknown';
|
||||||
}
|
}
|
||||||
|
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
@ -68,7 +68,7 @@ class LiquidPledgingState {
|
||||||
admin.name = res.name;
|
admin.name = res.name;
|
||||||
admin.url = res.url;
|
admin.url = res.url;
|
||||||
admin.commitTime = res.commitTime;
|
admin.commitTime = res.commitTime;
|
||||||
if (admin.paymentState === 'Project') {
|
if (admin.adminType === 'Project') {
|
||||||
admin.parentProject = res.parentProject;
|
admin.parentProject = res.parentProject;
|
||||||
admin.canceled = res.canceled;
|
admin.canceled = res.canceled;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue