Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change paritipantsIndex from hashmap to array #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions contracts/Conference.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ contract Conference is Destructible {
string public name;
uint256 public deposit;
uint public limitOfParticipants;
uint public registered;
uint public attended;
bool public ended;
bool public cancelled;
Expand All @@ -19,7 +18,7 @@ contract Conference is Destructible {
string public encryption;

mapping (address => Participant) public participants;
mapping (uint => address) public participantsIndex;
address[] public participantsIndex;
bool paid;

struct Participant {
Expand Down Expand Up @@ -102,11 +101,10 @@ contract Conference is Destructible {

function registerInternal(string _participant) internal {
require(msg.value == deposit);
require(registered < limitOfParticipants);
require(registered() < limitOfParticipants);
require(!isRegistered(msg.sender));

registered++;
participantsIndex[registered] = msg.sender;
participantsIndex.push(msg.sender);
participants[msg.sender] = Participant(_participant, msg.sender, false, false);
}

Expand All @@ -133,6 +131,14 @@ contract Conference is Destructible {
}

/* Constants */
function registered() constant returns(uint){
return participantsIndex.length;
}

function getParticipants() constant returns (address[]){
return participantsIndex;
}

function totalBalance() constant returns (uint256){
return this.balance;
}
Expand Down
10 changes: 5 additions & 5 deletions log/stress_0002.log
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type gasUsed gasPrice 1ETH*USD gasUsed*gasPrice(Ether) gasUsed*gasPrice(USD)
create 1686592 2 303 0.003373184 1.022074752
addConfirmation 89601 2 303 0.000179202 0.054298206
register 119996 2 303 0.000239992 0.07271757599999999
batchAttend 67248 2 303 0.000134496 0.040752288000000005
payback 84552 2 303 0.000169104 0.051238512
create 1764065 2 303 0.00352813 1.06902339
addConfirmation 89537 2 303 0.000179074 0.054259421999999995
register 120265 2 303 0.00024053 0.07288059
batchAttend 67270 2 303 0.00013454 0.040765619999999995
payback 84574 2 303 0.000169148 0.051251844
withdraw 37890 2 303 0.00007578 0.02296134
10 changes: 5 additions & 5 deletions log/stress_0020.log
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type gasUsed gasPrice 1ETH*USD gasUsed*gasPrice(Ether) gasUsed*gasPrice(USD)
create 1686592 2 303 0.003373184 1.022074752
addConfirmation 694042 2 303 0.001388084 0.420589452
register 119996 2 303 0.000239992 0.07271757599999999
batchAttend 331147 2 303 0.000662294 0.200675082
payback 84552 2 303 0.000169104 0.051238512
create 1764065 2 303 0.00352813 1.06902339
addConfirmation 693978 2 303 0.001387956 0.420550668
register 120265 2 303 0.00024053 0.07288059
batchAttend 331105 2 303 0.00066221 0.20064963
payback 84574 2 303 0.000169148 0.051251844
withdraw 37890 2 303 0.00007578 0.02296134
10 changes: 5 additions & 5 deletions log/stress_0100.log
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type gasUsed gasPrice 1ETH*USD gasUsed*gasPrice(Ether) gasUsed*gasPrice(USD)
create 1686592 2 303 0.003373184 1.022074752
addConfirmation 3381099 2 303 0.006762198 2.048945994
register 119996 2 303 0.000239992 0.07271757599999999
batchAttend 1503663 2 303 0.003007326 0.911219778
payback 84552 2 303 0.000169104 0.051238512
create 1764065 2 303 0.00352813 1.06902339
addConfirmation 3381035 2 303 0.00676207 2.04890721
register 120265 2 303 0.00024053 0.07288059
batchAttend 1503749 2 303 0.003007498 0.911271894
payback 84574 2 303 0.000169148 0.051251844
withdraw 37890 2 303 0.00007578 0.02296134
10 changes: 5 additions & 5 deletions log/stress_0200.log
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type gasUsed gasPrice 1ETH*USD gasUsed*gasPrice(Ether) gasUsed*gasPrice(USD)
create 1692580 2 303 0.00338516 1.02570348
register 119815 2 303 0.00023963 0.07260789000000001
batchAttend 2969251 2 303 0.005938502 1.799366106
payback 84325 2 303 0.00016865 0.05110095
withdraw 37660 2 303 0.00007532 0.022821960000000002
create 1764065 2 303 0.00352813 1.06902339
register 120265 2 303 0.00024053 0.07288059
batchAttend 2969398 2 303 0.005938796 1.7994551879999998
payback 84574 2 303 0.000169148 0.051251844
withdraw 37890 2 303 0.00007578 0.02296134
10 changes: 5 additions & 5 deletions log/stress_0300.log
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type gasUsed gasPrice 1ETH*USD gasUsed*gasPrice(Ether) gasUsed*gasPrice(USD)
create 1692644 2 303 0.003385288 1.025742264
register 119815 2 303 0.00023963 0.07260789000000001
batchAttend 4434618 2 303 0.008869236 2.687378508
payback 84325 2 303 0.00016865 0.05110095
withdraw 37660 2 303 0.00007532 0.022821960000000002
create 1764129 2 303 0.003528258 1.069062174
register 120265 2 303 0.00024053 0.07288059
batchAttend 4435021 2 303 0.008870042 2.687622726
payback 84574 2 303 0.000169148 0.051251844
withdraw 37890 2 303 0.00007578 0.02296134
4 changes: 4 additions & 0 deletions test/conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ contract('Conference', function(accounts) {
assert.equal((await conference.registered.call()).toNumber(), 1);
})

it('getParticipants returns list of addresses', async function(){
assert.equal((await conference.getParticipants.call())[0], owner);
})

it('increases totalBalance', async function(){
assert.equal((await conference.totalBalance.call()) - beforeContractBalance , deposit);
})
Expand Down