Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. pragma solidity ^0.5.10;
  2.  
  3. import "./SuperAccount.sol";
  4.  
  5. contract Account is Ownable{
  6.  
  7. event NewUser();
  8.  
  9. address public superAddress;
  10. SuperAccount public super_contract;
  11.  
  12. struct userAccount{
  13. uint256 ID;
  14. uint256 balance;
  15. uint256 defaultCount;
  16. bool state;
  17. address payable owner;
  18.  
  19. /////////////////////////////////////
  20. // uint256[] history;
  21. }
  22.  
  23. constructor(address Super_Contract_Address)
  24. public
  25. {
  26. super_contract = SuperAccount(Super_Contract_Address);
  27. (superAddress,) = super_contract.getSuper();
  28. bool exist = false;
  29. for(uint i=0;i<accounts.length;i++){
  30. if(accounts[i].owner == msg.sender){
  31. exist = true;
  32. break;
  33. }
  34. }
  35. if(!exist){
  36. _createAccount();
  37. }
  38. }
  39.  
  40. modifier onlySuper(){
  41. require(msg.sender == superAddress);
  42. _;
  43. }
  44.  
  45. userAccount[] public accounts;
  46. uint[] public accountHistory;
  47.  
  48. //keeps track of the address that owns an account by ID
  49. mapping (address=>uint) public ownerToAccount;
  50. mapping(uint=>uint[]) public accountToHistory;
  51. mapping (address => mapping (address => uint256)) allowed;
  52.  
  53. using SafeMath for uint256;
  54.  
  55. function _createAccount()
  56. internal
  57. returns(uint256 id)
  58. {
  59. uint256[] memory history;
  60. id = accounts.push(userAccount(accounts.length,0,0, true,msg.sender)).sub(1);
  61. ownerToAccount[msg.sender]=id;
  62. accountToHistory[id] = history;
  63. emit NewUser();
  64. return id;
  65. }
  66.  
  67. function getAccount_user(address _user)
  68. public
  69. view
  70. onlyOwner
  71. returns(uint256, bool,uint256 ){
  72. (uint256 ID ,bool state,,,uint256 defaultCount,) = _getAccount(_user);
  73. return (
  74. ID,
  75. state,
  76. defaultCount);
  77. }
  78.  
  79. function getUserAccount_Super(address _user)
  80. public
  81. view
  82. onlySuper
  83. returns(uint256, bool, address, uint256, uint256, uint256[] memory)
  84. {
  85. return _getAccount(_user);
  86. }
  87.  
  88. function _getAccount(address _user)
  89. internal
  90. view
  91. returns(uint256 , bool, address, uint256, uint256, uint256[] memory)
  92. {
  93. return (
  94. accounts[ownerToAccount[_user]].ID,
  95. accounts[ownerToAccount[_user]].state,
  96. accounts[ownerToAccount[_user]].owner,
  97. accounts[ownerToAccount[_user]].balance,
  98. accounts[ownerToAccount[_user]].defaultCount,
  99. accountToHistory[ownerToAccount[_user]]);
  100. }
  101.  
  102. function getUserNum()
  103. public
  104. view
  105. returns(uint num)
  106. {
  107. return accounts.length;
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement