|
|
@ -9,43 +9,38 @@ contract DepositContract { |
|
|
|
event LogUpdateStake(address indexed account, uint index, uint stake); |
|
|
|
event LogUpdateStake(address indexed account, uint index, uint stake); |
|
|
|
event LogDeleteAccount(address indexed account, uint index); |
|
|
|
event LogDeleteAccount(address indexed account, uint index); |
|
|
|
|
|
|
|
|
|
|
|
function isAccount(address account) public view returns(bool isIndeed) |
|
|
|
function isAccount(address account) public view returns(bool isIndeed) { |
|
|
|
{ |
|
|
|
|
|
|
|
if(accountList.length == 0) return false; |
|
|
|
if(accountList.length == 0) return false; |
|
|
|
return (accountList[Indices[account]] == account); |
|
|
|
return (accountList[Indices[account]] == account); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function deposit() public payable returns(uint index) |
|
|
|
function deposit() public payable returns(uint index) { |
|
|
|
{ |
|
|
|
|
|
|
|
if(isAccount(msg.sender)) { |
|
|
|
if(isAccount(msg.sender)) { |
|
|
|
Stakes[msg.sender] += msg.value; |
|
|
|
Stakes[msg.sender] += msg.value; |
|
|
|
emit LogUpdateStake(msg.sender, Indices[msg.sender], Stakes[msg.sender]); |
|
|
|
emit LogUpdateStake(msg.sender, Indices[msg.sender], Stakes[msg.sender]); |
|
|
|
return Indices[msg.sender]; |
|
|
|
return Indices[msg.sender]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Stakes[msg.sender] = msg.value; |
|
|
|
Stakes[msg.sender] = msg.value; |
|
|
|
Indices[msg.sender] = accountList.push(msg.sender) - 1; |
|
|
|
Indices[msg.sender] = accountList.push(msg.sender) - 1; |
|
|
|
emit LogNewAccount(msg.sender, Indices[msg.sender], Stakes[msg.sender]); |
|
|
|
emit LogNewAccount(msg.sender, Indices[msg.sender], Stakes[msg.sender]); |
|
|
|
return accountList.length-1; |
|
|
|
return accountList.length-1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function withdraw(uint withdrawAmount) public returns (uint remainingStake) |
|
|
|
function withdraw(uint withdrawAmount) public returns (uint remainingStake) { |
|
|
|
{ |
|
|
|
|
|
|
|
if (withdrawAmount <= Stakes[msg.sender]){ |
|
|
|
if (withdrawAmount <= Stakes[msg.sender]){ |
|
|
|
Stakes[msg.sender] -= withdrawAmount; |
|
|
|
Stakes[msg.sender] -= withdrawAmount; |
|
|
|
msg.sender.transfer(withdrawAmount); |
|
|
|
msg.sender.transfer(withdrawAmount); |
|
|
|
if (Stakes[msg.sender] == 0) |
|
|
|
if (Stakes[msg.sender] == 0) { //If all stake has been withdrawn, remove the Account. |
|
|
|
{ //If all stake has been withdrawn, remove the Account. |
|
|
|
|
|
|
|
deleteAccount(msg.sender); |
|
|
|
deleteAccount(msg.sender); |
|
|
|
} |
|
|
|
} |
|
|
|
return Stakes[msg.sender]; |
|
|
|
return Stakes[msg.sender]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return Stakes[msg.sender]; //Overdraft protection, no money is withdrawn! |
|
|
|
return Stakes[msg.sender]; //Overdraft protection, no money is withdrawn! |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function deleteAccount(address account) public returns(uint index) |
|
|
|
function deleteAccount(address account) public returns(uint index) { |
|
|
|
{ |
|
|
|
|
|
|
|
//Move the last index to deleted index. |
|
|
|
//Move the last index to deleted index. |
|
|
|
uint indexToDelete = Indices[account]; |
|
|
|
uint indexToDelete = Indices[account]; |
|
|
|
address lastIndexAddress = accountList[accountList.length-1]; |
|
|
|
address lastIndexAddress = accountList[accountList.length-1]; |
|
|
@ -57,16 +52,11 @@ contract DepositContract { |
|
|
|
return indexToDelete; |
|
|
|
return indexToDelete; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getAccountCount() public view returns(uint count) |
|
|
|
function getAccountCount() public view returns(uint count) { |
|
|
|
{ |
|
|
|
|
|
|
|
return accountList.length; |
|
|
|
return accountList.length; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getStakedAccountList() public view returns(address[] memory stakedAccountList) |
|
|
|
function getStakedAccountList() public view returns(address[] memory stakedAccountList) { |
|
|
|
{ |
|
|
|
|
|
|
|
return accountList; |
|
|
|
return accountList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |