From a00d6ff0e651c920a35a28955ec5a312a84cd914 Mon Sep 17 00:00:00 2001 From: "iteyelmp@gmail.com" Date: Wed, 11 Jan 2023 15:09:00 +0800 Subject: [PATCH 1/4] support Arbitrum Nova --- src/components/Wallet.vue | 18 ++++++++---------- src/components/w3q-deployer.vue | 4 ++-- src/store/state.js | 11 ++++++----- src/utils/request.js | 21 ++++++++------------- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/components/Wallet.vue b/src/components/Wallet.vue index 4b876fb..8ff96de 100644 --- a/src/components/Wallet.vue +++ b/src/components/Wallet.vue @@ -10,8 +10,6 @@
@@ -28,10 +26,10 @@ export class UnsupportedChainIdError extends Error { } } -const chain = 3334; +const chain = 421613; const chainID = `0x${chain.toString(16)}`; -const nodes = ['https://galileo.web3q.io:8545'] -const explorers = [`https://explorer.galileo.web3q.io/`]; +const nodes = ['https://nova.arbitrum.io/rpc'] +const explorers = ['https://nova.arbiscan.io/']; export default { name: "Wallet", @@ -62,7 +60,7 @@ export default { ...mapActions(["setChainConfig", "setAccount"]), connectWallet() { if (!window.ethereum) { - this.$message.error('Can\'t setup the Web3Q network on metamask because window.ethereum is undefined'); + this.$message.error('Can\'t setup the Arbitrum Nova network on metamask because window.ethereum is undefined'); return; } this.login(); @@ -138,10 +136,10 @@ export default { params: [ { chainId: chainID, - chainName: 'Web3Q Galileo', + chainName: 'Arbitrum Nova', nativeCurrency: { - name: 'W3Q', - symbol: 'W3Q', + name: 'ETH', + symbol: 'ETH', decimals: 18, }, rpcUrls: nodes, @@ -160,7 +158,7 @@ export default { return false } } else { - this.$message.error('Can\'t setup the Web3Q network on metamask because window.ethereum is undefined'); + this.$message.error('Can\'t setup the Arbitrum Nova network on metamask because window.ethereum is undefined'); return false } }, diff --git a/src/components/w3q-deployer.vue b/src/components/w3q-deployer.vue index af6702e..19a6f90 100644 --- a/src/components/w3q-deployer.vue +++ b/src/components/w3q-deployer.vue @@ -120,8 +120,8 @@ export default { }, normalizeFiles (rawFile) { let chunkSize = 1; - if (rawFile.size > 475 * 1024) { - chunkSize = Math.ceil(rawFile.size / (475 * 1024)); + if (rawFile.size > 24 * 1024 - 326) { + chunkSize = Math.ceil(rawFile.size / (24 * 1024 - 326)); } const file = { name: rawFile.name, diff --git a/src/store/state.js b/src/store/state.js index 50e983c..f2cf012 100644 --- a/src/store/state.js +++ b/src/store/state.js @@ -1,8 +1,9 @@ -export const chains = [{ - chainID: '0x14d', - FileBoxController:'0xCD469d20bc4da5F97DC350FDB02D6370559C9511', +export const chains = [ +{ + chainID: '0x66eed', // arb-gorli + FileBoxController:'0xDd57e21ce75C9C28205032B3b3510da9523764d2', }, { - chainID: '0xd06', - FileBoxController:'0x731Cd5311e9bAd1E99e7F1081A91a38c02b5F47d', + chainID: '0xa4ba', // nova + FileBoxController: '0x731Cd5311e9bAd1E99e7F1081A91a38c02b5F47d', }]; diff --git a/src/utils/request.js b/src/utils/request.js index fb0b2f0..52090e1 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -8,7 +8,8 @@ const FileContractInfo = { "function removes(bytes[] memory names) public", "function countChunks(bytes memory name) external view returns (uint256)", "function getChunkHash(bytes memory name, uint256 chunkId) public view returns (bytes32)", - "function getAuthorFiles(address author) public view returns (uint256[] memory times,bytes[] memory names,bytes[] memory types,string[] memory urls)" + "function getAuthorFiles(address author) public view returns (uint256[] memory times,bytes[] memory names,bytes[] memory types,string[] memory urls)", + "function gateway() public view returns (string memory)" ], }; @@ -90,12 +91,11 @@ const request = async ({ const hexName = stringToHex(name); const hexType = stringToHex(rawFile.type); // Data need to be sliced if file > 475K - let fileSize = rawFile.size; + const fileSize = rawFile.size; let chunks = []; - if (fileSize > 475 * 1024) { - const chunkSize = Math.ceil(fileSize / (475 * 1024)); + if (fileSize > 24 * 1024 - 326) { + const chunkSize = Math.ceil(fileSize / (24 * 1024 - 326)); chunks = bufferChunk(content, chunkSize); - fileSize = fileSize / chunkSize; } else { chunks.push(content); } @@ -110,10 +110,6 @@ const request = async ({ let uploadState = true; for (const index in chunks) { const chunk = chunks[index]; - let cost = 0; - if (fileSize > 24 * 1024 - 326) { - cost = Math.floor((fileSize + 326) / 1024 / 24); - } const hexData = '0x' + chunk.toString('hex'); const localHash = '0x' + sha3(chunk); const hash = await fileContract.getChunkHash(hexName, index); @@ -125,9 +121,7 @@ const request = async ({ try { // file is remove or change - const tx = await fileContract.writeChunk(hexName, hexType, index, hexData, { - value: ethers.utils.parseEther(cost.toString()) - }); + const tx = await fileContract.writeChunk(hexName, hexType, index, hexData); console.log(`Transaction Id: ${tx.hash}`); const receipt = await tx.wait(); if (!receipt.status) { @@ -141,7 +135,8 @@ const request = async ({ } } if (uploadState) { - const url = "https://galileo.web3q.io/file.w3q/" + account + "/" + name; + const gateway = await fileContract.gateway(); + const url = gateway + account + "/" + name; onSuccess({ path: url}); } else { onError(new Error('upload request failed!')); From b4c75b3b1610546bf9914bf8688b3b9201dca13d Mon Sep 17 00:00:00 2001 From: "iteyelmp@gmail.com" Date: Wed, 11 Jan 2023 16:34:14 +0800 Subject: [PATCH 2/4] support Arbitrum Goerli --- src/page/Profile.vue | 7 +++++++ src/store/state.js | 2 +- src/utils/profile.js | 16 +++++++++++----- src/utils/request.js | 24 ++++++++++++++++++++---- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/page/Profile.vue b/src/page/Profile.vue index c1988f0..724bec1 100644 --- a/src/page/Profile.vue +++ b/src/page/Profile.vue @@ -329,6 +329,13 @@ export default { width: 190px; text-align: left; } +a { + color: #2dce89; +} +a:hover { + color: #2dce8990; +} + .go-upload-list-item-delete { font-size: 20px; width: 30px; diff --git a/src/store/state.js b/src/store/state.js index f2cf012..1afb511 100644 --- a/src/store/state.js +++ b/src/store/state.js @@ -1,7 +1,7 @@ export const chains = [ { chainID: '0x66eed', // arb-gorli - FileBoxController:'0xDd57e21ce75C9C28205032B3b3510da9523764d2', + FileBoxController:'0x50391dAD45F1974B0C4904d7388Fda37086c50E4', }, { chainID: '0xa4ba', // nova diff --git a/src/utils/profile.js b/src/utils/profile.js index 53a3349..d22ba59 100644 --- a/src/utils/profile.js +++ b/src/utils/profile.js @@ -1,20 +1,26 @@ -import { FileContract } from "./request"; +import {ethers} from "ethers"; +import { FileContract, getGateway } from "./request"; + +const hexToString = (h) => ethers.utils.toUtf8String(h); // contract export const getUploadByAddress = async (controller, address) => { const fileContract = FileContract(controller); - const result = await fileContract.getAuthorFiles(address); + const [chainId, fileFD, result] = await Promise.all([ + window.ethereum.request({method: "eth_chainId"}), + fileContract.fileFD(), + fileContract.getAuthorFiles(address), + ]); const files = []; const times = result[0]; const names = result[1]; const types = result[2]; - const urls = result[3]; - for (let i = 0; i < urls.length; i++) { + for (let i = 0; i < names.length; i++) { const file = { time: new Date(parseInt(times[i], 10) * 1000), name: names[i], type: types[i], - url: urls[i], + url: getGateway(chainId, fileFD) + address + "/" + hexToString(names[i]), showProgress: false }; files.push(file); diff --git a/src/utils/request.js b/src/utils/request.js index 52090e1..52aa8b6 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -8,8 +8,8 @@ const FileContractInfo = { "function removes(bytes[] memory names) public", "function countChunks(bytes memory name) external view returns (uint256)", "function getChunkHash(bytes memory name, uint256 chunkId) public view returns (bytes32)", - "function getAuthorFiles(address author) public view returns (uint256[] memory times,bytes[] memory names,bytes[] memory types,string[] memory urls)", - "function gateway() public view returns (string memory)" + "function getAuthorFiles(address author) public view returns (uint256[] memory times,bytes[] memory names,bytes[] memory types)", + "function fileFD() public view returns (address)" ], }; @@ -21,6 +21,19 @@ export const FileContract = (address) => { return contract.connect(provider.getSigner()); }; +export const getGateway = (chainId, fileFD) => { + // https://0xdc245a328fda8205846fad9e6421a27f7b07a912.arb-goerli.w3link.io/ + switch (chainId) { + case "0xd06": + return "https://file.w3q.w3q-g.w3link.io/"; + case "0x66eed": + return "https://" + fileFD + ".arb-goerli.w3link.io/"; + case "0xa4ba": + return "https://" + fileFD + ".arb-nova.w3link.io/"; + } + return ""; +} + const readFile = (file) => { return new Promise((resolve) => { const reader = new FileReader(); @@ -135,8 +148,11 @@ const request = async ({ } } if (uploadState) { - const gateway = await fileContract.gateway(); - const url = gateway + account + "/" + name; + const [chainId, fileFD] = await Promise.all([ + window.ethereum.request({method: "eth_chainId"}), + fileContract.fileFD(), + ]); + const url = getGateway(chainId, fileFD) + account + "/" + name; onSuccess({ path: url}); } else { onError(new Error('upload request failed!')); From 673644238b5812484aff924de27534c79fe57533 Mon Sep 17 00:00:00 2001 From: "iteyelmp@gmail.com" Date: Wed, 11 Jan 2023 17:34:10 +0800 Subject: [PATCH 3/4] fix rpc error --- src/components/Wallet.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/Wallet.vue b/src/components/Wallet.vue index 8ff96de..7bd5595 100644 --- a/src/components/Wallet.vue +++ b/src/components/Wallet.vue @@ -28,8 +28,10 @@ export class UnsupportedChainIdError extends Error { const chain = 421613; const chainID = `0x${chain.toString(16)}`; -const nodes = ['https://nova.arbitrum.io/rpc'] -const explorers = ['https://nova.arbiscan.io/']; +// const nodes = ['https://nova.arbitrum.io/rpc'] +// const explorers = ['https://nova.arbiscan.io/']; +const nodes = ['https://goerli-rollup.arbitrum.io/rpc/'] +const explorers = ['https://goerli-rollup-explorer.arbitrum.io/']; export default { name: "Wallet", From b2fcddc7c30aeb5bff6e5055d7e4cacfd30a5f38 Mon Sep 17 00:00:00 2001 From: "iteyelmp@gmail.com" Date: Wed, 11 Jan 2023 18:00:22 +0800 Subject: [PATCH 4/4] change text --- package.json | 2 +- src/App.vue | 7 +++++-- src/page/Home.vue | 2 +- yarn.lock | 8 ++++---- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 18f0fe5..9456a29 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,9 @@ "@vue/cli-plugin-eslint": "~4.5.7", "@vue/cli-service": "~4.5.7", "babel-eslint": "^10.1.0", - "ethfs-uploader": "^1.0.0", "eslint": "^6.7.2", "eslint-plugin-vue": "^6.2.2", + "ethfs-uploader": "^1.1.8", "vue-template-compiler": "^2.6.11" }, "eslintConfig": { diff --git a/src/App.vue b/src/App.vue index f10889c..c129922 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,7 +1,10 @@