formatting and changing node name

pull/367/head
ak 6 years ago
parent 9fe7d7a8c2
commit e7561e015f
  1. 24
      contracts/DepositContract.sol

@ -9,14 +9,12 @@ 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]);
@ -29,13 +27,11 @@ contract DepositContract {
} }
} }
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];
@ -44,8 +40,7 @@ contract DepositContract {
} }
} }
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;
} }
} }
Loading…
Cancel
Save