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

chore: make contract artifacts usable in node #1632

Merged

Conversation

andremedeiros
Copy link
Collaborator

@andremedeiros andremedeiros commented May 21, 2019

This will work 100% of the time, all the time.

Co-Authored with @michaelsbradleyjr

@andremedeiros andremedeiros requested a review from a team May 21, 2019 18:38

let ${contractName}JSONConfig = ${JSON.stringify(contractJSON)};
let ${contractName} = new EmbarkJS.Blockchain.Contract(${contractName}JSONConfig);
export default ${contractName};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is where problems might arise. export doesn't exist in Node. I forgot to mention it to you because I hadn't notice because the problem the user was having was with the import.
When trying to do the node embarkjs, it's the export that gave me the most problems, because you can't put export in an if... Maybe you can find a solution, but maybe we'll need to transpile those too 😞

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, does module.exports not work on the browser?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last I tried, it didn't. Maybe it was something I was doing wrong.

@andremedeiros andremedeiros force-pushed the chore/make-contract-artifacts-usable-in-node branch 2 times, most recently from a0a3554 to ccb8fb0 Compare May 21, 2019 20:49
Copy link
Collaborator

@jrainville jrainville left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good (haven't tested, but I assume it works)

@andremedeiros andremedeiros force-pushed the chore/make-contract-artifacts-usable-in-node branch from ccb8fb0 to 1f336f2 Compare May 23, 2019 18:02
@ghost
Copy link

ghost commented May 23, 2019

DeepCode analyzed this pull request.
There is 1 new info report.

Click to see more details.

@andremedeiros andremedeiros force-pushed the chore/make-contract-artifacts-usable-in-node branch from 1f336f2 to a3ee37a Compare May 23, 2019 18:05
@ghost
Copy link

ghost commented May 23, 2019

DeepCode analyzed this pull request.
There are no new issues. 1 info report was fixed.

Click to see more details.

@andremedeiros andremedeiros force-pushed the chore/make-contract-artifacts-usable-in-node branch 2 times, most recently from 25918e8 to 5618c49 Compare May 23, 2019 18:10
@ghost
Copy link

ghost commented May 23, 2019

DeepCode analyzed this pull request.
There are no new issues. 1 info report was fixed.

Click to see more details.

Copy link
Collaborator

@jrainville jrainville left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!
Would just be better to use constants

@@ -24,6 +24,7 @@ class Whisper {
this.embark = embark;
this.web3Ready = false;
this.webSocketsChannels = {};
this.modulesPath = dappPath(embark.config.embarkConfig.generationDir + "/modules");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/modules should be put in a constant and used everywhere from the symlink generation to the uses in modules

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.modulesPath = dappPath(embark.config.embarkConfig.generationDir + "/modules");
this.modulesPath = dappPath(embark.config.embarkConfig.generationDir, "modules");

Also should make use of the path-joining that dappPath() does because doing + "/" is problematic on Windows.

@@ -23,6 +23,7 @@ class IPFS {
this.addedToConsole = false;
this.storageProcessesLauncher = null;
this.usingRunningNode = false;
this.modulesPath = dappPath(embark.config.embarkConfig.generationDir + "/modules");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@@ -23,6 +23,7 @@ class Swarm {
this.addedToConsole = false;
this.storageProcessesLauncher = null;
this.usingRunningNode = false;
this.modulesPath = dappPath(embark.config.embarkConfig.generationDir + "/modules");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

@andremedeiros andremedeiros force-pushed the chore/make-contract-artifacts-usable-in-node branch from 5618c49 to 52ea0aa Compare May 23, 2019 18:41
@@ -24,6 +24,7 @@ class Whisper {
this.embark = embark;
this.web3Ready = false;
this.webSocketsChannels = {};
this.modulesPath = dappPath(embark.config.embarkConfig.generationDir + "/modules");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.modulesPath = dappPath(embark.config.embarkConfig.generationDir + "/modules");
this.modulesPath = dappPath(embark.config.embarkConfig.generationDir, "modules");

Also should make use of the path-joining that dappPath() does because doing + "/" is problematic on Windows.

@andremedeiros andremedeiros force-pushed the chore/make-contract-artifacts-usable-in-node branch from 52ea0aa to cc493f1 Compare May 23, 2019 19:48
@andremedeiros andremedeiros force-pushed the chore/make-contract-artifacts-usable-in-node branch from cc493f1 to 0827ad4 Compare May 23, 2019 19:54
Copy link
Collaborator

@jrainville jrainville left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

Copy link
Contributor

@michaelsbradleyjr michaelsbradleyjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't merge yet: tests are consistently not passing on Windows, probably some path-related thing. I'm investigating currently and will commit on this branch when I've fixed it.

@michaelsbradleyjr michaelsbradleyjr force-pushed the chore/make-contract-artifacts-usable-in-node branch 3 times, most recently from 55260a5 to d855fa1 Compare May 26, 2019 21:16
@michaelsbradleyjr
Copy link
Contributor

michaelsbradleyjr commented May 26, 2019

Please see: https://github.com/embark-framework/embark/blob/chore/make-contract-artifacts-usable-in-node/packages/embark/src/cmd/cmd_controller.js#L676-L678

The reason that's needed is that otherwise symlink creation for embarkjs-ipfs|swarm|whisper will be in a race with the startup of other services.

The problem isn't noticed after the first run of embark test, but if you do embark reset before embark test, or test a fresh dapp, (without this change in place) there will be errors re: missing modules, e.g. embarkjs-swarm.

Unfortunately, it's not just embark test that needs to be changed. A similar fix is needed for embark run|build|etc, basically any command that involves engine.startService("codeGenerator");.

Rather than make those adjustments now, I'm leaving this PR marked as changes requested, and I think we should discuss if the fix above is the way to go or if there's a better way.

@michaelsbradleyjr michaelsbradleyjr force-pushed the chore/make-contract-artifacts-usable-in-node branch from d855fa1 to 3a19f10 Compare May 28, 2019 17:27
@ghost
Copy link

ghost commented May 28, 2019

DeepCode encountered a problem when analyzing this pull request. If you want to retry, create a comment: "Retry Deepcode".

@michaelsbradleyjr
Copy link
Contributor

Retry Deepcode

@ghost
Copy link

ghost commented Jun 1, 2019

DeepCode analyzed this pull request.
There are no new issues. 1 info report was fixed.

Click to see more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants