Merge branch 'master' into githubmodal

pull/5370/head
bunsenstraat 3 years ago committed by GitHub
commit 07e9f9b78b
  1. 56
      libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx
  2. 56
      libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx

@ -26,33 +26,41 @@ export const publishToSwarm = async (contract, api) => {
} }
await Promise.all(Object.keys(metadata.sources).map(fileName => { await Promise.all(Object.keys(metadata.sources).map(fileName => {
// find hash return new Promise((resolve, reject) => {
let hash = null // find hash
try { let hash = null
// we try extract the hash defined in the metadata.json try {
// in order to check if the hash that we get after publishing is the same as the one located in metadata.json // we try extract the hash defined in the metadata.json
// if it's not the same, we throw "hash mismatch between solidity bytecode and uploaded content" // in order to check if the hash that we get after publishing is the same as the one located in metadata.json
// if we don't find the hash in the metadata.json, the check is not done. // if it's not the same, we throw "hash mismatch between solidity bytecode and uploaded content"
// // if we don't find the hash in the metadata.json, the check is not done.
// TODO: refactor this with publishOnIpfs //
if (metadata.sources[fileName].urls) { // TODO: refactor this with publishOnIpfs
metadata.sources[fileName].urls.forEach(url => { if (metadata.sources[fileName].urls) {
if (url.includes('bzz')) hash = url.match('bzz-raw://(.+)')[1] metadata.sources[fileName].urls.forEach(url => {
}) if (url.includes('bzz')) hash = url.match('bzz-raw://(.+)')[1]
})
}
} catch (e) {
return reject(new Error('Error while extracting the hash from metadata.json'))
} }
} catch (e) {
throw new Error('Error while extracting the hash from metadata.json')
}
api.readFile(fileName).then((content) => { api.readFile(fileName).then((content) => {
sources.push({ sources.push({
content: content, content: content,
hash: hash, hash: hash,
filename: fileName filename: fileName
})
resolve({
content: content,
hash: hash,
filename: fileName
})
}).catch((error) => {
console.log(error)
reject(error)
}) })
}).catch((error) => { })
console.log(error)
})
})) }))
// the list of nodes to publish to // the list of nodes to publish to

@ -24,33 +24,41 @@ export const publishToIPFS = async (contract, api) => {
} }
await Promise.all(Object.keys(metadata.sources).map(fileName => { await Promise.all(Object.keys(metadata.sources).map(fileName => {
// find hash return new Promise((resolve, reject) => {
let hash = null // find hash
try { let hash = null
// we try extract the hash defined in the metadata.json try {
// in order to check if the hash that we get after publishing is the same as the one located in metadata.json // we try extract the hash defined in the metadata.json
// if it's not the same, we throw "hash mismatch between solidity bytecode and uploaded content" // in order to check if the hash that we get after publishing is the same as the one located in metadata.json
// if we don't find the hash in the metadata.json, the check is not done. // if it's not the same, we throw "hash mismatch between solidity bytecode and uploaded content"
// // if we don't find the hash in the metadata.json, the check is not done.
// TODO: refactor this with publishOnSwarm //
if (metadata.sources[fileName].urls) { // TODO: refactor this with publishOnSwarm
metadata.sources[fileName].urls.forEach(url => { if (metadata.sources[fileName].urls) {
if (url.includes('ipfs')) hash = url.match('dweb:/ipfs/(.+)')[1] metadata.sources[fileName].urls.forEach(url => {
}) if (url.includes('ipfs')) hash = url.match('dweb:/ipfs/(.+)')[1]
})
}
} catch (e) {
return reject(new Error('Error while extracting the hash from metadata.json'))
} }
} catch (e) {
throw new Error('Error while extracting the hash from metadata.json')
}
api.readFile(fileName).then((content) => { api.readFile(fileName).then((content) => {
sources.push({ sources.push({
content: content, content: content,
hash: hash, hash: hash,
filename: fileName filename: fileName
})
resolve({
content: content,
hash: hash,
filename: fileName
})
}).catch((error) => {
console.log(error)
reject(error)
}) })
}).catch((error) => { })
console.log(error)
})
})) }))
// publish the list of sources in order, fail if any failed // publish the list of sources in order, fail if any failed
await Promise.all(sources.map(async (item) => { await Promise.all(sources.map(async (item) => {

Loading…
Cancel
Save