opt factory

main
cyhhao 2 years ago
parent a2b9329a79
commit 22d19ea1fb

@ -1,4 +1,4 @@
//SPDX-License-Identifier: Unlicense //SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
// import "hardhat/console.sol"; // import "hardhat/console.sol";

@ -1,4 +1,4 @@
//SPDX-License-Identifier: Unlicense //SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
contract Git3HubStorage_SLI { contract Git3HubStorage_SLI {

@ -1,4 +1,4 @@
//SPDX-License-Identifier: Unlicense //SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
contract Hello{ contract Hello{

@ -3,6 +3,7 @@ pragma solidity ^0.8.0;
contract Git3NameService { contract Git3NameService {
mapping(string => address) public nameHub; mapping(string => address) public nameHub;
mapping(address => string) public hubName;
mapping(string => address) public nameOwner; mapping(string => address) public nameOwner;
string[] public nameList; string[] public nameList;
@ -18,6 +19,7 @@ contract Git3NameService {
function registerHub(string memory name, address hub) public { function registerHub(string memory name, address hub) public {
require(nameHub[name] == address(0), "Name already registered"); require(nameHub[name] == address(0), "Name already registered");
nameHub[name] = hub; nameHub[name] = hub;
hubName[hub] = name;
nameOwner[name] = msg.sender; nameOwner[name] = msg.sender;
nameList.push(name); nameList.push(name);
} }
@ -31,6 +33,7 @@ contract Git3NameService {
address hub address hub
) public onlyHubOwner(name) { ) public onlyHubOwner(name) {
nameHub[name] = hub; nameHub[name] = hub;
hubName[hub] = name;
} }
function transferNameOwner( function transferNameOwner(

@ -1,3 +1,4 @@
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
// import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; // import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
@ -8,12 +9,14 @@ import "./Hubv3.sol";
contract HubFactory is Ownable { contract HubFactory is Ownable {
event CreateHub(address indexed hub, address indexed creator); event CreateHub(address indexed hub, address indexed creator);
bool public dbSelector;
address[] public hubs; address[] public hubs;
Hubv3 public hubImp; Hubv3 public hubImp;
// function initialize() initializer public { constructor(bool _dbSelector) {
// __Ownable_init(); dbSelector = _dbSelector;
// } }
function newHubImp() public onlyOwner { function newHubImp() public onlyOwner {
hubImp = new Hubv3(); hubImp = new Hubv3();
@ -23,10 +26,10 @@ contract HubFactory is Ownable {
hubImp = Hubv3(addr); hubImp = Hubv3(addr);
} }
function createHub(bool dbSelector) external { function createHub(bool isPermissionless) external{
address instance = Clones.clone(address(hubImp)); address instance = Clones.clone(address(hubImp));
hubs.push(instance); hubs.push(instance);
Hubv3(instance).initialize(dbSelector, _msgSender()); Hubv3(instance).initialize(dbSelector, _msgSender(), isPermissionless);
emit CreateHub(instance, _msgSender()); emit CreateHub(instance, _msgSender());
} }
} }

@ -1,3 +1,4 @@
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/AccessControl.sol"; import "@openzeppelin/contracts/access/AccessControl.sol";
@ -41,11 +42,16 @@ contract Hubv3 is AccessControl, Initializable {
_setRoleAdmin(CONTRIBUTOR, MANAGER); _setRoleAdmin(CONTRIBUTOR, MANAGER);
} }
function initialize(bool dbSelector, address user) public initializer { function initialize(
bool dbSelector,
address user,
bool isPermissionless
) public initializer {
_setupRole(AccessControl.DEFAULT_ADMIN_ROLE, user); _setupRole(AccessControl.DEFAULT_ADMIN_ROLE, user);
_setupRole(MANAGER, user); _setupRole(MANAGER, user);
_setRoleAdmin(CONTRIBUTOR, MANAGER); _setRoleAdmin(CONTRIBUTOR, MANAGER);
_newDataBase(dbSelector); _newDataBase(dbSelector);
permissionless = isPermissionless;
} }
// ===== hub operator functions====== // ===== hub operator functions======
@ -226,9 +232,9 @@ contract Hubv3 is AccessControl, Initializable {
} }
// ===== database operator functions====== // ===== database operator functions======
function newDataBase(bool flag) public onlyRole(DEFAULT_ADMIN_ROLE) { // function newDataBase(bool flag) public onlyRole(DEFAULT_ADMIN_ROLE) {
_newDataBase(flag); // _newDataBase(flag);
} // }
function _newDataBase(bool flag) internal { function _newDataBase(bool flag) internal {
if (flag) { if (flag) {
@ -253,4 +259,15 @@ contract Hubv3 is AccessControl, Initializable {
) external payable { ) external payable {
return db.upload(repoName, path, data); return db.upload(repoName, path, data);
} }
function batchUpload(
bytes memory repoName,
bytes[] memory path,
bytes[] calldata data
) external payable {
require(path.length == data.length, "path and data length mismatch");
for (uint i = 0; i < path.length; i++) {
db.upload(repoName, path[i], data[i]);
}
}
} }

@ -1,3 +1,4 @@
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
library Repolib { library Repolib {

@ -1,3 +1,4 @@
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
interface database { interface database {

@ -1,3 +1,4 @@
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./EthStorage/LargeStorageManagerV2.sol"; import "./EthStorage/LargeStorageManagerV2.sol";
import "./database.sol"; import "./database.sol";

@ -1,3 +1,4 @@
//SPDX-License-Identifier: GLP-3.0
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "./database.sol"; import "./database.sol";

@ -1,32 +1,34 @@
import { ethers } from "hardhat"; import { ethers } from "hardhat";
async function main() { async function main() {
let provider = ethers.provider let provider = ethers.provider;
let [operator,] = await ethers.getSigners(); let [operator] = await ethers.getSigners();
let nonce = await operator.getTransactionCount() let nonce = await operator.getTransactionCount();
let price = await provider.getFeeData() let price = await provider.getFeeData();
console.log(price) console.log(price);
console.log(operator.address, nonce) console.log(operator.address, nonce);
const Git3Fac = await ethers.getContractFactory("HubFactory"); const Git3Fac = await ethers.getContractFactory("HubFactory");
const hubFac = await Git3Fac.deploy({ nonce: nonce }); const hubFac = await Git3Fac.deploy(true, { nonce: nonce });
let logicReceipt = await hubFac.deployed();
console.log(logicReceipt.deployTransaction.hash);
nonce++;
let newHubReceipt = await hubFac.newHubImp({ nonce: nonce });
nonce++;
let logicReceipt = await hubFac.deployed() await newHubReceipt.wait();
console.log(logicReceipt.deployTransaction.hash)
nonce++
await hubFac.newHubImp({ nonce: nonce }); let createHubReceipt = await hubFac.createHub({ nonce: nonce });
nonce++ nonce++;
await hubFac.createHub(true,{ nonce: nonce }) await createHubReceipt.wait();
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);

@ -1,31 +1,30 @@
import { ethers } from "hardhat"; import { ethers } from "hardhat";
async function main() { async function main() {
let provider = ethers.provider let provider = ethers.provider;
let [operator,] = await ethers.getSigners(); let [operator] = await ethers.getSigners();
let nonce = await operator.getTransactionCount() let nonce = await operator.getTransactionCount();
let price = await provider.getFeeData();
console.log(price);
let price = await provider.getFeeData() console.log(operator.address, nonce);
console.log(price)
console.log(operator.address, nonce)
const Git3Fac = await ethers.getContractFactory("HubFactory"); const Git3Fac = await ethers.getContractFactory("HubFactory");
const hubFac = await Git3Fac.deploy({ nonce: nonce }); const hubFac = await Git3Fac.deploy(false, { nonce: nonce });
let logicReceipt = await hubFac.deployed() let logicReceipt = await hubFac.deployed();
console.log(logicReceipt.deployTransaction.hash) console.log(logicReceipt.deployTransaction.hash);
nonce++ nonce++;
await hubFac.newHubImp({ nonce: nonce }); let newHubReceipt = await hubFac.newHubImp({ nonce: nonce });
nonce++ nonce++;
await hubFac.createHub(false,{ nonce: nonce }) let createHubReceipt = await hubFac.createHub({ 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);

Loading…
Cancel
Save