Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity 0.4.18;
- import "./contract/Owned.sol";
- import "./RocketUser.sol";
- import "./RocketStorage.sol";
- /// @title Examples of how to store and read a contract address in your dApps eternal storage for use in the hub / spoke pattern
- /// @author David Rugendyke
- contract RocketStorageExamples is Owned {
- /*** Contracts **************/
- RocketStorage rocketStorage = RocketStorage(0); // The main RocketStorage contract where primary persistant storage is maintained
- RocketUser rocketUser = RocketUser(0); // The contract that contains the user methods in Rocket Pool
- /*** Constructor ***********/
- /// @dev RocketStorageExamples constructor
- function RocketStorageExamples(address _rocketStorageAddress) public {
- // Update the storage contracts address when this contract is deployed so that it knows the location of the storage contract
- rocketStorage = RocketStorage(_rocketStorageAddress);
- }
- /**** Add a contract to the dApp storage/hub ***********/
- // An example of a method that could be used to add a contract to the dApps eternal storage/hub
- function addContract(string _name, address _newContractAddress) onlyOwner external {
- // Add the contract to the storage using a hash of the "contract.name" namespace and the name of the contract that was supplied as the 'key' and use the new contract address as the 'value'
- // This means we can get the address of the contract later by looking it up using its name eg 'rocketUser'
- rocketStorage.setAddress(keccak256("contract.name", _name), _newContractAddress);
- // Add the contract to the storage using a hash of the "contract.address" namespace and the address of the contract that was supplied as the 'key' and use the new contract address as the 'value'
- // This means we can verify this contract as belonging to the dApp by using it's address rather than its name.
- // Handy when you need to protect certain methods from being accessed by any contracts that are not part of the dApp using msg.sender (see the modifier onlyLatestRocketNetworkContract() in the RocketStorage code)
- rocketStorage.setAddress(keccak256("contract.address", _newContractAddress), _newContractAddress);
- }
- // An example of a method that asks the hub for the address of another contract in the dApp before communicating directly with that contract, ensures it gets the most up to date contract address
- function getUserExists(string _name) onlyOwner external returns (bool) {
- // Get the address of the user contract so that we can check if a user with this name exists, it was registered with the name 'rocketUser'
- rocketUser = RocketUser(rocketStorage.getAddress(keccak256("contract.name", "rocketUser")));
- // Now we have an instance of that contract using its most up to date address supplied by the hub, check if the user exists
- if (rocketUser.exists(_name)) {
- // User exists
- return true;
- }
- // Use does not exist
- return false;
- }
- }
Add Comment
Please, Sign In to add comment