Created
January 23, 2017 13:39
-
-
Save anonymous/9e1a26f067c6d9e3f89f9e8f804c003e to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.7+commit.822622cf.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.8; | |
/* | |
* Company | |
* | |
* Common Company contract that store user information and documents | |
*/ | |
contract Company { | |
address public index; | |
string public name; | |
string public taxId; | |
string public directors; | |
string public employees; | |
string public revenue; | |
string public earnings; | |
string public electricityConsumption; | |
string public waterConsumption; | |
string public legalAddress; | |
string public contact; | |
string public key; | |
Document[] public documents; | |
address public owner; | |
modifier onlyOwner() { | |
if (tx.origin == owner) _; | |
} | |
modifier fromIndex() { | |
if (msg.sender == index) _; | |
} | |
struct Document { | |
string name; | |
string docType; | |
address swarm; | |
uint status; | |
string statusText; | |
mapping(address => bool) access; | |
} | |
function Company(string _name, string _taxId, string _directors, string _employees, string _revenue, string _earnings, string _electricityConsumption, string _waterConsumption, string _contact, string _legalAddress, string _key) { | |
owner = tx.origin; | |
index = msg.sender; | |
name = _name; | |
taxId = _taxId; | |
directors = _directors; | |
employees = _employees; | |
revenue = _revenue; | |
earnings = _earnings; | |
electricityConsumption = _electricityConsumption; | |
waterConsumption = _waterConsumption; | |
legalAddress = _legalAddress; | |
contact = _contact; | |
} | |
function edit(string _name, string _taxId, string _directors, string _employees, string _revenue, string _earnings, string _electricityConsumption, string _waterConsumption, string _contact, string _legalAddress) fromIndex() returns (bool success) { | |
name = _name; | |
taxId = _taxId; | |
directors = _directors; | |
employees = _employees; | |
revenue = _revenue; | |
earnings = _earnings; | |
electricityConsumption = _electricityConsumption; | |
waterConsumption = _waterConsumption; | |
legalAddress = _legalAddress; | |
contact = _contact; | |
return true; | |
} | |
function addDoc(string _name, string _docType, address _swarm, string _text) fromIndex() { | |
documents.push(Document(_name, _docType, _swarm, 0, _text)); | |
documents[documents.length].access[msg.sender] = true; | |
} | |
function changeAccessDoc(uint _posDoc, address _addr, bool _access) fromIndex() { | |
documents[_posDoc].access[_addr] = _access; | |
} | |
function changeStatusDoc(bool onCompany, uint _posDoc, uint _status, string _statusText) fromIndex() returns (bool success) { | |
if (documents[_posDoc].access[msg.sender] == true) { | |
documents[_posDoc].status = _status; | |
documents[_posDoc].statusText = _statusText; | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function transferOwnership(address newOwner) onlyOwner() fromIndex() { | |
if (newOwner != address(0)) owner = newOwner; | |
} | |
function getDocsLength() constant returns (uint) { | |
return documents.length; | |
} | |
function getOwner() public constant returns (address) { | |
return owner; | |
} | |
function getCompany() public constant returns (string name, string taxId, string directors, string employees, string legalAddress, string contact) { | |
return (name, taxId, directors, employees, legalAddress, contact); | |
} | |
function getCompanyFinance() public constant returns (string revenue, string earnings, string electricityConsumption, string waterConsumption) { | |
return (revenue, earnings, electricityConsumption, waterConsumption); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.8; | |
import "User.sol"; | |
import "Company.sol"; | |
/* | |
* IndexRegistry | |
* | |
* Registry of all users public info and their addresses. | |
*/ | |
contract IndexRegistry { | |
User[] users; | |
Company[] companies; | |
mapping(address => uint) usersAddresses; | |
mapping(address => uint) companyAddresses; | |
mapping(string => uint) usersEmails; | |
mapping(string => uint) companyNames; | |
modifier fromUser(uint _pos) { | |
address _owner = users[_pos].getOwner(); | |
if (_owner == msg.sender) _; | |
} | |
modifier onlyUsers() { | |
if (usersAddresses[msg.sender] > 0) _; | |
} | |
modifier fromCompany(uint _pos) { | |
address _owner = companies[_pos].getOwner(); | |
if (_owner == msg.sender) _; | |
} | |
modifier onlyCompanies() { | |
if (companyAddresses[msg.sender] > 0) _; | |
} | |
modifier notRegistered() { | |
if ((usersAddresses[msg.sender] == 0) && (companyAddresses[msg.sender] == 0)) _; | |
} | |
function UsersRegistry() { | |
users.length ++; | |
companies.length ++; | |
} | |
function registerUser(string _name, string _surename, string _email, string _key) notRegistered() returns (bool success) { | |
User newUser = new User(_name, _surename, _email, "", "", "", "", _key); | |
users.push(newUser); | |
usersAddresses[msg.sender] = users.length; | |
usersEmails[_email] = users.length; | |
return true; | |
} | |
function removeUser(uint _pos, string _email) fromUser(_pos) returns (bool success) { | |
if (usersEmails[_email] != usersAddresses[msg.sender]) throw; | |
delete usersEmails[_email]; | |
delete users[_pos]; | |
delete usersAddresses[msg.sender]; | |
return true; | |
} | |
function callUser(uint _pos) fromUser(_pos) returns (bool success) { | |
if (users[_pos].call(msg.data)) | |
return true; | |
else | |
return false; | |
} | |
function callCompany(uint _pos) fromCompany(_pos) returns (bool success) { | |
if (companies[_pos].call(msg.data)) | |
return true; | |
else | |
return false; | |
} | |
function registerCompany(string _name, string _taxId, string _key) notRegistered() returns (bool success) { | |
Company newCompany = new Company(_name, _taxId, "", "", "", "", "", "", "", "", _key); | |
companies.push(newCompany); | |
companyAddresses[msg.sender] = companies.length; | |
companyNames[_name] = companies.length; | |
return true; | |
} | |
function removeCompany(uint _pos, string _name) fromCompany(_pos) returns (bool success) { | |
if (companyNames[_name] != companyAddresses[msg.sender]) throw; | |
delete companyNames[_name]; | |
delete companies[_pos]; | |
delete companyAddresses[msg.sender]; | |
return true; | |
} | |
function getUserByEmail(string _email) onlyUsers() returns (uint _pos) { | |
return (usersEmails[_email]); | |
} | |
function getCompanyByName(string _name) onlyCompanies() returns (uint _pos) { | |
return (companyNames[_name]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* User | |
* | |
* Common user contract that store user information and documents | |
*/ | |
contract User { | |
address public index; | |
string public name; | |
string public surename; | |
string public email; | |
string public id; | |
string public idType; | |
string public legalAddress; | |
string public country; | |
string public key; | |
Document[] public documents; | |
address public owner; | |
modifier onlyOwner() { | |
if (tx.origin == owner) _; | |
} | |
modifier fromIndex() { | |
if (msg.sender == index) _; | |
} | |
struct Document { | |
string name; | |
string docType; | |
address swarm; | |
uint status; | |
string statusText; | |
mapping(address => bool) access; | |
} | |
function User(string _name, string _surename, string _email, string _id, string _idType, string _legalAddress, string _country, string _key) { | |
owner = tx.origin; | |
index = msg.sender; | |
name = _name; | |
surename = _surename; | |
email = _email; | |
id = _id; | |
idType = _idType; | |
legalAddress = _legalAddress; | |
country = _country; | |
key = _key; | |
} | |
function edit(uint _pos, string _name, string _surename, string _email, string _id, string _idType, string _legalAddress, string _country) fromIndex() returns (bool success) { | |
name = _name; | |
surename = _surename; | |
email = _email; | |
id = _id; | |
idType = _idType; | |
legalAddress = _legalAddress; | |
country = _country; | |
return true; | |
} | |
function addDoc(string _name, string _docType, address _swarm, string _text) fromIndex() { | |
documents.push(Document(_name, _docType, _swarm, 0, _text)); | |
documents[documents.length].access[msg.sender] = true; | |
} | |
function changeAccessDoc(uint _posDoc, address _addr, bool _access) fromIndex() { | |
documents[_posDoc].access[_addr] = _access; | |
} | |
function changeStatusDoc(bool onCompany, uint _posDoc, uint _status, string _statusText) fromIndex() returns (bool success) { | |
if (documents[_posDoc].access[msg.sender] == true) { | |
documents[_posDoc].status = _status; | |
documents[_posDoc].statusText = _statusText; | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function transferOwnership(address newOwner) onlyOwner() fromIndex() { | |
if (newOwner != address(0)) owner = newOwner; | |
} | |
function getDocsLength() constant returns (uint) { | |
return documents.length; | |
} | |
function getOwner() public constant returns (address) { | |
return owner; | |
} | |
function getUser() public constant returns (string name, string surename, string id, string idType, string email, string legalAddress, string country) { | |
return (name, surename, id, idType, email, legalAddress, country); | |
} | |
} | |
/* | |
* Company | |
* | |
* Common Company contract that store user information and documents | |
*/ | |
contract Company { | |
address public index; | |
string public name; | |
string public taxId; | |
string public directors; | |
string public employees; | |
string public revenue; | |
string public earnings; | |
string public electricityConsumption; | |
string public waterConsumption; | |
string public legalAddress; | |
string public contact; | |
string public key; | |
Document[] public documents; | |
address public owner; | |
modifier onlyOwner() { | |
if (tx.origin == owner) _; | |
} | |
modifier fromIndex() { | |
if (msg.sender == index) _; | |
} | |
struct Document { | |
string name; | |
string docType; | |
address swarm; | |
uint status; | |
string statusText; | |
mapping(address => bool) access; | |
} | |
function Company(string _name, string _taxId, string _directors, string _employees, string _revenue, string _earnings, string _electricityConsumption, string _waterConsumption, string _contact, string _legalAddress, string _key) { | |
owner = tx.origin; | |
index = msg.sender; | |
name = _name; | |
taxId = _taxId; | |
directors = _directors; | |
employees = _employees; | |
revenue = _revenue; | |
earnings = _earnings; | |
electricityConsumption = _electricityConsumption; | |
waterConsumption = _waterConsumption; | |
legalAddress = _legalAddress; | |
contact = _contact; | |
} | |
function edit(string _name, string _taxId, string _directors, string _employees, string _revenue, string _earnings, string _electricityConsumption, string _waterConsumption, string _contact, string _legalAddress) fromIndex() returns (bool success) { | |
name = _name; | |
taxId = _taxId; | |
directors = _directors; | |
employees = _employees; | |
revenue = _revenue; | |
earnings = _earnings; | |
electricityConsumption = _electricityConsumption; | |
waterConsumption = _waterConsumption; | |
legalAddress = _legalAddress; | |
contact = _contact; | |
return true; | |
} | |
function addDoc(string _name, string _docType, address _swarm, string _text) fromIndex() { | |
documents.push(Document(_name, _docType, _swarm, 0, _text)); | |
documents[documents.length].access[msg.sender] = true; | |
} | |
function changeAccessDoc(uint _posDoc, address _addr, bool _access) fromIndex() { | |
documents[_posDoc].access[_addr] = _access; | |
} | |
function changeStatusDoc(bool onCompany, uint _posDoc, uint _status, string _statusText) fromIndex() returns (bool success) { | |
if (documents[_posDoc].access[msg.sender] == true) { | |
documents[_posDoc].status = _status; | |
documents[_posDoc].statusText = _statusText; | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function transferOwnership(address newOwner) onlyOwner() fromIndex() { | |
if (newOwner != address(0)) owner = newOwner; | |
} | |
function getDocsLength() constant returns (uint) { | |
return documents.length; | |
} | |
function getOwner() public constant returns (address) { | |
return owner; | |
} | |
function getCompany() public constant returns (string name, string taxId, string directors, string employees, string legalAddress, string contact) { | |
return (name, taxId, directors, employees, legalAddress, contact); | |
} | |
function getCompanyFinance() public constant returns (string revenue, string earnings, string electricityConsumption, string waterConsumption) { | |
return (revenue, earnings, electricityConsumption, waterConsumption); | |
} | |
} | |
/* | |
* IndexRegistry | |
* | |
* Registry of all users public info and their addresses. | |
*/ | |
contract IndexRegistry { | |
User[] users; | |
Company[] companies; | |
mapping(address => uint) usersAddresses; | |
mapping(address => uint) companyAddresses; | |
mapping(string => uint) usersEmails; | |
mapping(string => uint) companyNames; | |
modifier fromUser(uint _pos) { | |
address _owner = users[_pos].getOwner(); | |
if (_owner == msg.sender) _; | |
} | |
modifier onlyUsers() { | |
if (usersAddresses[msg.sender] > 0) _; | |
} | |
modifier fromCompany(uint _pos) { | |
address _owner = companies[_pos].getOwner(); | |
if (_owner == msg.sender) _; | |
} | |
modifier onlyCompanies() { | |
if (companyAddresses[msg.sender] > 0) _; | |
} | |
modifier notRegistered() { | |
if ((usersAddresses[msg.sender] == 0) && (companyAddresses[msg.sender] == 0)) _; | |
} | |
function UsersRegistry() { | |
users.length ++; | |
companies.length ++; | |
} | |
function registerUser(string _name, string _surename, string _email, string _key) notRegistered() returns (bool success) { | |
User newUser = new User(_name, _surename, _email, "", "", "", "", _key); | |
users.push(newUser); | |
usersAddresses[msg.sender] = users.length; | |
usersEmails[_email] = users.length; | |
return true; | |
} | |
function removeUser(uint _pos, string _email) fromUser(_pos) returns (bool success) { | |
if (usersEmails[_email] != usersAddresses[msg.sender]) throw; | |
delete usersEmails[_email]; | |
delete users[_pos]; | |
delete usersAddresses[msg.sender]; | |
return true; | |
} | |
function callUser(uint _pos) fromUser(_pos) returns (bool success) { | |
if (users[_pos].call(msg.data)) | |
return true; | |
else | |
return false; | |
} | |
function callCompany(uint _pos) fromCompany(_pos) returns (bool success) { | |
if (companies[_pos].call(msg.data)) | |
return true; | |
else | |
return false; | |
} | |
function registerCompany(string _name, string _taxId, string _key) notRegistered() returns (bool success) { | |
Company newCompany = new Company(_name, _taxId, "", "", "", "", "", "", "", "", _key); | |
companies.push(newCompany); | |
companyAddresses[msg.sender] = companies.length; | |
companyNames[_name] = companies.length; | |
return true; | |
} | |
function removeCompany(uint _pos, string _name) fromCompany(_pos) returns (bool success) { | |
if (companyNames[_name] != companyAddresses[msg.sender]) throw; | |
delete companyNames[_name]; | |
delete companies[_pos]; | |
delete companyAddresses[msg.sender]; | |
return true; | |
} | |
function getUserByEmail(string _email) onlyUsers() returns (uint _pos) { | |
return (usersEmails[_email]); | |
} | |
function getCompanyByName(string _name) onlyCompanies() returns (uint _pos) { | |
return (companyNames[_name]); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.8; | |
/* | |
* User | |
* | |
* Common user contract that store user information and documents | |
*/ | |
contract User { | |
address public index; | |
string public name; | |
string public surename; | |
string public email; | |
string public id; | |
string public idType; | |
string public legalAddress; | |
string public country; | |
string public key; | |
Document[] public documents; | |
address public owner; | |
modifier onlyOwner() { | |
if (tx.origin == owner) _; | |
} | |
modifier fromIndex() { | |
if (msg.sender == index) _; | |
} | |
struct Document { | |
string name; | |
string docType; | |
address swarm; | |
uint status; | |
string statusText; | |
mapping(address => bool) access; | |
} | |
function User(string _name, string _surename, string _email, string _id, string _idType, string _legalAddress, string _country, string _key) { | |
owner = tx.origin; | |
index = msg.sender; | |
name = _name; | |
surename = _surename; | |
email = _email; | |
id = _id; | |
idType = _idType; | |
legalAddress = _legalAddress; | |
country = _country; | |
key = _key; | |
} | |
function edit(uint _pos, string _name, string _surename, string _email, string _id, string _idType, string _legalAddress, string _country) fromIndex() returns (bool success) { | |
name = _name; | |
surename = _surename; | |
email = _email; | |
id = _id; | |
idType = _idType; | |
legalAddress = _legalAddress; | |
country = _country; | |
return true; | |
} | |
function addDoc(string _name, string _docType, address _swarm, string _text) fromIndex() { | |
documents.push(Document(_name, _docType, _swarm, 0, _text)); | |
documents[documents.length].access[msg.sender] = true; | |
} | |
function changeAccessDoc(uint _posDoc, address _addr, bool _access) fromIndex() { | |
documents[_posDoc].access[_addr] = _access; | |
} | |
function changeStatusDoc(bool onCompany, uint _posDoc, uint _status, string _statusText) fromIndex() returns (bool success) { | |
if (documents[_posDoc].access[msg.sender] == true) { | |
documents[_posDoc].status = _status; | |
documents[_posDoc].statusText = _statusText; | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function transferOwnership(address newOwner) onlyOwner() fromIndex() { | |
if (newOwner != address(0)) owner = newOwner; | |
} | |
function getDocsLength() constant returns (uint) { | |
return documents.length; | |
} | |
function getOwner() public constant returns (address) { | |
return owner; | |
} | |
function getUser() public constant returns (string name, string surename, string id, string idType, string email, string legalAddress, string country) { | |
return (name, surename, id, idType, email, legalAddress, country); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment