wip: add bee-js support

pull/5370/head
Attila Gazso 3 years ago committed by yann300
parent 517c81f204
commit 9648551c7a
  1. 3
      libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx
  2. 44
      libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx
  3. 4
      libs/remix-ui/solidity-compiler/src/lib/contract-selection.tsx
  4. 1011
      package-lock.json
  5. 3
      package.json

@ -34,7 +34,8 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => {
let parseError = err let parseError = err
try { try {
parseError = JSON.stringify(err) parseError = JSON.stringify(err)
} catch (e) {} } catch (e) {
}
modal('Swarm Publish Failed', publishMessageFailed(storage, parseError)) modal('Swarm Publish Failed', publishMessageFailed(storage, parseError))
} }
} else { } else {

@ -1,6 +1,11 @@
import swarm from 'swarmgw' import { Bee } from '@ethersphere/bee-js'
const swarmgw = swarm() const beeNodes = [
new Bee('http://localhost:1633/'),
new Bee('https://bee-0.gateway.ethswarm.org/')
]
const postageBatchId = '0000000000000000000000000000000000000000000000000000000000000000'
export const publishToSwarm = async (contract, api) => { export const publishToSwarm = async (contract, api) => {
// gather list of files to publish // gather list of files to publish
@ -19,6 +24,8 @@ export const publishToSwarm = async (contract, api) => {
throw new Error('No metadata') throw new Error('No metadata')
} }
console.debug({ metadata })
await Promise.all(Object.keys(metadata.sources).map(fileName => { await Promise.all(Object.keys(metadata.sources).map(fileName => {
// find hash // find hash
let hash = null let hash = null
@ -31,7 +38,7 @@ export const publishToSwarm = async (contract, api) => {
// TODO: refactor this with publishOnIpfs // TODO: refactor this with publishOnIpfs
if (metadata.sources[fileName].urls) { if (metadata.sources[fileName].urls) {
metadata.sources[fileName].urls.forEach(url => { metadata.sources[fileName].urls.forEach(url => {
if (url.includes('bzz')) hash = url.match('(bzzr|bzz-raw)://(.+)')[1] if (url.includes('bzz')) hash = url.match('bzz://(.+)')[1]
}) })
} }
} catch (e) { } catch (e) {
@ -55,7 +62,7 @@ export const publishToSwarm = async (contract, api) => {
const result = await swarmVerifiedPublish(item.content, item.hash) const result = await swarmVerifiedPublish(item.content, item.hash)
try { try {
item.hash = result.url.match('bzz-raw://(.+)')[1] item.hash = result.url.match('bzz://(.+)')[1]
} catch (e) { } catch (e) {
item.hash = '<Metadata inconsistency> - ' + item.fileName item.hash = '<Metadata inconsistency> - ' + item.fileName
} }
@ -73,7 +80,7 @@ export const publishToSwarm = async (contract, api) => {
const result = await swarmVerifiedPublish(metadataContent, '') const result = await swarmVerifiedPublish(metadataContent, '')
try { try {
contract.metadataHash = result.url.match('bzz-raw://(.+)')[1] contract.metadataHash = result.url.match('bzz://(.+)')[1]
} catch (e) { } catch (e) {
contract.metadataHash = '<Metadata inconsistency> - metadata.json' contract.metadataHash = '<Metadata inconsistency> - metadata.json'
} }
@ -93,15 +100,24 @@ export const publishToSwarm = async (contract, api) => {
} }
const swarmVerifiedPublish = async (content, expectedHash): Promise<Record<string, any>> => { const swarmVerifiedPublish = async (content, expectedHash): Promise<Record<string, any>> => {
return new Promise((resolve, reject) => { try {
swarmgw.put(content, function (err, ret) { const results = (await beeNodes[0].uploadData(content, postageBatchId)).reference
if (err) {
reject(err) console.debug({ results, expectedHash })
} else if (expectedHash && ret !== expectedHash) {
resolve({ message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'bzz-raw://' + ret, hash: ret }) if (expectedHash && results !== expectedHash) {
return { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'bzz://' + results, hash: results }
} else { } else {
resolve({ message: 'ok', url: 'bzz-raw://' + ret, hash: ret }) return { message: 'ok', url: 'bzz://' + results, hash: results }
}
} catch (error) {
throw new Error(error)
} }
})
})
} }
// const severalGatewaysPush = (content) => {
// const invert = p => new Promise((resolve, reject) => p.then(reject).catch(resolve)) // Invert res and rej
// const promises = beeNodes.map((node) => invert(node.uploadData(content, postageBatchId)))
// return invert(Promise.all(promises))
// }

@ -193,6 +193,10 @@ export const ContractSelection = (props: ContractSelectionProps) => {
<span>Publish on Ipfs</span> <span>Publish on Ipfs</span>
<img id="ipfsLogo" className="remixui_storageLogo ml-2" src="assets/img/ipfs.webp" /> <img id="ipfsLogo" className="remixui_storageLogo ml-2" src="assets/img/ipfs.webp" />
</button> </button>
<button id="publishOnSwarm" className="btn btn-secondary btn-block" title="Publish on Swarm" onClick={() => { handlePublishToStorage('swarm') }}>
<span>Publish on Swarm</span>
<img id="swarmLogo" className="remixui_storageLogo ml-2" src="assets/img/swarm.webp" />
</button>
<button data-id="compilation-details" className="btn btn-secondary btn-block" title="Display Contract Details" onClick={() => { details() }}> <button data-id="compilation-details" className="btn btn-secondary btn-block" title="Display Contract Details" onClick={() => { details() }}>
Compilation Details Compilation Details
</button> </button>

1011
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -149,6 +149,7 @@
"@ethereumjs/common": "^2.5.0", "@ethereumjs/common": "^2.5.0",
"@ethereumjs/tx": "^3.3.2", "@ethereumjs/tx": "^3.3.2",
"@ethereumjs/vm": "^5.5.3", "@ethereumjs/vm": "^5.5.3",
"@ethersphere/bee-js": "^2.0.0",
"@isomorphic-git/lightning-fs": "^4.4.1", "@isomorphic-git/lightning-fs": "^4.4.1",
"@monaco-editor/react": "^4.3.1", "@monaco-editor/react": "^4.3.1",
"@remixproject/engine": "^0.3.28", "@remixproject/engine": "^0.3.28",
@ -198,6 +199,7 @@
"selenium": "^2.20.0", "selenium": "^2.20.0",
"signale": "^1.4.0", "signale": "^1.4.0",
"string-similarity": "^4.0.4", "string-similarity": "^4.0.4",
"swarmgw": "^0.3.1",
"time-stamp": "^2.2.0", "time-stamp": "^2.2.0",
"ts-loader": "^9.2.6", "ts-loader": "^9.2.6",
"tslib": "^2.3.0", "tslib": "^2.3.0",
@ -313,7 +315,6 @@
"selenium-standalone": "^8.0.4", "selenium-standalone": "^8.0.4",
"semver": "^6.3.0", "semver": "^6.3.0",
"solc": "0.7.4", "solc": "0.7.4",
"swarmgw": "^0.3.1",
"tap-spec": "^5.0.0", "tap-spec": "^5.0.0",
"tape": "^4.13.3", "tape": "^4.13.3",
"terser-webpack-plugin": "^4.2.3", "terser-webpack-plugin": "^4.2.3",

Loading…
Cancel
Save