Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality for checking chainId #804

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions contracts/Schains.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ contract Schains is Permissions, ISchains {
string name;
address originator;
SchainOption[] options;
uint chainId;
}

// schainHash => Set of options hashes
Expand Down Expand Up @@ -109,7 +110,8 @@ contract Schains is Permissions, ISchains {
string calldata name,
address schainOwner,
address schainOriginator,
SchainOption[] calldata options
SchainOption[] calldata options,
uint chainId
)
external
payable
Expand All @@ -123,7 +125,8 @@ contract Schains is Permissions, ISchains {
nonce: nonce,
name: name,
originator: schainOriginator,
options: options
options: options,
chainId: chainId
});

address _schainOwner;
Expand Down Expand Up @@ -304,19 +307,21 @@ contract Schains is Permissions, ISchains {
uint deposit,
uint lifetime,
ISchainsInternal schainsInternal,
SchainOption[] memory options
SchainOption[] memory options,
uint chainId
)
private
{
require(schainsInternal.isSchainNameAvailable(name), "Schain name is not available");
require(schainsInternal.isChainIdAvailable(chainId), "Chain id is not available");

bytes32 schainHash = keccak256(abi.encodePacked(name));
for (uint i = 0; i < options.length; ++i) {
_setOption(schainHash, options[i]);
}

// initialize Schain
schainsInternal.initializeSchain(name, from, originator, lifetime, deposit);
schainsInternal.initializeSchain(name, from, originator, lifetime, deposit, chainId);
}

/**
Expand Down Expand Up @@ -369,7 +374,8 @@ contract Schains is Permissions, ISchains {
deposit,
schainParameters.lifetime,
schainsInternal,
schainParameters.options
schainParameters.options,
schainParameters.chainId
);

// create a group for Schain
Expand Down
16 changes: 14 additions & 2 deletions contracts/SchainsInternal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ contract SchainsInternal is Permissions, ISchainsInternal {

uint public currentGeneration;

mapping (uint => bool) public chainIds;


bytes32 public constant SCHAIN_TYPE_MANAGER_ROLE = keccak256("SCHAIN_TYPE_MANAGER_ROLE");
bytes32 public constant DEBUGGER_ROLE = keccak256("DEBUGGER_ROLE");
bytes32 public constant GENERATION_MANAGER_ROLE = keccak256("GENERATION_MANAGER_ROLE");
Expand Down Expand Up @@ -114,7 +117,8 @@ contract SchainsInternal is Permissions, ISchainsInternal {
address from,
address originator,
uint lifetime,
uint deposit
uint deposit,
uint chainId
)
external
override
Expand All @@ -133,7 +137,8 @@ contract SchainsInternal is Permissions, ISchainsInternal {
deposit: deposit,
index: numberOfSchains,
generation: currentGeneration,
originator: originator
originator: originator,
chainId: chainId
});
isSchainActive[schainHash] = true;
numberOfSchains++;
Expand Down Expand Up @@ -553,6 +558,13 @@ contract SchainsInternal is Permissions, ISchainsInternal {
bytes(name).length > 0;
}

/**
* @dev Checks whether chain Id is available.
*/
function isChainIdAvailable(uint chainId) external view override returns (bool) {
return !chainIds[chainId];
}

/**
* @dev Checks whether schain lifetime has expired.
*
Expand Down