Skip to content

Commit

Permalink
fix #34 #32
Browse files Browse the repository at this point in the history
  • Loading branch information
SatyamSB committed Mar 26, 2018
1 parent b7560e8 commit fe6614b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 23 deletions.
26 changes: 20 additions & 6 deletions contracts/SecurityTokenRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import './tokens/SecurityToken.sol';
import './interfaces/ISTProxy.sol';
import './interfaces/ISecurityTokenRegistry.sol';
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
import './helpers/Util.sol';

contract SecurityTokenRegistry is Ownable, ISecurityTokenRegistry {
contract SecurityTokenRegistry is Ownable, ISecurityTokenRegistry, Util {

event LogNewSecurityToken(string _ticker, address _securityTokenAddress, address _owner);

Expand All @@ -32,18 +33,18 @@ contract SecurityTokenRegistry is Ownable, ISecurityTokenRegistry {
function generateSecurityToken(string _name, string _symbol, uint8 _decimals, bytes32 _tokenDetails) public {
require(bytes(_name).length > 0 && bytes(_symbol).length > 0);
require(ITickerRegistry(tickerRegistry).checkValidity(_symbol, msg.sender, _name));

string memory symbol = lower(_symbol);
address newSecurityTokenAddress = ISTProxy(protocolVersionST[protocolVersion]).deployToken(
_name,
_symbol,
symbol,
_decimals,
_tokenDetails,
msg.sender
);

securityTokens[newSecurityTokenAddress] = SecurityTokenData(_symbol, msg.sender, _tokenDetails);
symbols[_symbol] = newSecurityTokenAddress;
LogNewSecurityToken(_symbol, newSecurityTokenAddress, msg.sender);
securityTokens[newSecurityTokenAddress] = SecurityTokenData(symbol, _tokenDetails);
symbols[symbol] = newSecurityTokenAddress;
LogNewSecurityToken(symbol, newSecurityTokenAddress, msg.sender);
}

function setProtocolVersion(address _stVersionProxyAddress, bytes32 _version) public onlyOwner {
Expand All @@ -62,4 +63,17 @@ contract SecurityTokenRegistry is Ownable, ISecurityTokenRegistry {
function getSecurityTokenAddress(string _symbol) public view returns (address) {
return symbols[_symbol];
}

/**
* @dev Get security token data by its address
* @param _securityToken Address of the Scurity token
* @return string, address, bytes32
*/
function getSecurityTokenData(address _securityToken) public view returns (string, address, bytes32) {
return (
securityTokens[_securityToken].symbol,
ISecurityToken(_securityToken).owner(),
securityTokens[_securityToken].tokenDetails
);
}
}
35 changes: 20 additions & 15 deletions contracts/TickerRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ pragma solidity ^0.4.18;
*/

import 'zeppelin-solidity/contracts/math/SafeMath.sol';
import './interfaces/ITickerRegistry.sol';
import 'zeppelin-solidity/contracts/ownership/Ownable.sol';
import './interfaces/ITickerRegistry.sol';
import './helpers/Util.sol';
/**
* @title TickerRegistry
* @dev Contract use to register the security token symbols
*/
contract TickerRegistry is ITickerRegistry, Ownable {
contract TickerRegistry is ITickerRegistry, Ownable, Util {

using SafeMath for uint256;
// constant variable to check the validity to use the symbol
Expand Down Expand Up @@ -53,9 +54,10 @@ contract TickerRegistry is ITickerRegistry, Ownable {
* @param _tokenName Name of the token
*/
function registerTicker(string _symbol, string _tokenName) public {
require(expiryCheck(_symbol));
registeredSymbols[_symbol] = SymbolDetails(msg.sender, now, _tokenName, false);
LogRegisterTicker(msg.sender, _symbol, _tokenName, now);
string memory symbol = lower(_symbol);
require(expiryCheck(symbol));
registeredSymbols[symbol] = SymbolDetails(msg.sender, now, _tokenName, false);
LogRegisterTicker(msg.sender, symbol, _tokenName, now);
}

/**
Expand Down Expand Up @@ -103,27 +105,30 @@ contract TickerRegistry is ITickerRegistry, Ownable {
* @return bool
*/
function checkValidity(string _symbol, address _owner, string _tokenName) public returns(bool) {
string memory symbol = lower(_symbol);
require(msg.sender == STRAddress);
require(registeredSymbols[_symbol].status != true);
require(registeredSymbols[_symbol].owner == _owner);
require(registeredSymbols[_symbol].timestamp.add(expiryLimit) >= now);
registeredSymbols[_symbol].tokenName = _tokenName;
registeredSymbols[_symbol].status = true;
require(registeredSymbols[symbol].status != true);
require(registeredSymbols[symbol].owner == _owner);
require(registeredSymbols[symbol].timestamp.add(expiryLimit) >= now);
registeredSymbols[symbol].tokenName = _tokenName;
registeredSymbols[symbol].status = true;
return true;
}


/**
* @dev Returns the owner and timestamp for a given symbol
* @param _symbol symbol
*/
function getDetails(string _symbol) public view returns (address, uint256, string, bool) {
if (registeredSymbols[_symbol].status == true || registeredSymbols[_symbol].timestamp.add(expiryLimit) > now ) {
string memory symbol = lower(_symbol);
if (registeredSymbols[symbol].status == true || registeredSymbols[symbol].timestamp.add(expiryLimit) > now ) {
return
(
registeredSymbols[_symbol].owner,
registeredSymbols[_symbol].timestamp,
registeredSymbols[_symbol].tokenName,
registeredSymbols[_symbol].status
registeredSymbols[symbol].owner,
registeredSymbols[symbol].timestamp,
registeredSymbols[symbol].tokenName,
registeredSymbols[symbol].status
);
}
else
Expand Down
21 changes: 21 additions & 0 deletions contracts/helpers/Util.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pragma solidity ^0.4.18;

contract Util {

/**
* @dev changes a string to lower case
* @param _base string to change
*/
function lower(string _base) internal pure returns (string) {
bytes memory _baseBytes = bytes(_base);
for (uint i = 0; i < _baseBytes.length; i++) {
bytes1 b1 = _baseBytes[i];
if (b1 >= 0x41 && b1 <= 0x5A) {
b1 = bytes1(uint8(b1)+32);
}
_baseBytes[i] = b1;
}
return string(_baseBytes);
}

}
12 changes: 10 additions & 2 deletions contracts/interfaces/ISecurityTokenRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
pragma solidity ^0.4.18;

import './ISecurityToken.sol';

contract ISecurityTokenRegistry {

address public polyAddress;
Expand All @@ -12,11 +14,10 @@ contract ISecurityTokenRegistry {

struct SecurityTokenData {
string symbol;
address owner;
bytes32 tokenDetails;
}

mapping(address => SecurityTokenData) public securityTokens;
mapping(address => SecurityTokenData) securityTokens;
mapping(string => address) symbols;

/**
Expand All @@ -39,4 +40,11 @@ contract ISecurityTokenRegistry {
* @return address _symbol
*/
function getSecurityTokenAddress(string _symbol) public view returns (address);

/**
* @dev Get security token data by its address
* @param _securityToken Address of the Scurity token
* @return string, address, bytes32
*/
function getSecurityTokenData(address _securityToken) public view returns (string, address, bytes32);
}

0 comments on commit fe6614b

Please sign in to comment.