fetch from IPFS

Aniket-Engg-patch-1
aniket-engg 10 months ago committed by Aniket
parent cd4f71a190
commit d12b1e9218
  1. 3
      libs/remix-ui/workspace/src/lib/actions/index.ts
  2. 27
      libs/remix-ui/workspace/src/lib/actions/workspace.ts

@ -22,6 +22,7 @@ let plugin, dispatch: React.Dispatch<Actions>
export type UrlParametersType = {
gist: string,
code: string,
shareCode: string,
url: string,
address: string
opendir: string,
@ -75,7 +76,7 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
plugin.setWorkspace({ name: 'code-sample', isLocalhost: false })
dispatch(setCurrentWorkspace({ name: 'code-sample', isGitRepo: false }))
await loadWorkspacePreset('gist-template')
} else if (params.code || params.url) {
} else if (params.code || params.url || params.shareCode) {
await createWorkspaceTemplate('code-sample', 'code-template')
plugin.setWorkspace({ name: 'code-sample', isLocalhost: false })
dispatch(setCurrentWorkspace({ name: 'code-sample', isGitRepo: false }))

@ -3,6 +3,7 @@ import { bufferToHex } from '@ethereumjs/util'
import { hash } from '@remix-project/remix-lib'
import { TEMPLATE_METADATA, TEMPLATE_NAMES } from '../utils/constants'
import { TemplateType } from '../utils/types'
import IpfsHttpClient from 'ipfs-http-client'
import axios, { AxiosResponse } from 'axios'
import {
addInputFieldSuccess,
@ -234,6 +235,7 @@ export const createWorkspaceTemplate = async (workspaceName: string, template: W
export type UrlParametersType = {
gist: string
code: string
shareCode: string
url: string
language: string
}
@ -257,6 +259,31 @@ export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDe
content = atob(decodeURIComponent(params.code))
await workspaceProvider.set(path, content)
}
if (params.shareCode) {
console.log('inside params.shareCode------>', params.shareCode)
const host = '127.0.0.1'
const port = 5001
const protocol = 'http'
// const projectId = ''
// const projectSecret = ''
// const auth = 'Basic ' + Buffer.from(projectId + ':' + projectSecret).toString('base64')
const ipfs = IpfsHttpClient({ port, host, protocol
, headers: {
// authorization: auth
}
})
const hashed = bufferToHex(hash.keccakFromString(params.shareCode))
path = 'contract-' + hashed.replace('0x', '').substring(0, 10) + (params.language && params.language.toLowerCase() === 'yul' ? '.yul' : '.sol')
const fileData = ipfs.get(params.shareCode)
for await (const file of fileData) {
const fileContent = []
for await (const chunk of file.content) fileContent.push(chunk)
content = Buffer.concat(fileContent).toString()
}
await workspaceProvider.set(path, content)
}
if (params.url) {
const data = await plugin.call('contentImport', 'resolve', params.url)

Loading…
Cancel
Save