Skip to content
Open
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
20 changes: 10 additions & 10 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
pragma solidity ^0.4.24;
pragma solidity >=0.4.21 <0.7.0;

contract Migrations {
address public owner;
uint256 public last_completed_migration;
uint public last_completed_migration;

modifier restricted() {
if (msg.sender == owner) _;
constructor() public {
owner = msg.sender;
}

constructor () public {
owner = msg.sender;
modifier restricted() {
if (msg.sender == owner) _;
}

function setCompleted(uint256 _completed) public restricted {
last_completed_migration = _completed;
function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}

function upgrade(address _newAddress) public restricted {
Migrations upgraded = Migrations(_newAddress);
function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* Author: Victor Mezrin victor@mezrin.com */

pragma solidity ^0.4.24;
pragma solidity >=0.4.0 <0.6.0;


import '../../../util/CommonModifiers/CommonModifiersInterface.sol';
import '../../../lifecycle/Manageable/ManageableInterface.sol';
import '../../../lifecycle/Pausable/PausableInterface.sol';
import '../../../util/CommonModifiers/CommonModifiers.sol';
import '../../../lifecycle/Manageable/Manageable.sol';
import '../../../lifecycle/Pausable/Pausable.sol';
import './CrydrControllerBaseInterface.sol';

import '../../view/CrydrViewBase/CrydrViewBaseInterface.sol';
Expand All @@ -15,17 +15,22 @@ import '../../view/CrydrViewBase/CrydrViewBaseInterface.sol';
* @title CrydrControllerBase
* @dev Implementation of a contract with business-logic of an CryDR, mediates CryDR views and storage
*/
contract CrydrControllerBase is CommonModifiersInterface,
ManageableInterface,
PausableInterface,
CrydrControllerBaseInterface {
contract CrydrControllerBase is CommonModifiers,
Pausable
{



/* Storage */

address crydrStorage = address(0x0);
mapping (string => address) crydrViewsAddresses;
mapping (address => bool) isRegisteredView;

event CrydrStorageChangedEvent(address indexed crydrstorage);
event CrydrViewAddedEvent(address indexed crydrview, bytes32 standardname);
event CrydrViewRemovedEvent(address indexed crydrview, bytes32 standardname);


/* CrydrControllerBaseInterface */

Expand All @@ -45,13 +50,13 @@ contract CrydrControllerBase is CommonModifiersInterface,
emit CrydrStorageChangedEvent(_crydrStorage);
}

function getCrydrStorageAddress() public constant returns (address) {
function getCrydrStorageAddress() public view returns (address) {
return address(crydrStorage);
}


function setCrydrView(
address _newCrydrView, string _viewApiStandardName
address _newCrydrView, string calldata _viewApiStandardName
)
external
onlyContractAddress(_newCrydrView)
Expand All @@ -64,16 +69,16 @@ contract CrydrControllerBase is CommonModifiersInterface,

CrydrViewBaseInterface crydrViewInstance = CrydrViewBaseInterface(_newCrydrView);
bytes32 standardNameHash = crydrViewInstance.getCrydrViewStandardNameHash();
require(standardNameHash == keccak256(_viewApiStandardName));
require(standardNameHash == keccak256(abi.encodePacked(_viewApiStandardName)));

crydrViewsAddresses[_viewApiStandardName] = _newCrydrView;
isRegisteredView[_newCrydrView] = true;

emit CrydrViewAddedEvent(_newCrydrView, keccak256(_viewApiStandardName));
emit CrydrViewAddedEvent(_newCrydrView, keccak256(abi.encodePacked(_viewApiStandardName)));
}

function removeCrydrView(
string _viewApiStandardName
string calldata _viewApiStandardName
)
external
onlyValidCrydrViewStandardName(_viewApiStandardName)
Expand All @@ -88,14 +93,14 @@ contract CrydrControllerBase is CommonModifiersInterface,
crydrViewsAddresses[_viewApiStandardName] == address(0x0);
isRegisteredView[removedView] = false;

emit CrydrViewRemovedEvent(removedView, keccak256(_viewApiStandardName));
emit CrydrViewRemovedEvent(removedView, keccak256(abi.encodePacked(_viewApiStandardName)));
}

function getCrydrViewAddress(
string _viewApiStandardName
string memory _viewApiStandardName
)
public
constant
view
onlyValidCrydrViewStandardName(_viewApiStandardName)
returns (address)
{
Expand All @@ -108,7 +113,7 @@ contract CrydrControllerBase is CommonModifiersInterface,
address _crydrViewAddress
)
public
constant
view
returns (bool)
{
require(_crydrViewAddress != address(0x0));
Expand All @@ -117,13 +122,25 @@ contract CrydrControllerBase is CommonModifiersInterface,
}

function isCrydrViewRegistered(
string _viewApiStandardName
string memory _viewApiStandardName
)
public
constant
view
onlyValidCrydrViewStandardName(_viewApiStandardName)
returns (bool)
{
return (crydrViewsAddresses[_viewApiStandardName] != address(0x0));
}

/* Helpers */

modifier onlyValidCrydrViewStandardName(string memory _viewApiStandard) {
require(bytes(_viewApiStandard).length > 0);
_;
}

modifier onlyCrydrView() {
require(isCrydrViewAddress(msg.sender) == true);
_;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { submitTxAndWaitConfirmation } from '../../../../jsroutines/util/SubmitT
const Promise = require('bluebird');

const CrydrControllerBaseInterfaceArtifact = global.artifacts.require('CrydrControllerBaseInterface.sol');
const CrydrControllerBaseArtifact = global.artifacts.require('CrydrControllerBase.sol');


/* Configuration */
Expand All @@ -13,21 +14,26 @@ export const setCrydrStorage = async (crydrControllerAddress, managerAddress,
global.console.log(`\t\tcontroller - ${crydrControllerAddress}`);
global.console.log(`\t\tmanagerAddress - ${managerAddress}`);
global.console.log(`\t\tstorage - ${crydrStorageAddress}`);
await submitTxAndWaitConfirmation(
CrydrControllerBaseInterfaceArtifact
.at(crydrControllerAddress)
.setCrydrStorage
.sendTransaction,
[crydrStorageAddress],
{ from: managerAddress }
);
// await submitTxAndWaitConfirmation(
// CrydrControllerBaseInterfaceArtifact
// .at(crydrControllerAddress)
// .setCrydrStorage
// .sendTransaction,
// [crydrStorageAddress],
// { from: managerAddress }
// );
const instance = await CrydrControllerBaseInterfaceArtifact.at(crydrControllerAddress);
const c = await CrydrControllerBaseArtifact.at(crydrControllerAddress);

await instance.setCrydrStorage(crydrStorageAddress, { from: managerAddress });
global.console.log('\tStorage of CryDR controller successfully set');
return null;
};

export const getCrydrStorageAddress = async (contractAddress) => {
global.console.log('\tFetch address of CrydrStorage configure in crydr controller');
const result = await CrydrControllerBaseInterfaceArtifact.at(contractAddress).getCrydrStorageAddress.call();
const i = await CrydrControllerBaseInterfaceArtifact.at(contractAddress);
const result = await i.getCrydrStorageAddress();
global.console.log(`\t\tFetched address: ${result}`);
return result;
};
Expand All @@ -41,14 +47,16 @@ export const setCrydrView = async (crydrControllerAddress, managerAddress,
global.console.log(`\t\tcrydrViewAddress - ${crydrViewAddress}`);
global.console.log(`\t\tcrydrViewStandardName - ${crydrViewStandardName}`);

await submitTxAndWaitConfirmation(
CrydrControllerBaseInterfaceArtifact
.at(crydrControllerAddress)
.setCrydrView
.sendTransaction,
[crydrViewAddress, crydrViewStandardName],
{ from: managerAddress }
);
// await submitTxAndWaitConfirmation(
// CrydrControllerBaseInterfaceArtifact
// .at(crydrControllerAddress)
// .setCrydrView
// .sendTransaction,
// [crydrViewAddress, crydrViewStandardName],
// { from: managerAddress }
// );
const instance = await CrydrControllerBaseInterfaceArtifact.at(crydrControllerAddress);
await instance.setCrydrView(crydrViewAddress, crydrViewStandardName, { from: managerAddress });
global.console.log('\tView of CryDR controller successfully set');
return null;
};
Expand All @@ -59,36 +67,41 @@ export const removeCrydrView = async (crydrControllerAddress, managerAddress,
global.console.log(`\t\tcontroller - ${crydrControllerAddress}`);
global.console.log(`\t\tmanagerAddress - ${managerAddress}`);
global.console.log(`\t\tviewApiStandardName - ${viewApiStandardName}`);
await submitTxAndWaitConfirmation(
CrydrControllerBaseInterfaceArtifact
.at(crydrControllerAddress)
.removeCrydrView
.sendTransaction,
[viewApiStandardName],
{ from: managerAddress }
);
// await submitTxAndWaitConfirmation(
// CrydrControllerBaseInterfaceArtifact
// .at(crydrControllerAddress)
// .removeCrydrView
// .sendTransaction,
// [viewApiStandardName],
// { from: managerAddress }
// );
const instance = await CrydrControllerBaseInterfaceArtifact.at(crydrControllerAddress);
await instance.removeCrydrView(viewApiStandardName, { from: managerAddress });
global.console.log('\tView of CryDR controller successfully removed');
return null;
};

export const getCrydrViewAddress = async (contractAddress, standardName) => {
global.console.log('\tFetch address of CrydrView configure in crydr controller');
const result = await CrydrControllerBaseInterfaceArtifact.at(contractAddress).getCrydrViewAddress.call(standardName);
const i = await CrydrControllerBaseInterfaceArtifact.at(contractAddress);
const result = i.getCrydrViewAddress(standardName);
global.console.log(`\t\tFetched address: ${result}`);
return result;
};


export const isCrydrViewAddress = async (contractAddress, crydrViewAddress) => {
global.console.log('\tFetch whether address is an crydr view contract');
const result = await CrydrControllerBaseInterfaceArtifact.at(contractAddress).isCrydrViewAddress.call(crydrViewAddress);
const i = await CrydrControllerBaseInterfaceArtifact.at(contractAddress);
const result = i.isCrydrViewAddress.call(crydrViewAddress);
global.console.log(`\t\tFetched result: ${result}`);
return result;
};

export const isCrydrViewRegistered = async (contractAddress, viewApiStandardName) => {
global.console.log('\tFetch whether view with given standard name exists');
const result = await CrydrControllerBaseInterfaceArtifact.at(contractAddress).isCrydrViewRegistered.call(viewApiStandardName);
const i = await CrydrControllerBaseInterfaceArtifact.at(contractAddress);
const result = i.isCrydrViewRegistered.call(viewApiStandardName);
global.console.log(`\t\tFetched result: ${result}`);
return result;
};
Expand All @@ -98,26 +111,41 @@ export const isCrydrViewRegistered = async (contractAddress, viewApiStandardName
* Events
*/

export const getCrydrStorageChangedEvents = (contractAddress, eventDataFilter = {}, commonFilter = {}) => {
const eventObj = CrydrControllerBaseInterfaceArtifact
.at(contractAddress)
.CrydrStorageChangedEvent(eventDataFilter, commonFilter);
const eventGet = Promise.promisify(eventObj.get).bind(eventObj);
return eventGet();
export const getCrydrStorageChangedEvents = async (contractAddress, eventDataFilter = {}, commonFilter = {}) => {
// const eventObj = CrydrControllerBaseInterfaceArtifact
// .at(contractAddress)
// .CrydrStorageChangedEvent(eventDataFilter, commonFilter);
// const eventGet = Promise.promisify(eventObj.get).bind(eventObj);
// return eventGet();
const filter = commonFilter;
filter.filter = eventDataFilter;
const i = await CrydrControllerBaseInterfaceArtifact.at(contractAddress);
const events = await i.getPastEvents('CrydrStorageChangedEvent', filter);
return events;
};

export const getCrydrViewAddedEvents = (contractAddress, eventDataFilter = {}, commonFilter = {}) => {
const eventObj = CrydrControllerBaseInterfaceArtifact
.at(contractAddress)
.CrydrViewAddedEvent(eventDataFilter, commonFilter);
const eventGet = Promise.promisify(eventObj.get).bind(eventObj);
return eventGet();
export const getCrydrViewAddedEvents = async (contractAddress, eventDataFilter = {}, commonFilter = {}) => {
// const eventObj = CrydrControllerBaseInterfaceArtifact
// .at(contractAddress)
// .CrydrViewAddedEvent(eventDataFilter, commonFilter);
// const eventGet = Promise.promisify(eventObj.get).bind(eventObj);
// return eventGet();
const filter = commonFilter;
filter.filter = eventDataFilter;
const i = await CrydrControllerBaseInterfaceArtifact.at(contractAddress);
const events = await i.getPastEvents('CrydrViewAddedEvent', filter);
return events;
};

export const getCrydrViewRemovedEvents = (contractAddress, eventDataFilter = {}, commonFilter = {}) => {
const eventObj = CrydrControllerBaseInterfaceArtifact
.at(contractAddress)
.CrydrViewRemovedEvent(eventDataFilter, commonFilter);
const eventGet = Promise.promisify(eventObj.get).bind(eventObj);
return eventGet();
export const getCrydrViewRemovedEvents = async (contractAddress, eventDataFilter = {}, commonFilter = {}) => {
// const eventObj = CrydrControllerBaseInterfaceArtifact
// .at(contractAddress)
// .CrydrViewRemovedEvent(eventDataFilter, commonFilter);
// const eventGet = Promise.promisify(eventObj.get).bind(eventObj);
// return eventGet();
const filter = commonFilter;
filter.filter = eventDataFilter;
const i = await CrydrControllerBaseInterfaceArtifact.at(contractAddress);
const events = await i.getPastEvents('CrydrViewRemovedEvent', filter);
return events;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Author: Victor Mezrin victor@mezrin.com */

pragma solidity ^0.4.24;
pragma solidity >=0.4.0 <0.6.0;


/**
Expand All @@ -19,19 +19,19 @@ contract CrydrControllerBaseInterface {
/* Configuration */

function setCrydrStorage(address _newStorage) external;
function getCrydrStorageAddress() public constant returns (address);
function getCrydrStorageAddress() public view returns (address);

function setCrydrView(address _newCrydrView, string _viewApiStandardName) external;
function removeCrydrView(string _viewApiStandardName) external;
function getCrydrViewAddress(string _viewApiStandardName) public constant returns (address);
function setCrydrView(address _newCrydrView, string calldata _viewApiStandardName) external;
function removeCrydrView(string calldata _viewApiStandardName) external;
function getCrydrViewAddress(string memory _viewApiStandardName) public view returns (address);

function isCrydrViewAddress(address _crydrViewAddress) public constant returns (bool);
function isCrydrViewRegistered(string _viewApiStandardName) public constant returns (bool);
function isCrydrViewAddress(address _crydrViewAddress) public view returns (bool);
function isCrydrViewRegistered(string memory _viewApiStandardName) public view returns (bool);


/* Helpers */

modifier onlyValidCrydrViewStandardName(string _viewApiStandard) {
modifier onlyValidCrydrViewStandardName(string memory _viewApiStandard) {
require(bytes(_viewApiStandard).length > 0);
_;
}
Expand Down
Loading