Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as C# by Sven ( 4 years ago )
// SPDX-License-Identifier: BSD-3-Clause

pragma solidity 0.6.8;

contract Test {

  struct Account {
    uint32 id;
    address sponsor;
    uint8[] activeLevel;
    bool exists;
  }

  uint32 lastId;

  mapping(address => Account) public account;

  constructor() public {}

  function registration(address _sponsor) public payable {
    createAccount(msg.sender, _sponsor);
    handleLevel(msg.sender, 1);
  }

  function hasAccount(address _addr) external view returns (bool) {
    return account[_addr].exists;
  }

  function createAccount(address _addr, address _sponsor) internal {
    lastId++;

    uint8[] memory levels;
    levels[0] = 1;
    Account memory member = Account({id: lastId, sponsor: _sponsor, activeLevel: levels, exists: true});

    account[_addr] = member;
  }

  function handleLevel(address _addr, uint8 level) internal {
    if (account[_addr].activeLevel[0] > level) {
      //The line above cause: Returned error: VM Exception while processing transaction: invalid opcode
    }

  }
}

 

Revise this Paste

Your Name: Code Language: