Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 64 additions & 6 deletions build/index.html

Large diffs are not rendered by default.

67 changes: 23 additions & 44 deletions contracts/WebContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ abstract contract WebContract is TokenManager {

/// @notice Represents a resource file with content chunks and content type
struct ResourceFile {
bytes[] content;
bytes content;
string contentType;
uint8 redirectCode;
}
Expand All @@ -156,66 +156,43 @@ abstract contract WebContract is TokenManager {
/// @param _path Path of the resource
/// @param _content Content of the chunk
/// @param _contentType Content type of the resource
/// @param _chunkIndex Index of the chunk
/// @dev Can only be called by an admin when the contract is not locked
function setResourceChunk(
/// @param _replace Replace or concat the resource
function setResource(
string calldata _path,
bytes calldata _content,
string calldata _contentType,
uint256 _chunkIndex,
bool _replace,
uint8 _redirectCode
) public virtual onlyAdmin notLocked {
ResourceFile storage file = resourceFiles[_path];
bytes[] storage chunks = file.content;

require(bytes(_contentType).length > 0, "Content type is required");

if (bytes(file.contentType).length == 0) {
// If the contentType is not set, this is a new file
if (
keccak256(abi.encode(_contentType)) !=
keccak256(abi.encode(file.contentType))
) {
file.contentType = _contentType;
chunks.push(_content);
}
if (_redirectCode != file.redirectCode) {
file.redirectCode = _redirectCode;
}
if (_replace) {
// If the contentType is not set, this is a new file
file.content = _content;
} else {
require(
keccak256(abi.encodePacked(file.contentType)) == keccak256(abi.encodePacked(_contentType)),
"Content type mismatch"
);

require(_chunkIndex <= chunks.length, "Chunk index out of bounds");

if (keccak256(_content) != keccak256(chunks[_chunkIndex])) {
chunks[_chunkIndex] = _content;
}

if (_redirectCode != file.redirectCode) {
file.redirectCode = _redirectCode;
}
file.content = abi.encodePacked(file.content, _content);
}

emit ResourceChunkSet(_path, _chunkIndex);
}

/// @notice Retrieves a chunk of a resource file
/// @param path Path of the resource
/// @param index Index of the chunk
/// @return bytes memory, string memory The content chunk and content type
function getResourceChunk(
string memory path,
uint256 index
) public view virtual returns (bytes memory, string memory) {
ResourceFile memory file = resourceFiles[path];
require(index < file.content.length, "Chunk index out of bounds");
return (file.content[index], file.contentType);
}

function getResource(
string memory path
) public view virtual returns (uint256, string memory, uint8) {
return (
resourceFiles[path].content.length,
resourceFiles[path].contentType,
resourceFiles[path].redirectCode
);
) public view virtual returns (bytes memory, string memory) {
ResourceFile memory file = resourceFiles[path];
return (file.content, file.contentType);
}

/// @notice Removes a resource
Expand All @@ -228,9 +205,12 @@ abstract contract WebContract is TokenManager {
emit ResourceRemoved(path);
}


/// @dev Emitted when the redirect information is set
event RedirectSet(string redirectValue, string redirectType, uint8 redirectCode);
event RedirectSet(
string redirectValue,
string redirectType,
uint8 redirectCode
);

/// @dev Emitted when the contract is locked
event ContractLocked();
Expand All @@ -252,5 +232,4 @@ abstract contract WebContract is TokenManager {

/// @dev Emitted when a resource is removed
event ResourceRemoved(string path);

}
28 changes: 16 additions & 12 deletions deploy/manifest.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
{
"ipfsFiles": {
"styles.css": "QmZtSFFdtZCq6XpMAjNYPe6BTMZaMtbELEE1sDdiK2dBeZ"
},
"ipfsFiles": {},
"contractFiles": {
"0xc7a7de7c1cf222f9055e488583096cc5b42d722b0a460e1c0510a71433f30556": "index.html",
"0xa30e23c499619e61b0d39dc6e740b2b0867efa9be78c756c50c49655e00ff86f": "index.html",
"0x1dbb756089e9167f3d0d3a0cdc77e434e8e85b66469feadb8ab8795c4342a1d7": "styles.css",
"0x27c5f6520884877b1f4c6b4ce878f2b34d567435afc8a7873ac5f711dbc762b5": "image.png",
"0x68cf56fd48b5670fe2cceb4afbfdc650ba4922380171facad6c02eadabff6f84": "index.html",
"0x5aebc0ce5b7f1881d844d535366da3830c4193dc4d3352a00740bbcd2dfda205": "profile.json",
"0x7c2ef04b46051d3b3d7583fd1aa1278e315f29758c547601d1089053671adc7c": "script.js",
"0xbc7e2d71b3897ad9ded8d4d4a9f092919635d1ae42e8459016a8bd10847e6773": "style.css",
"0x6601e55d28414ca803c25547bde623b5f2893b44964c80ca45f9a6154d6694e5": "index.html"
"0x69c7d2268c63d686d89e0d7a3a7d36913945156ce82218a5f84d580c98347b94": "index.html",
"0xb9f650b2f5204dc8af1c6fc6ad61b541ddecb7e8e025745c785b37cf7d95481e": "index.html",
"0x3c03864d02fe5d40f31cda99c08ab57d8ed92c4ecaab13767d758ad5ce1c8a28": "index.html",
"0x166e6a18b30a070b3f13590c06d27cf18f3da5488ea465ad5d77ca5a69a0f828": "index.html",
"0x2f2ea201fc69cc791d2b93fc0649e96780b4675aae25471d8a73c41232b280a0": "index.html",
"0xec02719a754390ff95cfb312e1388c2da018c7b7467224630babd31813dd6a47": "index.html",
"0x9feb3f7766e86b52319027dc744e3f39ca19ea3b93c3c6dcc88e410e356f751c": "index.html",
"0xb35245ebf87f8e2967f6ab1c4765f956c2f24e31f0b494b13ee0c1586af4dd98": "index.html",
"0x1e3d7b9bfb4def8b51b4288af9a913b73b680c037cf9f3d6ed7af78c463de569": "index.html",
"0x57d7a2aa0b6c7108c88424a85bb01018478f495ad3b5ee384345f3a7027b1da4": "index.html",
"0x794490d530d4d488d617ee1c35095b81e695b312a25e11078376fadb59b85a8f": "index.html",
"0xa5eb5dd5308ce6843988644f5c9c43af0d0b1143ede5746bf8b5bafd44a4e602": "index.html",
"0x3ed3ee767e214776f4f3ab60ff7191dcbdaf5102b8e84fb7c2025fac393c4022": "index.html",
"0x3e99699a41860b2953f73ff68dc82d7bb7802c5cc0ac25f6413d37f54d585efb": "index.html",
"0x5f330300dfa06db510f70868096db93a6dc81fd9ec1449a8f2bbcb9ba76ad447": "index.html"
}
}
10 changes: 10 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ const config: HardhatUserConfig = {
url: process.env.RPC_URL_137 || "",
accounts: [process.env.PRIVATE_KEY || ""],
}
},
etherscan: {
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
apiKey: process.env.ETHERSCAN_API_KEY || "",
},
sourcify: {
// Disabled by default
// Doesn't need an API key
enabled: true
}
};

Expand Down
Loading