Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.5.10;
- import "./SuperAccount.sol";
- contract Account is Ownable{
- event NewUser();
- address public superAddress;
- SuperAccount public super_contract;
- struct userAccount{
- uint256 ID;
- uint256 balance;
- uint256 defaultCount;
- bool state;
- address payable owner;
- /////////////////////////////////////
- // uint256[] history;
- }
- constructor(address Super_Contract_Address)
- public
- {
- super_contract = SuperAccount(Super_Contract_Address);
- (superAddress,) = super_contract.getSuper();
- bool exist = false;
- for(uint i=0;i<accounts.length;i++){
- if(accounts[i].owner == msg.sender){
- exist = true;
- break;
- }
- }
- if(!exist){
- _createAccount();
- }
- }
- modifier onlySuper(){
- require(msg.sender == superAddress);
- _;
- }
- userAccount[] public accounts;
- uint[] public accountHistory;
- //keeps track of the address that owns an account by ID
- mapping (address=>uint) public ownerToAccount;
- mapping(uint=>uint[]) public accountToHistory;
- mapping (address => mapping (address => uint256)) allowed;
- using SafeMath for uint256;
- function _createAccount()
- internal
- returns(uint256 id)
- {
- uint256[] memory history;
- id = accounts.push(userAccount(accounts.length,0,0, true,msg.sender)).sub(1);
- ownerToAccount[msg.sender]=id;
- accountToHistory[id] = history;
- emit NewUser();
- return id;
- }
- function getAccount_user(address _user)
- public
- view
- onlyOwner
- returns(uint256, bool,uint256 ){
- (uint256 ID ,bool state,,,uint256 defaultCount,) = _getAccount(_user);
- return (
- ID,
- state,
- defaultCount);
- }
- function getUserAccount_Super(address _user)
- public
- view
- onlySuper
- returns(uint256, bool, address, uint256, uint256, uint256[] memory)
- {
- return _getAccount(_user);
- }
- function _getAccount(address _user)
- internal
- view
- returns(uint256 , bool, address, uint256, uint256, uint256[] memory)
- {
- return (
- accounts[ownerToAccount[_user]].ID,
- accounts[ownerToAccount[_user]].state,
- accounts[ownerToAccount[_user]].owner,
- accounts[ownerToAccount[_user]].balance,
- accounts[ownerToAccount[_user]].defaultCount,
- accountToHistory[ownerToAccount[_user]]);
- }
- function getUserNum()
- public
- view
- returns(uint num)
- {
- return accounts.length;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement