Skip to content

Chunk numbering edits#1

Open
nickjuntilla wants to merge 2 commits intoTechnicallyWeb3:mainfrom
nickjuntilla:chunk-numbering-edits
Open

Chunk numbering edits#1
nickjuntilla wants to merge 2 commits intoTechnicallyWeb3:mainfrom
nickjuntilla:chunk-numbering-edits

Conversation

@nickjuntilla
Copy link

What I discovered when testing the chunking system was that any time you query bytes[] with any index, i.e. bytes[0], bytes[1] etc.. the entire bytes array was returned. The tests and javascript writing function would then slice just the part of the returned array to check if the chunk matched, but the entire array was always returned.

I also discovered that chunks past the first index would always fail because solidity does not appear to let you write to any specific index in a variable bytes array so very long files would fail. You can test this by using the long index file in this pull request on the current web-contract main branch. The error you may encounter will be ProviderError: execution reverted: out-of-bounds access of an array or bytesN but it's currently hidden unless you show the error on line 167 of writeToContract.ts in the main branch. So you must console log this error or it will just say "File not found with index /" when you try to write a very long file.

Anyway all of this is just my suggestion and it simplifies to getResource and setResource while still keeping the chunking which I think is elegant. The next step would be to add a fallback() function that points to getResource(/) to be more compatible with 4804 just in case. Feedback welcome.

…s getResource will always return the full file. Bytes[i] brought back the full file as well. Tests and the browser would need to be updated to accept this change.
@nickjuntilla
Copy link
Author

Oh I also changed optionalPositionParameter to optionParameter on these lines:

.addPositionalParam("filePath", "Relative path of the file to upload (from build folder)", "", types.string)
.addPositionalParam("key", "Key to write the file to in the contract", "", types.string)

Because when I tried a command like this
npx hardhat write-to-contract "index.html" "/" --network polygon
I would get an error saying -- was not valid or something like that so I switched to

.addOptionalParam("filePath", "Relative path of the file to upload (from build folder)", "", types.string)
.addOptionalParam("key", "Key to write the file to in the contract", "", types.string)

And then I could do
npx hardhat write-to-contract --file-path "index.html" --key "/" --network polygon
And it would work fine.

If you can get the optional position parameters to work with 2 parameters and a network flag it's all good with me.

@nickjuntilla
Copy link
Author

Oh I also added hardhat verify and typechain. I think typechain should be in dev dependencies since it's needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant