Skip to content

Commit 73d0443

Browse files
0x-r4bbitiurimatias
authored andcommitted
feat(@embark/deployment): introduce interfaces and libraries configuration
This commit adds two new configuration settings for Smart Contract configuration: - `interfaces` - Any Smart Contract that represent an interface or is used for inheritance - `libraries` - Any Smart Contract that is used as a library This makes the configuration less redundant in cases where otherwise the `deploy` property has been set to `false`, such as: ``` deploy: { Ownable: { deploy: false }, ... } ``` The above can now be done via: ``` interfaces: ['Ownable'], deploy: { ... } ```
1 parent 2527058 commit 73d0443

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

dapps/tests/app/config/contracts.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ module.exports = {
1111
console.log("before deploying contracts");
1212
console.log("==========================");
1313
},
14+
interfaces: ['Ownable'],
1415
deploy: {
15-
Ownable: {
16-
deploy: false
17-
},
1816
Token: {
1917
deploy: false,
2018
args: [1000]

packages/plugins/deploy-tracker/src/deploymentChecks.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import Web3 from "web3";
44
require("colors");
55

66
export default class DeploymentChecks {
7-
constructor({trackingFunctions, events, logger}) {
7+
constructor({trackingFunctions, events, logger, contractsConfig}) {
88
this.trackingFunctions = trackingFunctions;
99
this.events = events;
1010
this.logger = logger;
1111
this._web3 = null;
12+
this.contractsConfig = contractsConfig || {};
1213

1314
this.events.on("blockchain:started", () => {
1415
this._web3 = null;
@@ -33,6 +34,13 @@ export default class DeploymentChecks {
3334
return cb(null, params);
3435
}
3536

37+
const isInterface = this.contractsConfig.interfaces && this.contractsConfig.interfaces.includes(contract.className);
38+
const isLibrary = this.contractsConfig.libraries && this.contractsConfig.libraries.includes(contract.className);
39+
40+
if (isInterface || isLibrary) {
41+
contract.deploy = false;
42+
}
43+
3644
// check if contract set to not deploy in the config
3745
if (contract.deploy === false) {
3846
params.shouldDeploy = false;

packages/plugins/deploy-tracker/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class DeployTracker {
88
this.embark = embark;
99

1010
const trackingFunctions = new TrackingFunctions({config, fs, logger, events, trackContracts});
11-
const deploymentChecks = new DeploymentChecks({trackingFunctions, logger, events, plugins});
11+
const deploymentChecks = new DeploymentChecks({trackingFunctions, logger, events, plugins, contractsConfig: config.contractsConfig});
1212

1313
this.embark.registerActionForEvent("deployment:contract:deployed", trackingFunctions.trackAndSaveContract.bind(trackingFunctions));
1414
this.embark.registerActionForEvent("deployment:contract:shouldDeploy", deploymentChecks.checkContractConfig.bind(deploymentChecks));

packages/plugins/deploy-tracker/src/test/deploymentChecksSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('embark.deploymentChecks', function () {
7777
}
7878
};
7979
trackingFunctions._web3 = _web3;
80-
deploymentChecks = new DeploymentChecks({trackingFunctions, events, logger});
80+
deploymentChecks = new DeploymentChecks({trackingFunctions, events, logger, contractsConfig: {}});
8181
deploymentChecks._web3 = _web3;
8282
});
8383
afterEach(() => {

site/source/docs/contracts_configuration.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,26 @@ production: {
127127
...
128128
```
129129

130+
## Defining interfaces
131+
132+
There are scenarios in which certain Smart Contract sources are used for inheritance or as interfaces. While their source has to be compiled,
133+
we don't actually want to deploy them. To prevent such Smart Contracts from deploying, we can either take advantage of the `deploy: false`
134+
propery discussed above, or use the more semantic `interfaces` and `libraries` configurations.
135+
136+
Both of them are simple lists of Smart Contract names that should be treated as interfaces and libraries respectively. The following example
137+
show how the `Ownable` Smart Contract is configured as interface and therefore won't be deployed:
138+
139+
```json
140+
...
141+
development:
142+
interfaces: ['Ownable'],
143+
deploy: {
144+
InheritsOwnable: {}
145+
}
146+
}
147+
...
148+
```
149+
130150
## Deployment strategies
131151

132152
In order to give users full control over which Smart Contracts should be deployed, Embark comes with a configuration feature called "deployment strategies". Deployment strategies tell Embark whether it should deploy all of the user's Smart Contracts (and its (3rd-party) dependencies, or just deploy individual Smart Contracts.

0 commit comments

Comments
 (0)