Address Details
contract

0x61257EAF53497829636383f6C4AC467D575c3fd5

Contract Name
AddressLinkedList
Creator
0xe23a4c–2b2dee at 0x915a43–7a03c7
Balance
0 CELO ( )
Locked CELO Balance
0.00 CELO
Voting CELO Balance
0.00 CELO
Pending Unlocked Gold
0.00 CELO
Tokens
Fetching tokens...
Transactions
0 Transactions
Transfers
0 Transfers
Gas Used
Fetching gas used...
Last Balance Update
3543806
Contract name:
AddressLinkedList




Optimization enabled
false
Compiler version
v0.5.8+commit.23d335f2




Verified at
2020-04-22T22:47:00.686872Z

Contract source code

pragma solidity ^0.5.3;


library SafeMath {
    
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");

        return c;
    }

    
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return sub(a, b, "SafeMath: subtraction overflow");
    }

    
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;

        return c;
    }

    
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        
        
        
        if (a == 0) {
            return 0;
        }

        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");

        return c;
    }

    
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return div(a, b, "SafeMath: division by zero");
    }

    
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        
        require(b > 0, errorMessage);
        uint256 c = a / b;
        

        return c;
    }

    
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return mod(a, b, "SafeMath: modulo by zero");
    }

    
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b != 0, errorMessage);
        return a % b;
    }
}

library LinkedList {
  using SafeMath for uint256;

  struct Element {
    bytes32 previousKey;
    bytes32 nextKey;
    bool exists;
  }

  struct List {
    bytes32 head;
    bytes32 tail;
    uint256 numElements;
    mapping(bytes32 => Element) elements;
  }

  
  function insert(List storage list, bytes32 key, bytes32 previousKey, bytes32 nextKey) public {
    require(key != bytes32(0), "Key must be defined");
    require(!contains(list, key), "Can't insert an existing element");
    require(
      previousKey != key && nextKey != key,
      "Key cannot be the same as previousKey or nextKey"
    );

    Element storage element = list.elements[key];
    element.exists = true;

    if (list.numElements == 0) {
      list.tail = key;
      list.head = key;
    } else {
      require(
        previousKey != bytes32(0) || nextKey != bytes32(0),
        "Either previousKey or nextKey must be defined"
      );

      element.previousKey = previousKey;
      element.nextKey = nextKey;

      if (previousKey != bytes32(0)) {
        require(
          contains(list, previousKey),
          "If previousKey is defined, it must exist in the list"
        );
        Element storage previousElement = list.elements[previousKey];
        require(previousElement.nextKey == nextKey, "previousKey must be adjacent to nextKey");
        previousElement.nextKey = key;
      } else {
        list.tail = key;
      }

      if (nextKey != bytes32(0)) {
        require(contains(list, nextKey), "If nextKey is defined, it must exist in the list");
        Element storage nextElement = list.elements[nextKey];
        require(nextElement.previousKey == previousKey, "previousKey must be adjacent to nextKey");
        nextElement.previousKey = key;
      } else {
        list.head = key;
      }
    }

    list.numElements = list.numElements.add(1);
  }

  
  function push(List storage list, bytes32 key) public {
    insert(list, key, bytes32(0), list.tail);
  }

  
  function remove(List storage list, bytes32 key) public {
    Element storage element = list.elements[key];
    require(key != bytes32(0) && contains(list, key), "key not in list");
    if (element.previousKey != bytes32(0)) {
      Element storage previousElement = list.elements[element.previousKey];
      previousElement.nextKey = element.nextKey;
    } else {
      list.tail = element.nextKey;
    }

    if (element.nextKey != bytes32(0)) {
      Element storage nextElement = list.elements[element.nextKey];
      nextElement.previousKey = element.previousKey;
    } else {
      list.head = element.previousKey;
    }

    delete list.elements[key];
    list.numElements = list.numElements.sub(1);
  }

  
  function update(List storage list, bytes32 key, bytes32 previousKey, bytes32 nextKey) public {
    require(
      key != bytes32(0) && key != previousKey && key != nextKey && contains(list, key),
      "key on in list"
    );
    remove(list, key);
    insert(list, key, previousKey, nextKey);
  }

  
  function contains(List storage list, bytes32 key) public view returns (bool) {
    return list.elements[key].exists;
  }

  
  function headN(List storage list, uint256 n) public view returns (bytes32[] memory) {
    require(n <= list.numElements, "not enough elements");
    bytes32[] memory keys = new bytes32[](n);
    bytes32 key = list.head;
    for (uint256 i = 0; i < n; i = i.add(1)) {
      keys[i] = key;
      key = list.elements[key].previousKey;
    }
    return keys;
  }

  
  function getKeys(List storage list) public view returns (bytes32[] memory) {
    return headN(list, list.numElements);
  }
}

library AddressLinkedList {
  using LinkedList for LinkedList.List;
  using SafeMath for uint256;

  function toBytes(address a) public pure returns (bytes32) {
    return bytes32(uint256(a) << 96);
  }

  function toAddress(bytes32 b) public pure returns (address) {
    return address(uint256(b) >> 96);
  }

  
  function insert(LinkedList.List storage list, address key, address previousKey, address nextKey)
    public
  {
    list.insert(toBytes(key), toBytes(previousKey), toBytes(nextKey));
  }

  
  function push(LinkedList.List storage list, address key) public {
    list.insert(toBytes(key), bytes32(0), list.tail);
  }

  
  function remove(LinkedList.List storage list, address key) public {
    list.remove(toBytes(key));
  }

  
  function update(LinkedList.List storage list, address key, address previousKey, address nextKey)
    public
  {
    list.update(toBytes(key), toBytes(previousKey), toBytes(nextKey));
  }

  
  function contains(LinkedList.List storage list, address key) public view returns (bool) {
    return list.elements[toBytes(key)].exists;
  }

  
  function headN(LinkedList.List storage list, uint256 n) public view returns (address[] memory) {
    bytes32[] memory byteKeys = list.headN(n);
    address[] memory keys = new address[](n);
    for (uint256 i = 0; i < n; i = i.add(1)) {
      keys[i] = toAddress(byteKeys[i]);
    }
    return keys;
  }

  
  function getKeys(LinkedList.List storage list) public view returns (address[] memory) {
    return headN(list, list.numElements);
  }
}
        

Contract ABI

[{"type":"function","stateMutability":"pure","payable":false,"outputs":[{"type":"address","name":""}],"name":"toAddress","inputs":[{"type":"bytes32","name":"b"}],"constant":true},{"type":"function","stateMutability":"pure","payable":false,"outputs":[{"type":"bytes32","name":""}],"name":"toBytes","inputs":[{"type":"address","name":"a"}],"constant":true}]
              

Contract Creation Code

0x610a0e610026600b82828239805160001a60731461001957fe5b30600052607381538281f3fe730000000000000000000000000000000000000000301460806040526004361061009d5760003560e01c8063593b79fe11610070578063593b79fe1461026c578063b1cfea43146102c4578063b2f8fe9614610351578063e2c0c56a146103ec578063fe3c7a8e146104475761009d565b806307debf7c146100a257806326afac491461013d578063341f662314610198578063542424fb14610206575b600080fd5b8180156100ae57600080fd5b5061013b600480360360808110156100c557600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506104ca565b005b81801561014957600080fd5b506101966004803603604081101561016057600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610569565b005b6101c4600480360360208110156101ae57600080fd5b81019080803590602001909291905050506105fd565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102526004803603604081101561021c57600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061060e565b604051808215151515815260200191505060405180910390f35b6102ae6004803603602081101561028257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610646565b6040518082815260200191505060405180910390f35b6102fa600480360360408110156102da57600080fd5b81019080803590602001909291908035906020019092919050505061066d565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b8381101561033d578082015181840152602081019050610322565b505050509050019250505060405180910390f35b81801561035d57600080fd5b506103ea6004803603608081101561037457600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610827565b005b8180156103f857600080fd5b506104456004803603604081101561040f57600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506108c6565b005b6104736004803603602081101561045d57600080fd5b8101908080359060200190929190505050610943565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156104b657808201518184015260208101905061049b565b505050509050019250505060405180910390f35b83734cf604c6251c87d0c83e17f88397dec67ead825f63e931818590916104f086610646565b6104f986610646565b61050286610646565b6040518563ffffffff1660e01b81526004018085815260200184815260200183815260200182815260200194505050505060006040518083038186803b15801561054b57600080fd5b505af415801561055f573d6000803e3d6000fd5b5050505050505050565b81734cf604c6251c87d0c83e17f88397dec67ead825f63e9318185909161058f84610646565b6000801b86600101546040518563ffffffff1660e01b81526004018085815260200184815260200183815260200182815260200194505050505060006040518083038186803b1580156105e157600080fd5b505af41580156105f5573d6000803e3d6000fd5b505050505050565b600060608260001c901c9050919050565b600082600301600061061f84610646565b815260200190815260200160002060020160009054906101000a900460ff16905092915050565b600060608273ffffffffffffffffffffffffffffffffffffffff16901b60001b9050919050565b60608083734cf604c6251c87d0c83e17f88397dec67ead825f63b1cfea439091856040518363ffffffff1660e01b8152600401808381526020018281526020019250505060006040518083038186803b1580156106c957600080fd5b505af41580156106dd573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250602081101561070757600080fd5b81019080805164010000000081111561071f57600080fd5b8281019050602081018481111561073557600080fd5b815185602082028301116401000000008211171561075257600080fd5b5050929190505050905060608360405190808252806020026020018201604052801561078d5781602001602082028038833980820191505090505b50905060008090505b8481101561081b576107ba8382815181106107ad57fe5b60200260200101516105fd565b8282815181106107c657fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505061081460018261095a90919063ffffffff16565b9050610796565b50809250505092915050565b83734cf604c6251c87d0c83e17f88397dec67ead825f6389dc4fff909161084d86610646565b61085686610646565b61085f86610646565b6040518563ffffffff1660e01b81526004018085815260200184815260200183815260200182815260200194505050505060006040518083038186803b1580156108a857600080fd5b505af41580156108bc573d6000803e3d6000fd5b5050505050505050565b81734cf604c6251c87d0c83e17f88397dec67ead825f6342c22dbc90916108ec84610646565b6040518363ffffffff1660e01b8152600401808381526020018281526020019250505060006040518083038186803b15801561092757600080fd5b505af415801561093b573d6000803e3d6000fd5b505050505050565b606061095382836002015461066d565b9050919050565b6000808284019050838110156109d8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b809150509291505056fea165627a7a72305820825d47aa6cdf71d5938311803ce23d290bd275ab90758d74d4a2fbc0eadd4d150029

Deployed ByteCode

0x7361257eaf53497829636383f6c4ac467d575c3fd5301460806040526004361061009d5760003560e01c8063593b79fe11610070578063593b79fe1461026c578063b1cfea43146102c4578063b2f8fe9614610351578063e2c0c56a146103ec578063fe3c7a8e146104475761009d565b806307debf7c146100a257806326afac491461013d578063341f662314610198578063542424fb14610206575b600080fd5b8180156100ae57600080fd5b5061013b600480360360808110156100c557600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506104ca565b005b81801561014957600080fd5b506101966004803603604081101561016057600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610569565b005b6101c4600480360360208110156101ae57600080fd5b81019080803590602001909291905050506105fd565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6102526004803603604081101561021c57600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061060e565b604051808215151515815260200191505060405180910390f35b6102ae6004803603602081101561028257600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610646565b6040518082815260200191505060405180910390f35b6102fa600480360360408110156102da57600080fd5b81019080803590602001909291908035906020019092919050505061066d565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b8381101561033d578082015181840152602081019050610322565b505050509050019250505060405180910390f35b81801561035d57600080fd5b506103ea6004803603608081101561037457600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803573ffffffffffffffffffffffffffffffffffffffff169060200190929190505050610827565b005b8180156103f857600080fd5b506104456004803603604081101561040f57600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506108c6565b005b6104736004803603602081101561045d57600080fd5b8101908080359060200190929190505050610943565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156104b657808201518184015260208101905061049b565b505050509050019250505060405180910390f35b83734cf604c6251c87d0c83e17f88397dec67ead825f63e931818590916104f086610646565b6104f986610646565b61050286610646565b6040518563ffffffff1660e01b81526004018085815260200184815260200183815260200182815260200194505050505060006040518083038186803b15801561054b57600080fd5b505af415801561055f573d6000803e3d6000fd5b5050505050505050565b81734cf604c6251c87d0c83e17f88397dec67ead825f63e9318185909161058f84610646565b6000801b86600101546040518563ffffffff1660e01b81526004018085815260200184815260200183815260200182815260200194505050505060006040518083038186803b1580156105e157600080fd5b505af41580156105f5573d6000803e3d6000fd5b505050505050565b600060608260001c901c9050919050565b600082600301600061061f84610646565b815260200190815260200160002060020160009054906101000a900460ff16905092915050565b600060608273ffffffffffffffffffffffffffffffffffffffff16901b60001b9050919050565b60608083734cf604c6251c87d0c83e17f88397dec67ead825f63b1cfea439091856040518363ffffffff1660e01b8152600401808381526020018281526020019250505060006040518083038186803b1580156106c957600080fd5b505af41580156106dd573d6000803e3d6000fd5b505050506040513d6000823e3d601f19601f82011682018060405250602081101561070757600080fd5b81019080805164010000000081111561071f57600080fd5b8281019050602081018481111561073557600080fd5b815185602082028301116401000000008211171561075257600080fd5b5050929190505050905060608360405190808252806020026020018201604052801561078d5781602001602082028038833980820191505090505b50905060008090505b8481101561081b576107ba8382815181106107ad57fe5b60200260200101516105fd565b8282815181106107c657fe5b602002602001019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505061081460018261095a90919063ffffffff16565b9050610796565b50809250505092915050565b83734cf604c6251c87d0c83e17f88397dec67ead825f6389dc4fff909161084d86610646565b61085686610646565b61085f86610646565b6040518563ffffffff1660e01b81526004018085815260200184815260200183815260200182815260200194505050505060006040518083038186803b1580156108a857600080fd5b505af41580156108bc573d6000803e3d6000fd5b5050505050505050565b81734cf604c6251c87d0c83e17f88397dec67ead825f6342c22dbc90916108ec84610646565b6040518363ffffffff1660e01b8152600401808381526020018281526020019250505060006040518083038186803b15801561092757600080fd5b505af415801561093b573d6000803e3d6000fd5b505050505050565b606061095382836002015461066d565b9050919050565b6000808284019050838110156109d8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601b8152602001807f536166654d6174683a206164646974696f6e206f766572666c6f77000000000081525060200191505060405180910390fd5b809150509291505056fea165627a7a72305820825d47aa6cdf71d5938311803ce23d290bd275ab90758d74d4a2fbc0eadd4d150029

External libraries