Merge pull request #2461 from ethereum/save_to_fe

save published file to FE
pull/5370/head
yann300 3 years ago committed by GitHub
commit 64f353deb5
  1. 8
      apps/remix-ide-e2e/src/tests/publishContract.test.ts
  2. 12
      libs/remix-ui/publish-to-storage/src/lib/publish-to-storage.tsx
  3. 9
      libs/remix-ui/publish-to-storage/src/lib/publishOnSwarm.tsx
  4. 9
      libs/remix-ui/publish-to-storage/src/lib/publishToIPFS.tsx

@ -25,11 +25,13 @@ module.exports = {
const value = <string>(result.value) const value = <string>(result.value)
browser.perform((done) => { browser.perform((done) => {
if (value.indexOf('Metadata of "ballot" was published successfully.') === -1) browser.assert.fail('ipfs deploy failed') if (value.indexOf('Metadata and sources of "ballot" were published successfully.') === -1) browser.assert.fail('ipfs deploy failed')
done() done()
}) })
}) })
.click('[data-id="publishToStorage-modal-footer-ok-react"]') .click('[data-id="publishToStorage-modal-footer-ok-react"]')
.openFile('ipfs/QmSUodhSvoorFL5m5CNqve8YvmuBpjCq17NbTf4GUX8ydw')
.openFile('ipfs/QmXYUS1ueS22EqNVRaKuZa31EgHLjKZ8uTM8vWhQLxa3pw')
}, },
/* Disableing the test untill refactoring and the new swarm usage /* Disableing the test untill refactoring and the new swarm usage
@ -41,7 +43,7 @@ module.exports = {
const value = <string>(result.value) const value = <string>(result.value)
browser.perform((done) => { browser.perform((done) => {
if (value.indexOf('Metadata of "ballot" was published successfully.') === -1) browser.assert.fail('swarm deploy failed') if (value.indexOf('Metadata and sources of "ballot" were published successfully.') === -1) browser.assert.fail('swarm deploy failed')
if (value.indexOf('bzz') === -1) browser.assert.fail('swarm deploy failed') if (value.indexOf('bzz') === -1) browser.assert.fail('swarm deploy failed')
done() done()
}) })
@ -65,7 +67,7 @@ module.exports = {
.getText('[data-id="udappModalDialogModalBody-react"]', (result) => { .getText('[data-id="udappModalDialogModalBody-react"]', (result) => {
const value = typeof result.value === 'string' ? result.value : null const value = typeof result.value === 'string' ? result.value : null
if (value.indexOf('Metadata of "storage" was published successfully.') === -1) browser.assert.fail('ipfs deploy failed') if (value.indexOf('Metadata and sources of "storage" were published successfully.') === -1) browser.assert.fail('ipfs deploy failed')
}) })
.modalFooterOKClick('udapp') .modalFooterOKClick('udapp')
}, },

@ -28,9 +28,7 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => {
try { try {
const result = await publishToSwarm(contract, api) const result = await publishToSwarm(contract, api)
modal(`Published ${contract.name}'s Metadata`, publishMessage(result.uploaded)) modal(`Published ${contract.name}'s Metadata and Sources`, publishMessage(result.uploaded))
// triggered each time there's a new verified publish (means hash correspond)
api.writeFile('swarm/' + result.item.hash, result.item.content)
} catch (err) { } catch (err) {
let parseError = err let parseError = err
try { try {
@ -43,9 +41,7 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => {
try { try {
const result = await publishToIPFS(contract, api) const result = await publishToIPFS(contract, api)
modal(`Published ${contract.name}'s Metadata`, publishMessage(result.uploaded)) modal(`Published ${contract.name}'s Metadata and Sources`, publishMessage(result.uploaded))
// triggered each time there's a new verified publish (means hash correspond)
api.writeFile('ipfs/' + result.item.hash, result.item.content)
} catch (err) { } catch (err) {
modal('IPFS Publish Failed', publishMessageFailed(storage, err)) modal('IPFS Publish Failed', publishMessageFailed(storage, err))
} }
@ -59,7 +55,7 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => {
}, [storage]) }, [storage])
const publishMessage = (uploaded) => ( const publishMessage = (uploaded) => (
<span> Metadata of "{contract.name.toLowerCase()}" was published successfully. <br /> <span> Metadata and sources of "{contract.name.toLowerCase()}" were published successfully. <br />
<pre> <pre>
<div> <div>
{ uploaded.map((value, index) => <div key={index}><b>{ value.filename }</b> : <pre>{ value.output.url }</pre></div>) } { uploaded.map((value, index) => <div key={index}><b>{ value.filename }</b> : <pre>{ value.output.url }</pre></div>) }
@ -69,7 +65,7 @@ export const PublishToStorage = (props: RemixUiPublishToStorageProps) => {
) )
const publishMessageFailed = (storage, err) => ( const publishMessageFailed = (storage, err) => (
<span>Failed to publish metadata file to { storage }, please check the { storage } gateways is available. <br /> <span>Failed to publish metadata file and sources to { storage }, please check the { storage } gateways is available. <br />
{err} {err}
</span> </span>
) )

@ -79,7 +79,7 @@ export const publishToSwarm = async (contract, api) => {
// 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) => {
try { try {
const result = await swarmVerifiedPublish(beeNodes, postageStampId, item.content, item.hash) const result = await swarmVerifiedPublish(beeNodes, postageStampId, item.content, item.hash, api)
try { try {
item.hash = result.url.match('bzz-raw://(.+)')[1] item.hash = result.url.match('bzz-raw://(.+)')[1]
@ -96,9 +96,9 @@ export const publishToSwarm = async (contract, api) => {
} }
})) }))
const metadataContent = JSON.stringify(metadata) const metadataContent = JSON.stringify(metadata, null, '\t')
try { try {
const result = await swarmVerifiedPublish(beeNodes, postageStampId, metadataContent, '') const result = await swarmVerifiedPublish(beeNodes, postageStampId, metadataContent, '', api)
try { try {
contract.metadataHash = result.url.match('bzz-raw://(.+)')[1] contract.metadataHash = result.url.match('bzz-raw://(.+)')[1]
@ -121,7 +121,7 @@ export const publishToSwarm = async (contract, api) => {
return { uploaded, item } return { uploaded, item }
} }
const swarmVerifiedPublish = async (beeNodes: Bee[], postageStampId: string, content, expectedHash): Promise<Record<string, any>> => { const swarmVerifiedPublish = async (beeNodes: Bee[], postageStampId: string, content, expectedHash, api): Promise<Record<string, any>> => {
try { try {
const results = await uploadToBeeNodes(beeNodes, postageStampId, content) const results = await uploadToBeeNodes(beeNodes, postageStampId, content)
const hash = hashFromResults(results) const hash = hashFromResults(results)
@ -129,6 +129,7 @@ const swarmVerifiedPublish = async (beeNodes: Bee[], postageStampId: string, con
if (expectedHash && hash !== expectedHash) { if (expectedHash && hash !== expectedHash) {
return { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'bzz-raw://' + hash, hash } return { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'bzz-raw://' + hash, hash }
} else { } else {
api.writeFile('swarm/' + hash, content)
return { message: 'ok', url: 'bzz-raw://' + hash, hash } return { message: 'ok', url: 'bzz-raw://' + hash, hash }
} }
} catch (error) { } catch (error) {

@ -63,7 +63,7 @@ export const publishToIPFS = async (contract, api) => {
// 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) => {
try { try {
const result = await ipfsVerifiedPublish(item.content, item.hash) const result = await ipfsVerifiedPublish(item.content, item.hash, api)
try { try {
item.hash = result.url.match('dweb:/ipfs/(.+)')[1] item.hash = result.url.match('dweb:/ipfs/(.+)')[1]
@ -76,10 +76,10 @@ export const publishToIPFS = async (contract, api) => {
throw new Error(error) throw new Error(error)
} }
})) }))
const metadataContent = JSON.stringify(metadata) const metadataContent = JSON.stringify(metadata, null, '\t')
try { try {
const result = await ipfsVerifiedPublish(metadataContent, '') const result = await ipfsVerifiedPublish(metadataContent, '', api)
try { try {
contract.metadataHash = result.url.match('dweb:/ipfs/(.+)')[1] contract.metadataHash = result.url.match('dweb:/ipfs/(.+)')[1]
@ -101,13 +101,14 @@ export const publishToIPFS = async (contract, api) => {
return { uploaded, item } return { uploaded, item }
} }
const ipfsVerifiedPublish = async (content, expectedHash) => { const ipfsVerifiedPublish = async (content, expectedHash, api) => {
try { try {
const results = await severalGatewaysPush(content) const results = await severalGatewaysPush(content)
if (expectedHash && results !== expectedHash) { if (expectedHash && results !== expectedHash) {
return { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'dweb:/ipfs/' + results, hash: results } return { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'dweb:/ipfs/' + results, hash: results }
} else { } else {
api.writeFile('ipfs/' + results, content)
return { message: 'ok', url: 'dweb:/ipfs/' + results, hash: results } return { message: 'ok', url: 'dweb:/ipfs/' + results, hash: results }
} }
} catch (error) { } catch (error) {

Loading…
Cancel
Save