|
|
@ -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) => { |
|
|
|