Skip to content
This repository has been archived by the owner on Apr 18, 2021. It is now read-only.

Commit

Permalink
feat: add choice to add registry #33
Browse files Browse the repository at this point in the history
  • Loading branch information
JhChoy committed Jan 9, 2019
1 parent 9acce64 commit 278462b
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 55 deletions.
11 changes: 5 additions & 6 deletions packages/vvisp/scripts/deploy-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module.exports = async function(options) {
checkEnvExist();
checkConfigExist();

const { printOrSilent } = require('@haechi-labs/vvisp-utils');
const { printOrSilent, getWeb3 } = require('@haechi-labs/vvisp-utils');
const { writeState } = require('./utils');
const DeployState = require('./DeployState');
const preProcess = require('./preProcess');
Expand All @@ -26,8 +26,10 @@ module.exports = async function(options) {
head: chk.bold,
error: chk.red.bold,
keyWord: chk.blue.bold,
notImportant: chk.gray
notImportant: chk.gray,
warning: chk.yellow
};
global.web3 = getWeb3();

await main();

Expand All @@ -40,10 +42,7 @@ module.exports = async function(options) {
{
name: 'deployRegistry',
process: async function() {
const stateClone = deployState.getState();
if (stateClone.notUpgrading) {
await deployRegistry(deployState, options);
}
await deployRegistry(deployState, options);
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ module.exports = function(configContracts, stateClone) {
// Check if there is no upgradeable contract.
// If so, we don't have to compile proxy contract.
let noProxy = true;
forIn(targets.contracts, contract => {
forIn(targets, contract => {
if (contract.upgradeable === true) {
noProxy = false;
}
});
stateClone.noProxy = noProxy;

return {
targets: targets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module.exports = async function(compileInformation, options) {
if (compileInformation.noProxy !== true) {
compileFiles.push(PROXY_PATH);
}
compileFiles.push(REGISTRY_PATH);
if (compileInformation.noRegistry !== true) {
compileFiles.push(REGISTRY_PATH);
}

forIn(compileInformation.targets, contract => {
if (contract.path) {
Expand Down
27 changes: 27 additions & 0 deletions packages/vvisp/scripts/deploy-service/preProcess/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,33 @@ module.exports = async function(deployState, options) {
process.exit();
}

// Check whether this process needs Registry
// Event occurs when user sets config.registry false
if (config.registry === false) {
if (compileInformation.noProxy !== true) {
throw new Error(
`No Registry with upgradeable contracts is not allowed, change 'registry' from false to true in 'service.vvisp.json'`
);
} else {
if (web3.utils.isAddress(stateClone.registry)) {
printOrSilent(
`${chalk.warning('Warning:')} Registry address ${
stateClone.registry
} will be deleted.`
);
}
compileInformation.noRegistry = true;
stateClone.registry = 'noRegistry';
}
} else if (stateClone.registry === 'noRegistry') {
printOrSilent(
`${chalk.warning(
'Notice:'
)} Sorry. In this version, we do not support adding registry in noRegistry service.\nKeep 'registry' property to false or re-deploy whole service.`
);
process.exit();
}

const compileOutput = await require('./compileAll')(
compileInformation,
options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ module.exports = async function(deployState, options) {
const contracts = deployState.targets;
let stateClone = deployState.getState();

if (stateClone.noProxy === true) {
return;
}

const txCount = await getTxCount(PRIVATE_KEY);
if (!stateClone.paused.details) {
stateClone.paused.details = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,51 +114,58 @@ module.exports = async function(deployState, options) {
}
}

const registryInstance = pathToInstance(compileOutput, REGISTRY_PATH);
registryInstance.options.address = stateClone.registry;

const setTargets = Object.keys(stateClone.paused.details);
const _addresses = [];
let _names = '';
const _nameLength = [];
let _filNames = '';
const _fileNameLength = [];
for (let i = 0; i < setTargets.length; i++) {
const { address, fileName } = stateClone.contracts[setTargets[i]];
_addresses.push(address);
_names += setTargets[i];
_nameLength.push(setTargets[i].length);
_filNames += fileName;
_fileNameLength.push(fileName.length);
if (stateClone.registry !== 'noRegistry') {
await registeringNonUpgradeableInfo(compileOutput, stateClone);
}
const txData = registryInstance.methods
.setNonUpgradeables(
_addresses,
_names,
_nameLength,
_filNames,
_fileNameLength
)
.encodeABI();
printOrSilent(
chalk.head(
"\tRegister NonUpgradeable Contracts' Information åt Registry..."
),
options
);

const receipt = await sendTx(stateClone.registry, 0, PRIVATE_KEY, {
...options,
...TX_OPTIONS,
txCount: await getTxCount(PRIVATE_KEY),
data: txData
});
printOrSilent(
`${chalk.success('Done')} Transaction Hash: ${chalk.tx(
receipt.transactionHash
)}\n`,
options
);
// @dev Uploading information about nonUpgradeable contracts to registry
async function registeringNonUpgradeableInfo(compileOutput, stateClone) {
printOrSilent(
chalk.head(
"\tRegistering NonUpgradeable Contracts' Information at Registry..."
),
options
);
const registryInstance = pathToInstance(compileOutput, REGISTRY_PATH);
registryInstance.options.address = stateClone.registry;

const setTargets = Object.keys(stateClone.paused.details);
const _addresses = [];
let _names = '';
const _nameLength = [];
let _filNames = '';
const _fileNameLength = [];
for (let i = 0; i < setTargets.length; i++) {
const { address, fileName } = stateClone.contracts[setTargets[i]];
_addresses.push(address);
_names += setTargets[i];
_nameLength.push(setTargets[i].length);
_filNames += fileName;
_fileNameLength.push(fileName.length);
}
const txData = registryInstance.methods
.setNonUpgradeables(
_addresses,
_names,
_nameLength,
_filNames,
_fileNameLength
)
.encodeABI();

const receipt = await sendTx(stateClone.registry, 0, PRIVATE_KEY, {
...options,
...TX_OPTIONS,
txCount: await getTxCount(PRIVATE_KEY),
data: txData
});
printOrSilent(
`${chalk.success('Done')} Transaction Hash: ${chalk.tx(
receipt.transactionHash
)}\n`,
options
);
}

function injectAddress(_arguments, _path, _index, contractAddress) {
const argumentIndex = _path[_index];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ module.exports = async function(deployState, options) {
const compileOutput = deployState.compileOutput;
let stateClone = deployState.getState();

if (stateClone.noProxy === true) {
return;
}

const txCount = await getTxCount(PRIVATE_KEY);
const registryInstance = pathToInstance(compileOutput, REGISTRY_PATH);
registryInstance.options.address = stateClone.registry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ module.exports = async function(deployState, options) {
printOrSilent
} = require('@haechi-labs/vvisp-utils');

const stateClone = deployState.getState();
if (
stateClone.registry === 'noRegistry' ||
stateClone.notUpgrading !== true
) {
return;
}

printOrSilent('Registry Deploying...', options);
const compileOutput = deployState.compileOutput;
const stateClone = deployState.getState();

const receipt = await deploy(
getCompiledContracts(compileOutput, REGISTRY_PATH),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ module.exports = function(deployState, options) {
});
delete stateClone.paused;
delete stateClone.notUpgrading;
delete stateClone.noProxy;
writeState(stateClone, options);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ module.exports = async function(deployState, options) {
const { compileOutput, targets } = deployState;
let stateClone = deployState.getState();

if (stateClone.registry === 'noRegistry' || stateClone.noProxy === true) {
return;
}

const upgradeables = [];
forIn(targets, (contract, name) => {
if (contract[UPGRADEABLE] === true) {
Expand Down
4 changes: 4 additions & 0 deletions packages/vvisp/scripts/deploy-service/processes/upgradeAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ module.exports = async function(deployState, options) {
const { compileOutput, targets } = deployState;
let stateClone = deployState.getState();

if (stateClone.noProxy === true) {
return;
}

const upgradeables = [];
forIn(targets, (contract, name) => {
if (contract[UPGRADEABLE] === true) {
Expand Down
38 changes: 38 additions & 0 deletions packages/vvisp/test/dummy/noRegistry.service1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"serviceName": "Haechi",
"registry": false,
"variables" : {
"owner" : "0xb5F4E40c8177Ad63B19D4D3a254a5758771f57d0",
"value1": 1
},
"contracts": {
"DependencyA": {
"path": "contracts/test/DependencyA.sol",
"constructorArguments": [
"${contracts.DependencyB.address}",
"${contracts.DependencyC.address}",
"${variables.owner}"
]
},
"DependencyB": {
"path": "contracts/test/DependencyB.sol",
"constructorArguments": [
3,
"${contracts.DependencyD.address}",
"${variables.owner}"
]
},
"DependencyC": {
"path": "contracts/test/DependencyC.sol",
"constructorArguments": [
]
},
"DependencyD": {
"path": "contracts/test/DependencyD.sol",
"constructorArguments": [
["${variables.value1}",2,3],
"${variables.owner}"
]
}
}
}
69 changes: 69 additions & 0 deletions packages/vvisp/test/dummy/noRegistry.service2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"serviceName": "Haechi",
"registry": false,
"variables" : {
"owner" : "0xb5F4E40c8177Ad63B19D4D3a254a5758771f57d0",
"value1": 1
},
"contracts": {
"DependencyA": {
"path": "contracts/test/DependencyA.sol",
"constructorArguments": [
"${contracts.DependencyB.address}",
"${contracts.DependencyC.address}",
"${variables.owner}"
]
},
"DependencyB": {
"path": "contracts/test/DependencyB.sol",
"constructorArguments": [
3,
"${contracts.DependencyD.address}",
"${variables.owner}"
]
},
"DependencyC": {
"path": "contracts/test/DependencyC.sol",
"constructorArguments": [
]
},
"DependencyD": {
"path": "contracts/test/DependencyD.sol",
"constructorArguments": [
["${variables.value1}",2,3],
"${variables.owner}"
]
},
"SecondA": {
"path": "contracts/test/SecondA.sol",
"constructorArguments": [
"${contracts.SecondC.address}",
"${contracts.DependencyD.address}",
["${contracts.SecondC.address}", "${variables.owner}"]
],
"initialize": {
"functionName": "initialize",
"arguments": [
"${contracts.SecondD.address}",
"${variables.owner}",
["${contracts.SecondC.address}", "${variables.owner}"]
]
}
},
"SecondC": {
"path": "contracts/test/SecondC.sol",
"constructorArguments": [
"${contracts.SecondD.address}",
"${contracts.DependencyD.address}",
"${contracts.SecondD.address}"
]
},
"SecondD": {
"path": "contracts/test/SecondD.sol",
"constructorArguments": [
"${variables.owner}",
"${variables.owner}"
]
}
}
}
22 changes: 22 additions & 0 deletions packages/vvisp/test/dummy/noRegistry.state1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"contracts": {
"DependencyA": {
"address": "0x0D2657C2136428Ba7bE1CcF0Ee8e2c5c6AACD927",
"fileName": "DependencyA.sol"
},
"DependencyB": {
"address": "0x8b19C0EB06925f7708214230615228C9F30E49f0",
"fileName": "DependencyB.sol"
},
"DependencyC": {
"address": "0x46f39068665D6EeDEFa53e5C660168AB9e946cA3",
"fileName": "DependencyC.sol"
},
"DependencyD": {
"address": "0x074A3218146a98C8651696af9fF2396b5aD5700D",
"fileName": "DependencyD.sol"
}
},
"serviceName": "Haechi",
"registry": "noRegistry"
}

0 comments on commit 278462b

Please sign in to comment.