|
|
@ -20,6 +20,7 @@ contract Git3 {
|
|
|
|
string name;
|
|
|
|
string name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mapping(bytes => address) public repoNameToOwner;
|
|
|
|
mapping(string => refInfo) public nameToRefInfo; // dev => {hash: 0x1234..., index: 1 }
|
|
|
|
mapping(string => refInfo) public nameToRefInfo; // dev => {hash: 0x1234..., index: 1 }
|
|
|
|
string[] public refs; // [main, dev, test, staging]
|
|
|
|
string[] public refs; // [main, dev, test, staging]
|
|
|
|
|
|
|
|
|
|
|
@ -34,28 +35,38 @@ contract Git3 {
|
|
|
|
storageManager = IFileOperator(address(new FlatDirectory(220)));
|
|
|
|
storageManager = IFileOperator(address(new FlatDirectory(220)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
modifier onlyOwner(bytes memory repoName, address memory user) {
|
|
|
|
|
|
|
|
require(repoNameToOwner[repoName] == user || repoNameToOwner[repoName] == address(0));
|
|
|
|
|
|
|
|
_;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function download(
|
|
|
|
function download(
|
|
|
|
|
|
|
|
bytes memory repoName,
|
|
|
|
bytes memory path
|
|
|
|
bytes memory path
|
|
|
|
) external view returns (bytes memory, bool) {
|
|
|
|
) external view returns (bytes memory, bool) {
|
|
|
|
// call flat directory(FD)
|
|
|
|
// call flat directory(FD)
|
|
|
|
return storageManager.read(path);
|
|
|
|
return storageManager.read(bytes.concat(repoName, '/', path));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function upload(bytes memory path, bytes memory data) external payable {
|
|
|
|
function upload(bytes memory repoName, bytes memory path, bytes memory data)
|
|
|
|
storageManager.writeChunk{value: msg.value}(path, 0, data);
|
|
|
|
external payable onlyOwner(repoName, msg.sender)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
storageManager.writeChunk{value: msg.value}(bytes.concat(repoName, '/', path), 0, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function uploadChunk(
|
|
|
|
function uploadChunk(
|
|
|
|
|
|
|
|
bytes memory repoName,
|
|
|
|
bytes memory path,
|
|
|
|
bytes memory path,
|
|
|
|
uint256 chunkId,
|
|
|
|
uint256 chunkId,
|
|
|
|
bytes memory data
|
|
|
|
bytes memory data
|
|
|
|
) external payable {
|
|
|
|
) external payable onlyOwner(repoName, msg.sender) {
|
|
|
|
storageManager.writeChunk{value: msg.value}(path, chunkId, data);
|
|
|
|
storageManager.writeChunk{value: msg.value}(bytes.concat(repoName, '/', path), chunkId, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function remove(bytes memory path) external {
|
|
|
|
function remove(bytes memory repoName, bytes memory path) external onlyOwner(repoName, msg.sender) {
|
|
|
|
|
|
|
|
|
|
|
|
// The actually process of remove will remove all the chunks
|
|
|
|
// The actually process of remove will remove all the chunks
|
|
|
|
storageManager.remove(path);
|
|
|
|
storageManager.remove(bytes.concat(repoName, '/', path));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function size(bytes memory name) external view returns (uint256, uint256) {
|
|
|
|
function size(bytes memory name) external view returns (uint256, uint256) {
|
|
|
@ -73,7 +84,7 @@ contract Git3 {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setRef(string memory name, bytes20 refHash) public {
|
|
|
|
function setRef(bytes memory repoName, bytes memory name, bytes20 refHash) public onlyOwner(repoName, msg.sender) {
|
|
|
|
// only execute `sload` once to reduce gas consumption
|
|
|
|
// only execute `sload` once to reduce gas consumption
|
|
|
|
refInfo memory srs;
|
|
|
|
refInfo memory srs;
|
|
|
|
srs = nameToRefInfo[name];
|
|
|
|
srs = nameToRefInfo[name];
|
|
|
@ -86,6 +97,7 @@ contract Git3 {
|
|
|
|
"Refs exceed valid length"
|
|
|
|
"Refs exceed valid length"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
repoToOwner
|
|
|
|
nameToRefInfo[name].hash = refHash;
|
|
|
|
nameToRefInfo[name].hash = refHash;
|
|
|
|
nameToRefInfo[name].index = uint96(refsLen);
|
|
|
|
nameToRefInfo[name].index = uint96(refsLen);
|
|
|
|
|
|
|
|
|
|
|
@ -96,7 +108,7 @@ contract Git3 {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function delRef(string memory name) public {
|
|
|
|
function delRef(bytes memory repoName, bytes memory name) public onlyOwner(repoName, msg.sender) {
|
|
|
|
// only execute `sload` once to reduce gas consumption
|
|
|
|
// only execute `sload` once to reduce gas consumption
|
|
|
|
refInfo memory srs;
|
|
|
|
refInfo memory srs;
|
|
|
|
srs = nameToRefInfo[name];
|
|
|
|
srs = nameToRefInfo[name];
|
|
|
|