diff --git a/contracts/v3/Hubv3.sol b/contracts/v3/Hubv3.sol index 0b063f5..3f4f919 100644 --- a/contracts/v3/Hubv3.sol +++ b/contracts/v3/Hubv3.sol @@ -269,7 +269,7 @@ contract Hubv3 is AccessControlEnumerable, Initializable { bytes memory path, bytes calldata data ) external payable { - return db.upload(repoName, path, data); + return db.upload{value:msg.value}(repoName, path, data); } function uploadChunk( @@ -278,7 +278,7 @@ contract Hubv3 is AccessControlEnumerable, Initializable { uint256 chunkId, bytes calldata data ) external payable { - return db.uploadChunk(repoName, path,chunkId, data); + return db.uploadChunk{value:msg.value}(repoName, path,chunkId, data); } function batchUpload( diff --git a/contracts/v3/database/EthStorage/LargeStorageManagerV2.sol b/contracts/v3/database/EthStorage/LargeStorageManagerV2.sol index 8896343..52aea97 100644 --- a/contracts/v3/database/EthStorage/LargeStorageManagerV2.sol +++ b/contracts/v3/database/EthStorage/LargeStorageManagerV2.sol @@ -22,12 +22,13 @@ contract LargeStorageManagerV2 { function _preparePut(bytes32 key, uint256 chunkId) private { bytes32 metadata = keyToMetadata[key][chunkId]; - if (metadata == bytes32(0)) { - require( - chunkId == 0 || keyToMetadata[key][chunkId - 1] != bytes32(0x0), - "must replace or append" - ); - } + // Remove the following code to support out-of-order upload chunks + // if (metadata == bytes32(0)) { + // require( + // chunkId == 0 || keyToMetadata[key][chunkId - 1] != bytes32(0x0), + // "must replace or append" + // ); + // } if (!metadata.isInSlot()) { address addr = metadata.bytes32ToAddr(); diff --git a/contracts/v3/database/EthStorage/StorageHelperV2.sol b/contracts/v3/database/EthStorage/StorageHelperV2.sol index f638e7c..448c315 100644 --- a/contracts/v3/database/EthStorage/StorageHelperV2.sol +++ b/contracts/v3/database/EthStorage/StorageHelperV2.sol @@ -5,6 +5,7 @@ import "./Memory.sol"; import "./StorageSlotFactory.sol"; library StorageHelperV2 { + uint256 public constant STORAGE_SLOT_CODE_V2_PREFIX_LEN = 280; // StorageSlotSelfDestructableV2 compiled via solc 0.8.7 optimized 200 bytes internal constant STORAGE_SLOT_CODE_V2 = hex"6080604052348015600f57600080fd5b506004361060285760003560e01c80632b68b9c614602d575b600080fd5b60336035565b005b336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161460965760405162461bcd60e51b81526020600482015260036024820152624e464f60e81b604482015260640160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316fffea2646970667358221220154417754813d1989858c876ab2ded2ba1aa380679fff7a4c8faea076ba020e664736f6c63430008070033"; diff --git a/contracts/v3/database/ethstorage.sol b/contracts/v3/database/ethstorage.sol index 1456ce6..7a80126 100644 --- a/contracts/v3/database/ethstorage.sol +++ b/contracts/v3/database/ethstorage.sol @@ -57,7 +57,7 @@ contract ethstorage is LargeStorageManagerV2, database { bytes memory path, uint256 chunkId, bytes calldata data - ) external payable { + ) external payable override{ _putChunkFromCalldata( keccak256(bytes.concat(repoName, "/", path)), chunkId, diff --git a/test/v3-hub-test.js b/test/v3-hub-test.js index 4c6e844..3f3c100 100644 --- a/test/v3-hub-test.js +++ b/test/v3-hub-test.js @@ -227,6 +227,37 @@ describe("Hub V3 Test", function () { expect(refs[0]).to.eql([data3, concatHexStr(repoName, key2)]); }); + it("upload chunks", async function () { + const hubfacFac = await ethers.getContractFactory("HubFactory"); + const hubFac = await hubfacFac.deploy(true); + await hubFac.deployed(); + + await hubFac.newHubImp(); + + expect(await hubFac.createHub(true)).to.emit(hubFac,"CreateHub"); + let hub = await hubFac.hubs(0); + console.log(hub); + let git3 = await ethers.getContractAt("Hubv3",hub) + + let chunk = Buffer.alloc(10 * 1024, Math.random(1024).toString()); + console.log(chunk); + let chunk_1 = Buffer.alloc(5*1024) + let chunk_2 = Buffer.alloc(2*1024) + chunk.copy(chunk_1,0,0,5*1024) + chunk.copy(chunk_2,0,5*1024,7*1024) + expect(chunk.compare(chunk_1,0,5*1024,0,5*1024)).to.eq(0); + expect(chunk.compare(chunk_2,0,2*1024,5*1024,7*1024)).to.eq(0); + expect(chunk.length).to.eq(10 * 1024); + + + + let tx = await git3.uploadChunk(Buffer.from("git3"),Buffer.from("git3/test") ,0,"0x"+chunk.toString("hex"),{value:ethers.utils.parseEther("1")}) + let rec = await tx.wait(); + console.log("Receipt:",rec) + let context = await git3.download(Buffer.from("git3"),Buffer.from("git3/test")) + expect(context[0]).to.equal("0x"+chunk.toString("hex")); + }) + it("HubFactory", async function () { const hubfacFac = await ethers.getContractFactory("HubFactory");