-
Notifications
You must be signed in to change notification settings - Fork 490
Added swarm support in embarkjs, isAvailable for messages/storage, swarm/ipfs checks #390
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
Conversation
Adding swarm to embarkjs. WIP. Add 'auto' setting for geth CORS and websockets origin * 'auto' now supported for `rpcCorsDomain` and `wsOrigins` in the blockchain config. * 'auto' set to the default value in blockchain config for test and demo apps. test add config and contract and add test addFileToPipeline test and registerBeforeDeploy with new arg add more registers but generation one fails in run WIP commit Undo changes to test config. Merge pull request #381 from embark-framework/features/cors-auto Add 'auto' setting for geth CORS and websockets origin fix a bug where upload cmd used plugin name don't error if it's an empty dapp with no contracts yet Merge pull request #383 from embark-framework/no_contracts don't error if it's an empty dapp with no contracts yet remove duplicated entry force zepplein version for travis Merge pull request #384 from embark-framework/chores/test-allpligin-apis Small fixes for plugin APIs intercept logs in the app itself - stopgap fix Merge pull request #385 from embark-framework/console_logs_fix intercept logs in the app itself - stopgap fix * removed unneeded provider property. * add 'swarm' as a provider in the storage.config * update method for swarm service check Merge branch 'develop' into features/add-swarm-to-embarkjs More work to add swarm to embarkjs * added eth-lib to parse result of swarm text * changed "currentStorage" and "currentMessages" to "currentProvider" for consistency. * added protocol to storage config * selectively starts storage service depending on which one is configured in the storage config * run service check for ipfs/swarm prior to uploaded * added swarm methods for embarkjs Updated code based on code review check if testrpc is installed and warn if not Merge pull request #386 from embark-framework/bug_fix/test-rpc-not-installed check if testrpc is installed and warn if not Removed timeout Removed spacer Merge pull request #382 from embark-framework/react-demo Updating embark demo to use react instead of jquery fix on contract add Merge pull request #387 from embark-framework/bug_fix/new-contract-in-empty-dapp Fix adding a contract redeploy with right config on config change fix tests reset watchers after build to make sure files remain watch Merge pull request #389 from embark-framework/bug_fix/file-changes-not-watched Fix files not being watched Merge pull request #388 from embark-framework/bug_fix/changing-contract-config Redeploy with right config on config change Added swarm support in embarkjs and isAvailable for messages/storage * reverted currentProvider back to currentStorage and currentMessages * added `EmbarkJS.Storage.isAvailable` and `EmbarkJS.Messages.isAvailable()` and underlying provider functions for Whisper, Orbit, IPFS, and Swarm * Finished swarm implementation in embarkjs plus cleanup * updated test app storage config to swarm to show swarm config option Merge branch 'develop' into features/add-swarm-to-embarkjs
…rm-to-embarkjs' of https://github.com/embark-framework/embark into features/add-swarm-to-embarkjs
|
on the test app, run |
…rm-to-embarkjs' of https://github.com/embark-framework/embark into features/add-swarm-to-embarkjs
…into features/add-swarm-to-embarkjs
jrainville
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly the same comment at multiple places about returning to prevent further code execution and also because it's cleaner. Otherwise, it's pretty gucci 👍
lib/index.js
Outdated
| return true; | ||
| } | ||
| }); | ||
| if(!checkFn || typeof checkFn.fn !== 'function') callback(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just code cleaning: You could just do:
if(!checkFn || typeof checkFn.fn !== 'function') {
return callback();
}
That way, we don't need an else.
lib/index.js
Outdated
| if(!serviceCheckResult.status || serviceCheckResult.status === 'off'){ | ||
| callback({message:`Cannot upload: ${platform} node is not running on http://${engine.config.storageConfig.host}:${engine.config.storageConfig.port}.`}); | ||
| } else { | ||
| callback(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, you can use a return from the first one to remove the else. But mostly, no need to put null in the callback.
lib/index.js
Outdated
| callback(); | ||
| } | ||
| } | ||
| else callback(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing as above.
lib/modules/ipfs/embarkjs.js
Outdated
|
|
||
| __embarkIPFS.isAvailable = function(){ | ||
| return new Promise((resolve) => { | ||
| if(!this.ipfsConnection) resolve(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you need a return here to make sure we don't resolve twice (not sure if it is possible, but at least to prevent anymore code execution)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I tested and it does only take the first resolve, but it also does continue the code execution, so I think using a return would still be nice.
lib/modules/swarm/embarkjs.js
Outdated
| this.connectError = new Error(`Cannot connect to Swarm node on ${this.connectUrl}`); | ||
| this._getUrl = options.getUrl || `${this.connectUrl}/bzzr:/`; | ||
|
|
||
| var promise = new Promise((resolve, reject) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the var. Just return new Promise((resolve, reject) => { ......
lib/modules/swarm/embarkjs.js
Outdated
| __embarkSwarm.saveText = function(text) { | ||
| return new Promise((resolve, reject) => { | ||
| this.isAvailable().then((isAvailable) => { | ||
| if(!isAvailable) reject(this.connectError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again return
lib/modules/swarm/embarkjs.js
Outdated
| __embarkSwarm.get = function(hash) { | ||
| return new Promise((resolve, reject) => { | ||
| this.isAvailable().then((isAvailable) => { | ||
| if(!isAvailable) reject(this.connectError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again return (sorry for copy-pasta, just want you to know all the spots 🤷♂️ )
lib/modules/swarm/embarkjs.js
Outdated
| reader.onloadend = (event) => { | ||
| var fileContent = new Uint8Array(event.target.result); | ||
| this.isAvailable().then((isAvailable) => { | ||
| if(!isAvailable) reject(this.connectError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again return
lib/modules/whisper/js/embarkjs.js
Outdated
|
|
||
| __embarkWhisperNewWeb3.isAvailable = function(){ | ||
| return new Promise((resolve, reject) => { | ||
| if(!this.web3.shh) resolve(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again return
|
|
||
| __embarkWhisperOld.isAvailable = function(){ | ||
| return new Promise((resolve, reject) => { | ||
| if(!this.web3) resolve(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again return
|
@jrainville could you add the missing early returns please and then merge? @emizzle is currently traveling |
jrainville
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I'm concerned, the code is good. I tested in the demo app and it worked ok. Sometimes, the image returned a 0 byte file, but could be swarm-gateways. However, upload swarm returns with a dir_hash of false (both in the demo app and test app) and I'm not sure why that is. @emizzle is there another step to configure?
|
Returning 0 byte files and returning a hash that 404's on the network are exactly the issues I was having with swarm. What does your storage.json look like @jrainville? |
|
I went back to IPFS after testing, but I had what you put in the test_app: |
|
The config looks good. I just feel like Swarm is strangely unreliable. Mostly on localhost, getting a resource seemed to return a 200 but with 0 bytes. While swarm-gateways.net seems to 404 most often (and sometimes the resource will eventually become available). And other times, I'll get a CORS error when trying to get a resource. It's definitely flaky. In saying that, I have never hit an issue with not getting a hash. And even weirder, I swear sometimes it would seem to work better when running a local node, but using swarm-gateways.net. But that would never be 100% reliable either. Witch craft. |
EmbarkJS.Storage.isAvailableandEmbarkJS.Messages.isAvailable()and underlying provider functions for Whisper, Orbit, IPFS, and Swarm so service availability can be checked from the DApp (@richard-ramos)