1

Just going through some of the 0x Contract Code trying to improve my understanding of solidity and Smart Contract oriented language programming.

Stumbled on the TokenRegistry.sol contract and trying to get a bit of a deeper understanding of it. In 0x there is an exchange and token registry holding all the tokens available for sale by buyers and sellers.

Are these values held in the contract, if so how can this be efficient and feasible in terms of mining and computation?

This makes the TokenRegistry contract feel like a "God" type of contract which maps all token values to addresses. Is this a usual design pattern?

pragma solidity 0.4.11;

import "./base/Ownable.sol";

contract TokenRegistry is Ownable {

mapping (address => TokenMetadata) public tokens;
mapping (string => address) tokenBySymbol;
mapping (string => address) tokenByName;

address[] public tokenAddresses;

struct TokenMetadata {
    address token;
    string name;
    string symbol;
    uint8 decimals;
    bytes ipfsHash;
    bytes swarmHash;
}
//..
function addToken(
    address _token,
    string _name,
    string _symbol,
    uint8 _decimals,
    bytes _ipfsHash,
    bytes _swarmHash)
    public
    onlyOwner
    tokenDoesNotExist(_token)
    addressNotNull(_token)
    symbolDoesNotExist(_symbol)
    nameDoesNotExist(_name)
{
    tokens[_token] = TokenMetadata({
        token: _token,
        name: _name,
        symbol: _symbol,
        decimals: _decimals,
        ipfsHash: _ipfsHash,
        swarmHash: _swarmHash
    });
    tokenAddresses.push(_token);
    tokenBySymbol[_symbol] = _token;
    tokenByName[_name] = _token;

}
//..

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.