Merge branch 'latest'

main
cyl19970726 2 years ago
commit d844d782e2

@ -2,6 +2,8 @@
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
contract Git3NameService { contract Git3NameService {
event RegisterHub(string name, address hub);
mapping(string => address) public nameHub; mapping(string => address) public nameHub;
mapping(address => string) public hubName; mapping(address => string) public hubName;
mapping(string => address) public nameOwner; mapping(string => address) public nameOwner;
@ -22,6 +24,7 @@ contract Git3NameService {
hubName[hub] = name; hubName[hub] = name;
nameOwner[name] = msg.sender; nameOwner[name] = msg.sender;
nameList.push(name); nameList.push(name);
emit RegisterHub(name, hub);
} }
function nameListLength() public view returns (uint256) { function nameListLength() public view returns (uint256) {
@ -34,6 +37,7 @@ contract Git3NameService {
) public onlyHubOwner(name) { ) public onlyHubOwner(name) {
nameHub[name] = hub; nameHub[name] = hub;
hubName[hub] = name; hubName[hub] = name;
emit RegisterHub(name, hub);
} }
function transferNameOwner( function transferNameOwner(

@ -12,6 +12,9 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
using EnumerableSet for EnumerableSet.AddressSet; using EnumerableSet for EnumerableSet.AddressSet;
using Repolib for Repolib.BranchInfo; using Repolib for Repolib.BranchInfo;
event RepoCreated(bytes repoName, address owner);
event SetRepoRef(bytes repoName, bytes branchPath, bytes20 refHash);
// Hub Info // Hub Info
// bytes32 public constant CREATOR = bytes32(uint256(1)); // bytes32 public constant CREATOR = bytes32(uint256(1));
bytes32 public constant MANAGER = bytes32(uint256(1)); bytes32 public constant MANAGER = bytes32(uint256(1));
@ -88,10 +91,13 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
return false; return false;
} }
function getMembersByRole(bytes32 role) public view returns(address[] memory members){ function getMembersByRole(
bytes32 role
) public view returns(address[] memory members){
uint256 count = getRoleMemberCount(role); uint256 count = getRoleMemberCount(role);
members = new address[](count); members = new address[](count);
for (uint i = 0; i < count; i++){ for (uint i = 0; i < count; i++) {
members[i] = getRoleMember(role, i); members[i] = getRoleMember(role, i);
} }
} }
@ -126,11 +132,8 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
// ===== repository operator functions====== // ===== repository operator functions======
function repoList() public view returns(string[] memory rn){ function repoList() public view returns (bytes[] memory rn) {
rn = new string[](repoNames.length); return repoNames;
for (uint i = 0; i <repoNames.length;i++){
rn[i] = string(repoNames[i]);
}
} }
//createRepository can be invoked by anyone within Hub //createRepository can be invoked by anyone within Hub
@ -158,6 +161,7 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
repo.owner = _msgSender(); repo.owner = _msgSender();
repo.exist = true; repo.exist = true;
repoNames.push(repoName); repoNames.push(repoName);
emit RepoCreated(repoName, repo.owner);
} }
function deleteRepo(bytes memory repoName) public { function deleteRepo(bytes memory repoName) public {
@ -241,6 +245,7 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
branchPath, branchPath,
refHash refHash
); );
emit SetRepoRef(repoName, branchPath, refHash);
} }
function getRepoRef( function getRepoRef(
@ -285,16 +290,16 @@ contract Hubv3 is AccessControlEnumerable, Initializable {
bytes memory path, bytes memory path,
bytes calldata data bytes calldata data
) external payable { ) external payable {
return db.upload{value:msg.value}(repoName, path, data); return db.upload{value: msg.value}(repoName, path, data);
} }
function uploadChunk( function uploadChunk(
bytes memory repoName, bytes memory repoName,
bytes memory path, bytes memory path,
uint256 chunkId, uint256 chunkId,
bytes calldata data bytes calldata data
) external payable { ) external payable {
return db.uploadChunk{value:msg.value}(repoName, path,chunkId, data); return db.uploadChunk{value: msg.value}(repoName, path, chunkId, data);
} }
function batchUpload( function batchUpload(

@ -24,12 +24,16 @@ contract filecoin is database {
pathToHash[fullName] = data; pathToHash[fullName] = data;
} }
function uploadChunk( function uploadChunk(
bytes memory repoName, bytes memory repoName,
bytes memory path, bytes memory path,
uint256 chunkId, uint256 chunkId,
bytes calldata data bytes calldata data
) external payable override { ) external payable override {
repoName;
path;
chunkId;
data;
revert("unsupport uploadChunk"); revert("unsupport uploadChunk");
} }
} }

@ -22,17 +22,17 @@ async function main() {
await newHubReceipt.wait(); await newHubReceipt.wait();
let createHubReceipt = await hubFac.createHub({ nonce: nonce }); // let createHubReceipt = await hubFac.createHub(false, { nonce: nonce });
nonce++; // nonce++;
await createHubReceipt.wait(); // await createHubReceipt.wait();
let hubAddr = await hubFac.hubs(0); // let hubAddr = await hubFac.hubs(0);
let git3 = await ethers.getContractAt("Hubv3", hubAddr); // let git3 = await ethers.getContractAt("Hubv3", hubAddr);
// console.log({logicReceipt,proxyReceipt}); // console.log({logicReceipt,proxyReceipt});
console.log("HubFactory Contract", hubFac.address); console.log("HubFactory Contract", hubFac.address);
console.log("Hub Contract", git3.address); // console.log("Hub Contract", git3.address);
} }
// We recommend this pattern to be able to use async/await everywhere // We recommend this pattern to be able to use async/await everywhere

@ -20,15 +20,15 @@ async function main() {
let newHubReceipt = await hubFac.newHubImp({ nonce: nonce }); let newHubReceipt = await hubFac.newHubImp({ nonce: nonce });
nonce++; nonce++;
let createHubReceipt = await hubFac.createHub({ nonce: nonce }); // let createHubReceipt = await hubFac.createHub(false, { nonce: nonce });
nonce++; // nonce++;
let hubAddr = await hubFac.hubs(0); // let hubAddr = await hubFac.hubs(0);
let git3 = await ethers.getContractAt("Hubv3", hubAddr); // let git3 = await ethers.getContractAt("Hubv3", hubAddr);
// console.log({logicReceipt,proxyReceipt}); // console.log({logicReceipt,proxyReceipt});
console.log("HubFactory Contract", hubFac.address); console.log("HubFactory Contract", hubFac.address);
console.log("Hub Contract", git3.address); // console.log("Hub Contract", git3.address);
} }
// We recommend this pattern to be able to use async/await everywhere // We recommend this pattern to be able to use async/await everywhere

Loading…
Cancel
Save