wip: add bee-js support

pull/2134/head
Attila Gazso 3 years ago committed by yann300
parent 7e8f3e5be1
commit fb180cd1af
  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
try {
parseError = JSON.stringify(err)
} catch (e) {}
} catch (e) {
}
modal('Swarm Publish Failed', publishMessageFailed(storage, parseError))
}
} 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) => {
// gather list of files to publish
@ -19,6 +24,8 @@ export const publishToSwarm = async (contract, api) => {
throw new Error('No metadata')
}
console.debug({ metadata })
await Promise.all(Object.keys(metadata.sources).map(fileName => {
// find hash
let hash = null
@ -31,7 +38,7 @@ export const publishToSwarm = async (contract, api) => {
// TODO: refactor this with publishOnIpfs
if (metadata.sources[fileName].urls) {
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) {
@ -55,7 +62,7 @@ export const publishToSwarm = async (contract, api) => {
const result = await swarmVerifiedPublish(item.content, item.hash)
try {
item.hash = result.url.match('bzz-raw://(.+)')[1]
item.hash = result.url.match('bzz://(.+)')[1]
} catch (e) {
item.hash = '<Metadata inconsistency> - ' + item.fileName
}
@ -73,7 +80,7 @@ export const publishToSwarm = async (contract, api) => {
const result = await swarmVerifiedPublish(metadataContent, '')
try {
contract.metadataHash = result.url.match('bzz-raw://(.+)')[1]
contract.metadataHash = result.url.match('bzz://(.+)')[1]
} catch (e) {
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>> => {
return new Promise((resolve, reject) => {
swarmgw.put(content, function (err, ret) {
if (err) {
reject(err)
} else if (expectedHash && ret !== expectedHash) {
resolve({ message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'bzz-raw://' + ret, hash: ret })
try {
const results = (await beeNodes[0].uploadData(content, postageBatchId)).reference
console.debug({ results, expectedHash })
if (expectedHash && results !== expectedHash) {
return { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'bzz://' + results, hash: results }
} 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>
<img id="ipfsLogo" className="remixui_storageLogo ml-2" src="assets/img/ipfs.webp" />
</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() }}>
Compilation Details
</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/tx": "^3.3.2",
"@ethereumjs/vm": "^5.5.3",
"@ethersphere/bee-js": "^2.0.0",
"@isomorphic-git/lightning-fs": "^4.4.1",
"@monaco-editor/react": "^4.3.1",
"@remixproject/engine": "^0.3.28",
@ -198,6 +199,7 @@
"selenium": "^2.20.0",
"signale": "^1.4.0",
"string-similarity": "^4.0.4",
"swarmgw": "^0.3.1",
"time-stamp": "^2.2.0",
"ts-loader": "^9.2.6",
"tslib": "^2.3.0",
@ -313,7 +315,6 @@
"selenium-standalone": "^8.0.4",
"semver": "^6.3.0",
"solc": "0.7.4",
"swarmgw": "^0.3.1",
"tap-spec": "^5.0.0",
"tape": "^4.13.3",
"terser-webpack-plugin": "^4.2.3",

Loading…
Cancel
Save