SHARE
TWEET

Untitled

a guest Dec 17th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. pragma solidity ^0.4.24;
  2.  
  3. import "./Owned.sol";
  4. import "./KMToken.sol";
  5.  
  6. contract BC is Owned {
  7.     mapping (address => bool) public admins;
  8.     string public name;
  9.     string public phone;
  10.     string public url;
  11.     string private did;
  12.     address private uPortAddress;
  13.     mapping (address => address[]) public tokens;
  14.    
  15.     event BCCreated(address companyAddress, string _companyName, string _phone, string _url);
  16.     event BCTokenAdded(address indexed tokenAdded);
  17.     event BCMsgSender(address indexed msgSender);
  18.  
  19.  
  20.     constructor(address _owner, string _companyName, string _phone, string _url, string _did, address _uPortAddress)
  21.         public
  22.     {
  23.         owner = _owner;  
  24.         emit BCMsgSender(msg.sender);
  25.         name = _companyName;
  26.         phone = _phone;
  27.         url = _url;
  28.         did = _did;
  29.         uPortAddress = _uPortAddress;
  30.         admins[owner] = true;
  31.         emit BCCreated(this, _companyName, _phone, _url);
  32.  
  33.     }
  34.     /*
  35.     function addToken(address token)
  36.         public
  37.         ownerOnly(msg.sender)
  38.     {
  39.         require (0 != token && !tokens[token], "Token already exists or is null.");
  40.         tokens[token] = true;
  41.         emit BCTokenAdded(token);
  42.     }
  43.    
  44.       function getToken(address token)
  45.         public
  46.         ownerOnly(msg.sender)
  47.         returns (KMToken)
  48.     {
  49.         require (0 != token && tokens[token], "Token not found.");
  50.         return KMToken(token);
  51.     }
  52.    
  53.     */
  54.  
  55. }
  56.  
  57.  
  58.  
  59.  
  60. contract BCFactory is Owned {
  61.     /* Copy of KMP storage to allow DELEGATECALL*/
  62.     uint8 constant MAX_OWNER_COMPANIES = 5; //1 owner could register up to 5 companies.
  63.     mapping (address => address[MAX_OWNER_COMPANIES]) public companies; // (owner => companies[5])  
  64.     BCFactory bcFactory;
  65.      //address private tokenFactory;
  66.     //mapping (address => BC) companies; I dont need to store anything in the factory, I need it in the KMPlatform
  67.     event BCFactoryMsgSender(address indexed msgSender);
  68.  
  69.     event BCFactoryCompanyCreated(address companyAddress, string _companyName, string _phone, string _url);
  70.  
  71.  
  72.     constructor(address deployer)
  73.         public
  74.     {
  75.         owner = deployer;
  76.     }
  77.    
  78.    
  79.     function createBCCompany( string _companyName, string _phone, string _url, string _did, address _uPortAddress)
  80.         public
  81.        // ownerOnly(msg.sender) // I won't control WHO because I want anybody to create companies.
  82.         returns (BC)
  83.     {
  84.         emit BCFactoryMsgSender(msg.sender);
  85.         uint8 position = companyPosition(msg.sender);
  86.         require(MAX_OWNER_COMPANIES == position, "You can't create a new company. Max limit reached (5 companies).");
  87.         BC newCompany = new BC(msg.sender, _companyName, _phone, _url, _did, _uPortAddress);
  88.         companies[msg.sender][position] = newCompany;
  89.         emit BCFactoryCompanyCreated(newCompany, _companyName, _phone, _url);
  90.         return newCompany;
  91.     }
  92.    
  93.    
  94.     function createToken(string _name, string _symbol, uint256 _initialAmount)
  95.         public
  96.         ownerOnly(owner)
  97.     {
  98.         KMToken newToken = new KMToken(_name,  _symbol, _initialAmount); //lo crea BCFactory!! No msg.sender?
  99.  
  100.     }
  101.    
  102.     function companyPosition(address _owner)
  103.         internal
  104.         view
  105.         returns (uint8)
  106.     {
  107.         address anOwner = _owner; // Check if msg.sender gets here or if I need param.
  108.         address[MAX_OWNER_COMPANIES] memory ownersCompanies = companies[anOwner];
  109.         for (uint8 i = 0; i < MAX_OWNER_COMPANIES; i++) {
  110.             if (ownersCompanies[i] == 0){
  111.                 return i; // There is an empty spot available.
  112.             }
  113.         }
  114.        return MAX_OWNER_COMPANIES; // No empty spot available.
  115.     }
  116.  
  117. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top