Skip to content

Commit

Permalink
Merge pull request #102 from OpenSTFoundation/jasonbanks/gh89/make-uu…
Browse files Browse the repository at this point in the history
…ids-iterable-uc

Make UUIDs iterable on utility chain
  • Loading branch information
benjaminbollen authored Feb 2, 2018
2 parents 8adbf90 + bcbd4f5 commit 1395b35
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 54 deletions.
77 changes: 32 additions & 45 deletions contracts/OpenSTUtility.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import "./ProtocolVersioned.sol";


/// @title OpenST Utility
contract OpenSTUtility is Hasher, OpsManaged {
contract OpenSTUtility is Hasher, OpsManaged, STPrimeConfig {
using SafeMath for uint256;

/*
Expand Down Expand Up @@ -93,11 +93,6 @@ contract OpenSTUtility is Hasher, OpsManaged {
/*
* Constants
*/
string public constant STPRIME_SYMBOL = "STP";
string public constant STPRIME_NAME = "SimpleTokenPrime";
uint256 public constant STPRIME_CONVERSION_RATE = 1;
uint8 public constant TOKEN_DECIMALS = 18;
uint256 public constant DECIMALSFACTOR = 10**uint256(TOKEN_DECIMALS);
// ~2 weeks, assuming ~15s per block
uint256 public constant BLOCKS_TO_WAIT_LONG = 80667;
// ~1hour, assuming ~15s per block
Expand All @@ -114,8 +109,9 @@ contract OpenSTUtility is Hasher, OpsManaged {
/// chainId of the current utility chain
uint256 public chainIdUtility;
address public registrar;
/// registered branded tokens
mapping(bytes32 /* uuid */ => RegisteredToken) internal registeredTokens;
bytes32[] public uuids;
/// registered branded tokens
mapping(bytes32 /* uuid */ => RegisteredToken) public registeredTokens;
/// name reservation is first come, first serve
mapping(bytes32 /* hashName */ => address /* requester */) public nameReservation;
/// symbol reserved for unique API routes
Expand Down Expand Up @@ -170,10 +166,11 @@ contract OpenSTUtility is Hasher, OpsManaged {
STPRIME_CONVERSION_RATE);

registeredTokens[uuidSTPrime] = RegisteredToken({
token: UtilityTokenInterface(simpleTokenPrime),
registrar: registrar
token: UtilityTokenInterface(simpleTokenPrime),
registrar: registrar
});

uuids.push(uuidSTPrime);
// lock name and symbol route for ST'
bytes32 hashName = keccak256(STPRIME_NAME);
nameReservation[hashName] = registrar;
Expand Down Expand Up @@ -480,23 +477,6 @@ contract OpenSTUtility is Hasher, OpsManaged {
return (uuid, redeemer, beneficiary, amountUT);
}

/*
* External view functions
*/
function registeredTokenProperties(
bytes32 _uuid)
external
view
returns (
address, /* token */
address /* registrar */)
{
RegisteredToken storage registeredToken = registeredTokens[_uuid];
return (
address(registeredToken.token),
registeredToken.registrar);
}

/*
* Public functions
*/
Expand Down Expand Up @@ -571,30 +551,36 @@ contract OpenSTUtility is Hasher, OpsManaged {
return false;
}

/// @dev Returns size of uuids
/// @return size
function getUuidsSize() public view returns (uint256) {
return uuids.length;
}

/*
* Registrar functions
*/
/// @dev for v0.9.1 tracking Ethereum mainnet on the utility chain
/// is not a required feature yet, so the core is simplified
/// to uint256 valueChainId as storage on construction
// function addCore(
// CoreInterface _core)
// public
// onlyRegistrar
// returns (bool /* success */)
// CoreInterface _core)
// public
// onlyRegistrar
// returns (bool /* success */)
// {
// require(address(_core) != address(0));
// // core constructed with same registrar
// require(registrar == _core.registrar());
// // on utility chain core only tracks a remote value chain
// uint256 coreChainIdValue = _core.chainIdRemote();
// require(chainIdUtility != 0);
// // cannot overwrite core for given chainId
// require(cores[coreChainIdValue] == address(0));

// cores[coreChainIdValue] = _core;

// return true;
// require(address(_core) != address(0));
// // core constructed with same registrar
// require(registrar == _core.registrar());
// // on utility chain core only tracks a remote value chain
// uint256 coreChainIdValue = _core.chainIdRemote();
// require(chainIdUtility != 0);
// // cannot overwrite core for given chainId
// require(cores[coreChainIdValue] == address(0));

// cores[coreChainIdValue] = _core;

// return true;
// }

/* solhint-disable-next-line separate-by-one-line-in-contract */
Expand Down Expand Up @@ -631,14 +617,15 @@ contract OpenSTUtility is Hasher, OpsManaged {
assert(address(registeredTokens[registeredUuid].token) == address(0));

registeredTokens[registeredUuid] = RegisteredToken({
token: _brandedToken,
registrar: registrar
token: _brandedToken,
registrar: registrar
});

// register name to registrar
nameReservation[hashName] = registrar;
// register symbol
symbolRoute[hashSymbol] = _brandedToken;
uuids.push(registeredUuid);

RegisteredBrandedToken(registrar, _brandedToken, registeredUuid, _symbol, _name,
_conversionRate, _requester);
Expand Down
4 changes: 2 additions & 2 deletions contracts/STPrime.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ contract STPrime is UtilityTokenAbstract, STPrimeConfig {
public
UtilityTokenAbstract(
_uuid,
TOKEN_SYMBOL,
TOKEN_NAME,
STPRIME_SYMBOL,
STPRIME_NAME,
_chainIdValue,
_chainIdUtility,
_conversionRate)
Expand Down
12 changes: 7 additions & 5 deletions contracts/STPrimeConfig.sol
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* solhint-disable-next-line compiler-fixed */
pragma solidity ^0.4.17;

// Copyright 2017 OpenST Ltd.
Expand All @@ -21,12 +22,13 @@ pragma solidity ^0.4.17;
//
// ----------------------------------------------------------------------------


/* solhint-disable-next-line two-lines-top-level-separator */
/// @title STPrimeConfig
contract STPrimeConfig {

string public constant TOKEN_SYMBOL = "STP";
string public constant TOKEN_NAME = "SimpleTokenPrime";
uint8 public constant TOKEN_DECIMALS = 18;
string public constant STPRIME_SYMBOL = "STP";
string public constant STPRIME_NAME = "SimpleTokenPrime";
uint256 public constant STPRIME_CONVERSION_RATE = 1;
uint8 public constant TOKEN_DECIMALS = 18;

uint256 public constant DECIMALSFACTOR = 10**uint256(TOKEN_DECIMALS);
uint256 public constant TOKENS_MAX = 800000000 * DECIMALSFACTOR;
Expand Down
3 changes: 3 additions & 0 deletions test/OpenSTUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ contract('OpenSTUtility', function(accounts) {
})

it('successfully registers', async () => {
assert.equal(await openSTUtility.getUuidsSize.call(), 1); // there is already 1 UUID in uuids for STPrime
assert.equal(await openSTUtility.registerBrandedToken.call(symbol, name, conversionRate, accounts[0], brandedToken, checkBtUuid, { from: registrar }), checkBtUuid);
result = await openSTUtility.registerBrandedToken(symbol, name, conversionRate, accounts[0], brandedToken, checkBtUuid, { from: registrar });
assert.equal(await openSTUtility.getUuidsSize.call(), 2);
assert.equal((await openSTUtility.registeredTokens.call(checkBtUuid))[0], brandedToken);
await OpenSTUtility_utils.checkRegisteredBrandedTokenEvent(result.logs[0], registrar, brandedToken, checkBtUuid, symbol, name, conversionRate, accounts[0]);
})
})
Expand Down
4 changes: 2 additions & 2 deletions test/STPrime_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module.exports.deploySTPrime = async (artifacts, accounts) => {
const conversionRate = 10;
const genesisChainIdValue = 3;
const genesisChainIdUtility = 1410;
const stPrimeSymbol = await stPrimeConfig.TOKEN_SYMBOL.call();
const stPrimeName = await stPrimeConfig.TOKEN_NAME.call();
const stPrimeSymbol = await stPrimeConfig.STPRIME_SYMBOL.call();
const stPrimeName = await stPrimeConfig.STPRIME_NAME.call();
const UUID = await hasher.hashUuid.call(stPrimeSymbol, stPrimeName, genesisChainIdValue, genesisChainIdUtility, openSTProtocol, conversionRate);

const stPrime = await STPrime.new(UUID, genesisChainIdValue, genesisChainIdUtility, conversionRate, { from: openSTProtocol });
Expand Down

0 comments on commit 1395b35

Please sign in to comment.