Skip to content

Commit

Permalink
Naming: "subsidiary" => "unit" (WARNING! BREAKING CHANGE!)
Browse files Browse the repository at this point in the history
  • Loading branch information
kvakes committed Jun 7, 2020
1 parent 5c17de8 commit f8c7434
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 65 deletions.
40 changes: 20 additions & 20 deletions contracts/OrgId.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract OrgId is OrgIdInterface, Ownable, ERC165, Initializable {
address director;
bool isActive;
bool directorConfirmed;
bytes32[] subsidiaries;
bytes32[] units;
}

/// @dev Mapped list of Organizations
Expand All @@ -44,9 +44,9 @@ contract OrgId is OrgIdInterface, Ownable, ERC165, Initializable {
/**
* @dev Emits when new organizational unit created
*/
event SubsidiaryCreated(
event UnitCreated(
bytes32 indexed parentOrgId,
bytes32 indexed subOrgId,
bytes32 indexed unitOrgId,
address indexed director
);

Expand Down Expand Up @@ -177,7 +177,7 @@ contract OrgId is OrgIdInterface, Ownable, ERC165, Initializable {
* @param orgJsonUri Unit ORG.JSON URI
* @param orgJsonHash ORG.JSON keccak256 hash
*/
function createSubsidiary(
function createUnit(
bytes32 parentOrgId,
address director,
string calldata orgJsonUri,
Expand All @@ -194,7 +194,7 @@ contract OrgId is OrgIdInterface, Ownable, ERC165, Initializable {
orgJsonUri,
orgJsonHash
);
emit SubsidiaryCreated(parentOrgId, newUnitOrgId, director);
emit UnitCreated(parentOrgId, newUnitOrgId, director);

// If parent ORG.ID owner indicates their address as director,
// their directorship is automatically confirmed
Expand Down Expand Up @@ -372,18 +372,18 @@ contract OrgId is OrgIdInterface, Ownable, ERC165, Initializable {

/**
* @dev Get all active organizational units of a particular ORG.ID
* @param orgId Parent ORG.ID hash
* @param parentOrgId Parent ORG.ID hash
* @return {
"organizationsList": "Array of ORG.ID hashes of active organizational units"
}
*/
function getSubsidiaries(bytes32 orgId)
function getUnits(bytes32 parentOrgId)
external
view
orgIdMustExist(orgId)
orgIdMustExist(parentOrgId)
returns (bytes32[] memory)
{
return _getOrganizations(orgId);
return _getOrganizations(parentOrgId);
}

/**
Expand Down Expand Up @@ -462,10 +462,10 @@ contract OrgId is OrgIdInterface, Ownable, ERC165, Initializable {
org.getOrganization.selector,

// hierarchy interface: 0x3a3bc250
org.createSubsidiary.selector ^
org.createUnit.selector ^
org.confirmDirectorOwnership.selector ^
org.transferDirectorOwnership.selector ^
org.getSubsidiaries.selector
org.getUnits.selector
];
for (uint256 i = 0; i < interfaceIds.length; i++) {
_registerInterface(interfaceIds[i]);
Expand All @@ -475,16 +475,16 @@ contract OrgId is OrgIdInterface, Ownable, ERC165, Initializable {
/**
* @dev Create new organization and add it to storage
* @param orgJsonUri ORG.JSON URI
* @param orgJsonHash ORG.JSON's keccak256 hash
* @param orgJsonHash ORG.JSON keccak256 hash
* @param parentOrgId Parent ORG.ID hash (if applicable)
* @param subsidiaryDirector Unit director's address (if applicable)
* @param director Unit director address (if applicable)
* @return {
"ORG.ID": "New ORG.ID hash"
}
*/
function _createOrganization(
bytes32 parentOrgId,
address subsidiaryDirector,
address director,
string memory orgJsonUri,
bytes32 orgJsonHash
) internal returns (bytes32) {
Expand All @@ -504,7 +504,7 @@ contract OrgId is OrgIdInterface, Ownable, ERC165, Initializable {
);

require(
subsidiaryDirector != address(0),
director != address(0),
"ORG.ID: Invalid director address"
);
}
Expand All @@ -515,15 +515,15 @@ contract OrgId is OrgIdInterface, Ownable, ERC165, Initializable {
orgJsonHash,
parentOrgId,
msg.sender,
subsidiaryDirector,
director,
true,
subsidiaryDirector == msg.sender,
director == msg.sender,
new bytes32[](0)
);
orgIds.push(orgId);

if (parentOrgId != bytes32(0)) {
organizations[parentOrgId].subsidiaries.push(orgId);
organizations[parentOrgId].units.push(orgId);
}

return orgId;
Expand All @@ -545,7 +545,7 @@ contract OrgId is OrgIdInterface, Ownable, ERC165, Initializable {
bytes32[] memory source =
orgId == bytes32(0)
? orgIds
: organizations[orgId].subsidiaries;
: organizations[orgId].director;
organizationsList = new bytes32[](_getOrganizationsCount(orgId));
uint256 index;

Expand Down Expand Up @@ -583,7 +583,7 @@ contract OrgId is OrgIdInterface, Ownable, ERC165, Initializable {
bytes32[] memory source =
orgId == bytes32(0)
? orgIds
: organizations[orgId].subsidiaries;
: organizations[orgId].director;

for (uint256 i = 0; i < source.length; i++) {
if (organizations[source[i]].isActive &&
Expand Down
6 changes: 3 additions & 3 deletions contracts/OrgIdInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contract OrgIdInterface {
* @param orgJsonUri Unit ORG.JSON URI
* @param orgJsonHash ORG.JSON keccak256 hash
*/
function createSubsidiary(
function createUnit(
bytes32 parentOrgId,
address director,
string calldata orgJsonUri,
Expand Down Expand Up @@ -119,12 +119,12 @@ contract OrgIdInterface {

/**
* @dev Get all active organizational units of a particular ORG.ID
* @param orgId Parent ORG.ID hash
* @param parentOrgId Parent ORG.ID hash
* @return {
"organizationsList": "Array of ORG.ID hashes of active organizational units"
}
*/
function getSubsidiaries(bytes32 orgId)
function getUnits(bytes32 parentOrgId)
external
view
returns (bytes32[] memory);
Expand Down
33 changes: 15 additions & 18 deletions scripts/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ Usage: `cmd=makehash <PROPERTIES>`

Generates a hash of the given json file using keccak method from solidity. This hash should be used as ORG.ID JSON validation parameter.

Parameters:
Parameters:
- `file=<PATH_TO_JSON>`
Relative path to the ORG.ID json file.
Relative path to the ORG.ID json file.

## deploy

Usage: `cmd=deploy <PROPERTIES>`

Manages contracts deployments.

Parameters:
Parameters:
- `name=<CONTRACT_NAME>`
Contract name to deploy or upgrade

- `from=<SENDER_ACCOUNT_ADDRESS>`
Account address that should be used to signing transactions

Expand Down Expand Up @@ -85,15 +85,15 @@ Usage: `cmd=upgrade <PROPERTIES>`

Manages contracts upgrades.

Parameters:
Parameters:
- `name=<CONTRACT_NAME>`
Contract name to deploy or upgrade

- `from=<SENDER_ACCOUNT_ADDRESS>`
Account address that should be used to signing transactions

- `initMethod=<INITIALIZER_METHOD_NAME>`
Name of the contract initializer method name. Optional.
Name of the contract initializer method name. Optional.

- `initArgs=<INITIALIZER_ARGUMENTS>`
Initializer arguments separated by comma. Optional.
Expand All @@ -102,12 +102,12 @@ Parameters:

Usage: `cmd=tx <PROPERTIES>`

Sending transactions to the contract instances.
Sending transactions to the contract instances.

Properties:
- `name=<CONTRACT_NAME>`
Contract name to transaction sending

- `from=<SENDER_ACCOUNT_ADDRESS>`
Account address that should be used to signing transactions

Expand All @@ -124,12 +124,12 @@ Properties:

Usage: `cmd=call <PROPERTIES>`

Sending transactions to the contract instances.
Sending transactions to the contract instances.

Properties:
- `name=<CONTRACT_NAME>`
Contract name

- `address=<CONTRACT_PROXY_ADDRESS>`
Address of the deployed contract (proxy) on the network

Expand All @@ -147,7 +147,7 @@ Running the series of predefined commands

Properties:
- `file=<PATH_TO_FILE>`
Relative path to the file that contains a configuration of the task.
Relative path to the file that contains a configuration of the task.
- `params=FROM:<addr>,HOLDER1:<addr>,HOLDER2:<addr>`
Parameters that can be used as in-script commands parameters replacements.

Expand Down Expand Up @@ -187,9 +187,8 @@ Here the example of possible task configuration:
"name": "OrgId",
"address": "[TASK:2:contract.proxy]",
"from": "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1",
"method": "createOrganization(bytes32,string,bytes32)",
"method": "createOrganization(string,bytes32)",
"args": [
"0x31f5e1745a65fd8a2dd556c8b27d8d585ed184876126779e1323c6a1f06c68f0",
"https://gist.githubusercontent.com/[username]/3bde88a0e8248c73c68c1aed2ca4b9be/raw/5df8c96ceff4d0fa99a32d1da63b061ad4b27ccd/ORG.ID",
"[TASK:2:hash]"
]
Expand All @@ -207,10 +206,9 @@ Here the example of possible task configuration:
"name": "OrgId",
"address": "[TASK:2:contract.proxy]",
"from": "0x90f8bf6a479f320ead074411a4b0e7944ea8c9c1",
"method": "createSubsidiary(string,bytes32,address,string,string)",
"method": "createUnit(bytes32,address,string,bytes32)",
"args": [
"0x31f5e1745a65fd8a2dd556c8b27d8d585ed184876126779e1323c6a1f06c68f0",
"0x5ba8f3df5408ee9db90015040cf8cacca679a145ca3452cbd09b66eac2e54cdc",
"0xa284D6724Ab7D8194b0D894C74C34318c1319391",
"https://gist.githubusercontent.com/[username]/3b680e83da367b68c6e84407e5f2d44/raw/569ce8f321499a8249bec31fd09f6c618bcf52cd/Subsidiary%2520ORG.ID",
"[TASK:4:hash]"
Expand All @@ -226,5 +224,4 @@ The explanation of this task:
- Running `makehash` command for file `./assets/orgid-legal.json`
- Running of `tx` command. Creation of an Organization record. The hash is obtained from previous step
- Running `makehash` command for file `./assets/orgid-unit.json`
- Running of `tx` command. Creation of an Subsidiary record. The hash is obtained from previous step

- Running of `tx` command. Creation of a new organizational unit record. The hash is obtained from previous step
8 changes: 4 additions & 4 deletions test/helpers/orgid.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ module.exports.createOrganizationHelper = async (
* Helper function for creating organizational units
* @param {Object} orgIdContract ORG.ID contract instance
* @param {address} callerAddress Caller address
* @param {array} args Array of arguments for the real createSubsidiary
* @param {array} args Array of arguments for the real createUnit
* @dev Arguments order: [requestedUnitHash(bytes32), directorAddress(address), orgJsonUri(string), orgJsonHash(bytes32)]
* @returns {Promise<{string}>} New unit's ORG.ID hash
*/
module.exports.createSubsidiaryHelper = async (
module.exports.createUnitHelper = async (
orgIdContract,
callerAddress,
args
Expand All @@ -77,7 +77,7 @@ module.exports.createSubsidiaryHelper = async (
const orgJsonHash = args[3];

const result = await orgIdContract
.methods['createSubsidiary(bytes32,address,string,bytes32)'](
.methods['createUnit(bytes32,address,string,bytes32)'](
parentOrgIdHash,
directorAddress,
orgJsonUri,
Expand All @@ -86,7 +86,7 @@ module.exports.createSubsidiaryHelper = async (
.send({ from: callerAddress });

let newUnitOrgIdHash;
assertEvent(result, 'SubsidiaryCreated', [
assertEvent(result, 'UnitCreated', [
[
'parentOrgId',
p => (p).should.equal(parentOrgIdHash)
Expand Down

0 comments on commit f8c7434

Please sign in to comment.