Merge pull request #2359 from ethereum/pushes_on_several_ipfs_gateways

Push on several ipfs nodes
pull/1/head
yann300 5 years ago committed by GitHub
commit 2a010ad995
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/lib/publishOnIpfs.js

@ -2,8 +2,11 @@
const async = require('async')
const IpfsClient = require('ipfs-mini')
const host = 'ipfs.komputing.org'
const ipfs = new IpfsClient({ host, port: 443, protocol: 'https' })
const ipfsNodes = [
new IpfsClient({ host: 'ipfs.komputing.org', port: 443, protocol: 'https' }),
new IpfsClient({ host: 'ipfs.infura.io', port: 5001, protocol: 'https' })
]
module.exports = (contract, fileManager, cb, ipfsVerifiedPublishCallBack) => {
// gather list of files to publish
@ -89,7 +92,7 @@ module.exports = (contract, fileManager, cb, ipfsVerifiedPublishCallBack) => {
async function ipfsVerifiedPublish (content, expectedHash, cb) {
try {
const results = await ipfs.add(content)
const results = await severalGatewaysPush(content)
if (results !== expectedHash) {
cb(null, { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'dweb:/ipfs/' + results, hash: results })
} else {
@ -99,3 +102,9 @@ async function ipfsVerifiedPublish (content, expectedHash, cb) {
cb(error)
}
}
function severalGatewaysPush (content) {
const invert = p => new Promise((resolve, reject) => p.then(reject).catch(resolve)) // Invert res and rej
const promises = ipfsNodes.map((node) => invert(node.add(content)))
return invert(Promise.all(promises))
}

Loading…
Cancel
Save