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

Fix default path of chain:export command #1035

Merged
merged 2 commits into from
Mar 15, 2022

Conversation

Kupuyc
Copy link
Contributor

@Kupuyc Kupuyc commented Feb 17, 2022

Summary

Fixes #997

Default path of ironfish chain:export command is constant and relative - ../ironfish-graph-explorer/src/data.json. It means command will always fail except when called from ~/ironfish/* subfolder (in situation when -p flag is not set). It possible to fix such behavior using process.env.PWD.

Testing Plan

There is no test for this command - it should be tested manually. Run ironfish chain:export w/o -p flag from different places.

Breaking Change

Is this a breaking change? If yes, add notes below on why this is breaking and
what additional work is required, if any.

[ ] Yes
[x] No

@Kupuyc Kupuyc requested a review from a team as a code owner February 17, 2022 16:15
@Kupuyc Kupuyc changed the title Set default path depending of PWD Fix default path of chain:export command Feb 17, 2022
@mat-if
Copy link
Contributor

mat-if commented Feb 18, 2022

Checked this out a bit, I'm still seeing the issue. Testing on a mac, PWD seems to just return the directory from which the command was executed, not sure if this is different on other operating systems. Compared with __dirname just to test:

image

__dirname docs for reference https://nodejs.org/docs/latest/api/modules.html#__dirname

Thinking about this a bit more, this might be difficult to get right with the way it's currently coded, because we use a slightly different file structure in Docker, brew, built from source, etc.

@Kupuyc
Copy link
Contributor Author

Kupuyc commented Feb 18, 2022

@mat-if Interesting... Thank you for information. I will check.

@mat-if
Copy link
Contributor

mat-if commented Feb 18, 2022

I had an idea last night. The easiest way to fix this is probably to store the json in the datadir. We would probably need to change the default path on the ironfish-graph-explorer as well to look in the datadir, as well, and give the file a more specific name, like 'chain-export.json' or something.

@Kupuyc
Copy link
Contributor Author

Kupuyc commented Feb 19, 2022

Yeah... probably it is the best way. Let's ask team members in discord next monday.

@Kupuyc Kupuyc marked this pull request as draft February 25, 2022 00:59
default: (): Promise<string> => {
Assert.isNotUndefined(process.env.PWD)

return Promise.resolve(`${process.env.PWD}/../ironfish-graph-explorer/src/data.json`)
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR still uses incorrect relative paths. How about we just set the default path to the data directory in a folder called exports? I would recommend maybe just removing this default entirely, then below use the data dir from this.sdk.config.dataDir where the data dir is stored if no path is specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's done by second way: default value of flag set to empty string and we will resolve path using this.sdk.config.dataDir in that case.

@@ -18,7 +18,7 @@ export default class Export extends IronfishCommand {
char: 'p',
parse: (input: string): Promise<string> => Promise.resolve(input.trim()),
required: false,
default: '../ironfish-graph-explorer/src/data.json',
default: '',
Copy link
Contributor

Choose a reason for hiding this comment

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

We can just delete this now

Suggested change
default: '',

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.
Also, I added path accessibility verification.

@Kupuyc Kupuyc marked this pull request as ready for review March 12, 2022 07:22
@NullSoldier NullSoldier enabled auto-merge (squash) March 14, 2022 23:53
@NullSoldier
Copy link
Contributor

I just removed the check access, and just had it recursively create the folder for better usability. It's now good to go.

@NullSoldier NullSoldier merged commit 1a6f13b into iron-fish:staging Mar 15, 2022
@deekerno deekerno mentioned this pull request Apr 8, 2022
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.

None yet

3 participants