main
Harry 2 years ago
parent f829e2baf6
commit b6a009f8d3

@ -35,8 +35,8 @@ contract Git3 {
storageManager = IFileOperator(address(new FlatDirectory(220)));
}
modifier onlyOwner(bytes memory repoName, address memory user) {
require(repoNameToOwner[repoName] == user || repoNameToOwner[repoName] == address(0));
modifier onlyOwner(bytes memory repoName) {
require(repoNameToOwner[repoName] == msg.sender);
_;
}
@ -48,8 +48,15 @@ contract Git3 {
return storageManager.read(bytes.concat(repoName, '/', path));
}
function createRepo(bytes memory repoName)
external payable
{
require(repoNameToOwner[repoName] == address(0));
repoNameToOwner[repoName] = msg.sender;
}
function upload(bytes memory repoName, bytes memory path, bytes memory data)
external payable onlyOwner(repoName, msg.sender)
external payable onlyOwner(repoName)
{
storageManager.writeChunk{value: msg.value}(bytes.concat(repoName, '/', path), 0, data);
}
@ -59,22 +66,22 @@ contract Git3 {
bytes memory path,
uint256 chunkId,
bytes memory data
) external payable onlyOwner(repoName, msg.sender) {
) external payable onlyOwner(repoName) {
storageManager.writeChunk{value: msg.value}(bytes.concat(repoName, '/', path), chunkId, data);
}
function remove(bytes memory repoName, bytes memory path) external onlyOwner(repoName, msg.sender) {
function remove(bytes memory repoName, bytes memory path) external onlyOwner(repoName) {
// The actually process of remove will remove all the chunks
storageManager.remove(bytes.concat(repoName, '/', path));
}
function size(bytes memory name) external view returns (uint256, uint256) {
return storageManager.size(name);
function size(string memory name) external view returns (uint256, uint256) {
return storageManager.size(bytes(name));
}
function countChunks(bytes memory name) external view returns (uint256) {
return storageManager.countChunks(name);
function countChunks(string memory name) external view returns (uint256) {
return storageManager.countChunks(bytes(name));
}
function listRefs() public view returns (refData[] memory list) {
@ -84,7 +91,7 @@ contract Git3 {
}
}
function setRef(bytes memory repoName, bytes memory name, bytes20 refHash) public onlyOwner(repoName, msg.sender) {
function setRef(bytes memory repoName, string memory name, bytes20 refHash) public onlyOwner(repoName) {
// only execute `sload` once to reduce gas consumption
refInfo memory srs;
srs = nameToRefInfo[name];
@ -97,7 +104,6 @@ contract Git3 {
"Refs exceed valid length"
);
repoToOwner
nameToRefInfo[name].hash = refHash;
nameToRefInfo[name].index = uint96(refsLen);
@ -108,7 +114,7 @@ contract Git3 {
}
}
function delRef(bytes memory repoName, bytes memory name) public onlyOwner(repoName, msg.sender) {
function delRef(bytes memory repoName, string memory name) public onlyOwner(repoName) {
// only execute `sload` once to reduce gas consumption
refInfo memory srs;
srs = nameToRefInfo[name];

1403
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -18,10 +18,12 @@
"homepage": "https://github.com/cyl19970726/dGithub#readme",
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@typechain/ethers-v5": "^10.2.0",
"@typechain/hardhat": "^6.1.5",
"dotenv": "^16.0.3",
"hardhat": "^2.12.4",
"hardhat-gas-reporter": "^1.0.9",
"solidity-coverage": "^0.8.2",
"ts-node": "^10.9.1",
"typescript": "^4.9.4"
},
@ -31,6 +33,7 @@
"@nomiclabs/hardhat-etherscan": "^3.1.3",
"@openzeppelin/contracts": "^4.8.0",
"chai": "^4.3.7",
"evm-large-storage": "^1.0.0"
"evm-large-storage": "^1.0.0",
"typechain": "^8.1.1"
}
}

Loading…
Cancel
Save