No plugin update plus public normalizeNote and cancelNote and allow to be called from plugin

This commit is contained in:
Jordi Baylina 2017-09-18 15:43:09 +02:00
parent b20420edad
commit 34e928ced9
No known key found for this signature in database
GPG Key ID: 7480C80C1BE43112
12 changed files with 143 additions and 211 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -115,8 +115,7 @@ contract LiquidPledgingBase {
uint64 idDonor,
address newAddr,
string newName,
uint64 newCommitTime,
ILiquidPledgingPlugin newPlugin)
uint64 newCommitTime)
{
NoteManager storage donor = findManager(idDonor);
require(donor.managerType == NoteManagerType.Donor);
@ -124,7 +123,6 @@ contract LiquidPledgingBase {
donor.addr = newAddr;
donor.name = newName;
donor.commitTime = newCommitTime;
donor.plugin = newPlugin;
DonorUpdated(idDonor);
}
@ -152,15 +150,13 @@ contract LiquidPledgingBase {
uint64 idDelegate,
address newAddr,
string newName,
uint64 newCommitTime,
ILiquidPledgingPlugin newPlugin) {
uint64 newCommitTime) {
NoteManager storage delegate = findManager(idDelegate);
require(delegate.managerType == NoteManagerType.Delegate);
require(delegate.addr == msg.sender);
delegate.addr = newAddr;
delegate.name = newName;
delegate.commitTime = newCommitTime;
delegate.plugin = newPlugin;
DelegateUpdated(idDelegate);
}
@ -191,14 +187,18 @@ contract LiquidPledgingBase {
event ProjectAdded(uint64 indexed idProject);
function updateProject(uint64 idProject, address newAddr, string newName, uint64 newCommitTime, ILiquidPledgingPlugin newPlugin) {
function updateProject(
uint64 idProject,
address newAddr,
string newName,
uint64 newCommitTime)
{
NoteManager storage project = findManager(idProject);
require(project.managerType == NoteManagerType.Project);
require(project.addr == msg.sender);
project.addr = newAddr;
project.name = newName;
project.commitTime = newCommitTime;
project.plugin = newPlugin;
ProjectUpdated(idProject);
}
@ -376,4 +376,11 @@ contract LiquidPledgingBase {
return getOldestNoteNotCanceled(n.oldNote);
}
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

View File

@ -115,8 +115,7 @@ contract LiquidPledgingBase {
uint64 idDonor,
address newAddr,
string newName,
uint64 newCommitTime,
ILiquidPledgingPlugin newPlugin)
uint64 newCommitTime)
{
NoteManager storage donor = findManager(idDonor);
require(donor.managerType == NoteManagerType.Donor);
@ -124,7 +123,6 @@ contract LiquidPledgingBase {
donor.addr = newAddr;
donor.name = newName;
donor.commitTime = newCommitTime;
donor.plugin = newPlugin;
DonorUpdated(idDonor);
}
@ -152,15 +150,13 @@ contract LiquidPledgingBase {
uint64 idDelegate,
address newAddr,
string newName,
uint64 newCommitTime,
ILiquidPledgingPlugin newPlugin) {
uint64 newCommitTime) {
NoteManager storage delegate = findManager(idDelegate);
require(delegate.managerType == NoteManagerType.Delegate);
require(delegate.addr == msg.sender);
delegate.addr = newAddr;
delegate.name = newName;
delegate.commitTime = newCommitTime;
delegate.plugin = newPlugin;
DelegateUpdated(idDelegate);
}
@ -191,14 +187,18 @@ contract LiquidPledgingBase {
event ProjectAdded(uint64 indexed idProject);
function updateProject(uint64 idProject, address newAddr, string newName, uint64 newCommitTime, ILiquidPledgingPlugin newPlugin) {
function updateProject(
uint64 idProject,
address newAddr,
string newName,
uint64 newCommitTime)
{
NoteManager storage project = findManager(idProject);
require(project.managerType == NoteManagerType.Project);
require(project.addr == msg.sender);
project.addr = newAddr;
project.name = newName;
project.commitTime = newCommitTime;
project.plugin = newPlugin;
ProjectUpdated(idProject);
}
@ -376,6 +376,13 @@ contract LiquidPledgingBase {
return getOldestNoteNotCanceled(n.oldNote);
}
function checkManagerOwner(NoteManager m) internal constant {
require((msg.sender == m.addr) || (msg.sender == address(m.plugin)));
}
}
//File: contracts/LiquidPledging.sol
@ -406,8 +413,9 @@ contract LiquidPledging is LiquidPledgingBase {
function donate(uint64 idDonor, uint64 idReceiver) payable {// TODO change to `pledge()`
NoteManager storage sender = findManager(idDonor);
checkManagerOwner(sender);
require(sender.managerType == NoteManagerType.Donor);
require(sender.addr == msg.sender);
uint amount = msg.value;
@ -447,7 +455,7 @@ contract LiquidPledging is LiquidPledgingBase {
NoteManager storage receiver = findManager(idReceiver);
NoteManager storage sender = findManager(idSender);
require(sender.addr == msg.sender);
checkManagerOwner(sender);
require(n.paymentState == PaymentState.NotPaid);
// If the sender is the owner
@ -530,7 +538,7 @@ contract LiquidPledging is LiquidPledgingBase {
NoteManager storage owner = findManager(n.owner);
require(owner.addr == msg.sender);
checkManagerOwner(owner);
uint64 idNewNote = findNote(
n.owner,
@ -596,10 +604,23 @@ contract LiquidPledging is LiquidPledgingBase {
/// @param idProject Id of the projct that wants to be canceled.
function cancelProject(uint64 idProject) {
NoteManager storage project = findManager(idProject);
require(project.addr == msg.sender);
checkManagerOwner(project);
project.canceled = true;
}
function cancelNote(uint64 idNote, uint amount) {
idNote = normalizeNote(idNote);
Note storage n = findNote(idNote);
NoteManager storage m = findManager(n.owner);
checkManagerOwner(m);
doTransfer(idNote, n.oldNote, amount);
}
////////
// Multi note methods
////////

View File

@ -115,8 +115,7 @@ contract LiquidPledgingBase {
uint64 idDonor,
address newAddr,
string newName,
uint64 newCommitTime,
ILiquidPledgingPlugin newPlugin)
uint64 newCommitTime)
{
NoteManager storage donor = findManager(idDonor);
require(donor.managerType == NoteManagerType.Donor);
@ -124,7 +123,6 @@ contract LiquidPledgingBase {
donor.addr = newAddr;
donor.name = newName;
donor.commitTime = newCommitTime;
donor.plugin = newPlugin;
DonorUpdated(idDonor);
}
@ -152,15 +150,13 @@ contract LiquidPledgingBase {
uint64 idDelegate,
address newAddr,
string newName,
uint64 newCommitTime,
ILiquidPledgingPlugin newPlugin) {
uint64 newCommitTime) {
NoteManager storage delegate = findManager(idDelegate);
require(delegate.managerType == NoteManagerType.Delegate);
require(delegate.addr == msg.sender);
delegate.addr = newAddr;
delegate.name = newName;
delegate.commitTime = newCommitTime;
delegate.plugin = newPlugin;
DelegateUpdated(idDelegate);
}
@ -191,14 +187,18 @@ contract LiquidPledgingBase {
event ProjectAdded(uint64 indexed idProject);
function updateProject(uint64 idProject, address newAddr, string newName, uint64 newCommitTime, ILiquidPledgingPlugin newPlugin) {
function updateProject(
uint64 idProject,
address newAddr,
string newName,
uint64 newCommitTime)
{
NoteManager storage project = findManager(idProject);
require(project.managerType == NoteManagerType.Project);
require(project.addr == msg.sender);
project.addr = newAddr;
project.name = newName;
project.commitTime = newCommitTime;
project.plugin = newPlugin;
ProjectUpdated(idProject);
}
@ -376,6 +376,13 @@ contract LiquidPledgingBase {
return getOldestNoteNotCanceled(n.oldNote);
}
function checkManagerOwner(NoteManager m) internal constant {
require((msg.sender == m.addr) || (msg.sender == address(m.plugin)));
}
}
//File: ./contracts/LiquidPledging.sol
@ -406,8 +413,9 @@ contract LiquidPledging is LiquidPledgingBase {
function donate(uint64 idDonor, uint64 idReceiver) payable {// TODO change to `pledge()`
NoteManager storage sender = findManager(idDonor);
checkManagerOwner(sender);
require(sender.managerType == NoteManagerType.Donor);
require(sender.addr == msg.sender);
uint amount = msg.value;
@ -447,7 +455,7 @@ contract LiquidPledging is LiquidPledgingBase {
NoteManager storage receiver = findManager(idReceiver);
NoteManager storage sender = findManager(idSender);
require(sender.addr == msg.sender);
checkManagerOwner(sender);
require(n.paymentState == PaymentState.NotPaid);
// If the sender is the owner
@ -530,7 +538,7 @@ contract LiquidPledging is LiquidPledgingBase {
NoteManager storage owner = findManager(n.owner);
require(owner.addr == msg.sender);
checkManagerOwner(owner);
uint64 idNewNote = findNote(
n.owner,
@ -596,10 +604,23 @@ contract LiquidPledging is LiquidPledgingBase {
/// @param idProject Id of the projct that wants to be canceled.
function cancelProject(uint64 idProject) {
NoteManager storage project = findManager(idProject);
require(project.addr == msg.sender);
checkManagerOwner(project);
project.canceled = true;
}
function cancelNote(uint64 idNote, uint amount) {
idNote = normalizeNote(idNote);
Note storage n = findNote(idNote);
NoteManager storage m = findManager(n.owner);
checkManagerOwner(m);
doTransfer(idNote, n.oldNote, amount);
}
////////
// Multi note methods
////////

View File

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

View File

@ -1,74 +0,0 @@
contract LiquidPledgingInterface {
function addUser
function updateUser
function addCause
function deposit(uint64 user) payable;
function withdraw(uint64 user, uint64 idNote, uint amount);
function delegate(uint64 user, uint64 idNote, uint64 purpuse, uint amout);
function undelegate(uint64 user, uint64 idNote, uint amount);
function precommit(uint user, uint64 idNote, uint64 recipient, uint amount);
function unPrecommit(uint user, uint64 idNote, uint amount);
function transfer(uint64 user, uint64 idNote, uint64 recipient, uint amount);
}
owner project out
owner transfer invest withdrow
project uninvest detail spend
in deposit xx xx
Who owns
////
Liquid LiquidPledging
//////
Funding part
/////
Executive part
contract Project {
struct TokenOwnership {
address token;
uint purchaseBlock;
uint amount;
bytes32 ref;
}
Minime2Token public projectToken;
mapping(uint => Minime2Token) public pledgedTokens;
TokenOwnership[] public ownerships;
function pledge(address investor, uint amount, uint precommit);
function unpledge(address investor, uint amount);
function invest(address investor, uint amount);
function unInvest(address investor, uint amount);
function pay(address dest, uint amount, uint block) onlyProjectManager;
function receive(uint amount);
function payDividends(uint token, uint amount, uint payBlock);
}

View File

@ -25,8 +25,9 @@ contract LiquidPledging is LiquidPledgingBase {
function donate(uint64 idDonor, uint64 idReceiver) payable {// TODO change to `pledge()`
NoteManager storage sender = findManager(idDonor);
checkManagerOwner(sender);
require(sender.managerType == NoteManagerType.Donor);
require(sender.addr == msg.sender);
uint amount = msg.value;
@ -66,7 +67,7 @@ contract LiquidPledging is LiquidPledgingBase {
NoteManager storage receiver = findManager(idReceiver);
NoteManager storage sender = findManager(idSender);
require(sender.addr == msg.sender);
checkManagerOwner(sender);
require(n.paymentState == PaymentState.NotPaid);
// If the sender is the owner
@ -149,7 +150,7 @@ contract LiquidPledging is LiquidPledgingBase {
NoteManager storage owner = findManager(n.owner);
require(owner.addr == msg.sender);
checkManagerOwner(owner);
uint64 idNewNote = findNote(
n.owner,
@ -215,10 +216,23 @@ contract LiquidPledging is LiquidPledgingBase {
/// @param idProject Id of the projct that wants to be canceled.
function cancelProject(uint64 idProject) {
NoteManager storage project = findManager(idProject);
require(project.addr == msg.sender);
checkManagerOwner(project);
project.canceled = true;
}
function cancelNote(uint64 idNote, uint amount) {
idNote = normalizeNote(idNote);
Note storage n = findNote(idNote);
NoteManager storage m = findManager(n.owner);
checkManagerOwner(m);
doTransfer(idNote, n.oldNote, amount);
}
////////
// Multi note methods
////////
@ -262,6 +276,14 @@ contract LiquidPledging is LiquidPledgingBase {
}
}
function mNormalizeNote(uint[] notes) returns(uint64) {
for (uint i = 0; i < notes.length; i++ ) {
uint64 idNote = uint64( notes[i] & (D64-1) );
normalizeNote(idNote, amount);
}
}
////////
// Private methods
///////
@ -375,7 +397,9 @@ contract LiquidPledging is LiquidPledgingBase {
// 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.
function normalizeNote(uint64 idNote) internal returns(uint64) {
// 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.
function normalizeNote(uint64 idNote) returns(uint64) {
Note storage n = findNote(idNote);
// Check to make sure this note hasnt already been used or is in the process of being used

View File

@ -92,8 +92,7 @@ contract LiquidPledgingBase {
uint64 idDonor,
address newAddr,
string newName,
uint64 newCommitTime,
ILiquidPledgingPlugin newPlugin)
uint64 newCommitTime)
{
NoteManager storage donor = findManager(idDonor);
require(donor.managerType == NoteManagerType.Donor);
@ -101,7 +100,6 @@ contract LiquidPledgingBase {
donor.addr = newAddr;
donor.name = newName;
donor.commitTime = newCommitTime;
donor.plugin = newPlugin;
DonorUpdated(idDonor);
}
@ -129,15 +127,13 @@ contract LiquidPledgingBase {
uint64 idDelegate,
address newAddr,
string newName,
uint64 newCommitTime,
ILiquidPledgingPlugin newPlugin) {
uint64 newCommitTime) {
NoteManager storage delegate = findManager(idDelegate);
require(delegate.managerType == NoteManagerType.Delegate);
require(delegate.addr == msg.sender);
delegate.addr = newAddr;
delegate.name = newName;
delegate.commitTime = newCommitTime;
delegate.plugin = newPlugin;
DelegateUpdated(idDelegate);
}
@ -168,14 +164,18 @@ contract LiquidPledgingBase {
event ProjectAdded(uint64 indexed idProject);
function updateProject(uint64 idProject, address newAddr, string newName, uint64 newCommitTime, ILiquidPledgingPlugin newPlugin) {
function updateProject(
uint64 idProject,
address newAddr,
string newName,
uint64 newCommitTime)
{
NoteManager storage project = findManager(idProject);
require(project.managerType == NoteManagerType.Project);
require(project.addr == msg.sender);
project.addr = newAddr;
project.name = newName;
project.commitTime = newCommitTime;
project.plugin = newPlugin;
ProjectUpdated(idProject);
}
@ -353,4 +353,11 @@ contract LiquidPledgingBase {
return getOldestNoteNotCanceled(n.oldNote);
}
function checkManagerOwner(NoteManager m) internal constant {
require((msg.sender == m.addr) || (msg.sender == address(m.plugin)));
}
}

View File

@ -1,6 +1,6 @@
{
"name": "liquidpledging",
"version": "0.0.5",
"version": "0.0.6",
"description": "Liquid Pledging Smart Contract",
"main": "index.js",
"directories": {

View File

@ -48,7 +48,7 @@ describe('LiquidPledging test', () => {
let adminProject2a;
let delegate2;
before((done) => {
ethConnector.init('testrpc', { gasLimit: 4700000 }, () => {
ethConnector.init('testrpc', { gasLimit: 5200000 }, () => {
web3 = ethConnector.web3;
accounts = ethConnector.accounts;
donor1 = accounts[1];
@ -62,7 +62,7 @@ describe('LiquidPledging test', () => {
});
it('Should deploy LiquidPledgin contract', async () => {
vault = await Vault.new(web3);
liquidPledging = await LiquidPledging.new(web3, vault.$address);
liquidPledging = await LiquidPledging.new(web3, vault.$address, { gas: 5200000 });
await vault.setLiquidPledging(liquidPledging.$address);
}).timeout(6000);
it('Should create a donor', async () => {