From 3c7423eabf7beb56631501103acd6a0a521f5833 Mon Sep 17 00:00:00 2001 From: cyhhao Date: Sat, 18 Feb 2023 21:09:37 +0800 Subject: [PATCH 1/2] add batch upload function --- contracts/SLI/Git3Hub.sol | 13 +++++++++++++ scripts/deploy-sli.ts | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/contracts/SLI/Git3Hub.sol b/contracts/SLI/Git3Hub.sol index 4d1e0a3..f496811 100644 --- a/contracts/SLI/Git3Hub.sol +++ b/contracts/SLI/Git3Hub.sol @@ -64,6 +64,19 @@ contract Git3Hub_SLI is Git3HubStorage_SLI { pathToHash[keccak256(bytes.concat(repoName, "/", path))] = data; } + function batchUpload( + bytes memory repoName, + bytes[] memory path, + bytes[] calldata data + ) external payable onlyOwner(repoName) { + require(path.length == data.length, "path and data length mismatch"); + for (uint i = 0; i < path.length; i++) { + pathToHash[keccak256(bytes.concat(repoName, "/", path[i]))] = data[ + i + ]; + } + } + function remove( bytes memory repoName, bytes memory path diff --git a/scripts/deploy-sli.ts b/scripts/deploy-sli.ts index 346a4d4..3f74174 100644 --- a/scripts/deploy-sli.ts +++ b/scripts/deploy-sli.ts @@ -16,7 +16,6 @@ async function main() { type: 2, maxFeePerGas: price.maxFeePerGas!, maxPriorityFeePerGas: price.maxPriorityFeePerGas!, - gasLimit: 3000000, }); let logicReceipt = await git3.deployed(); From 250dba3e98afaf2c750d54afe94435360e2fbe09 Mon Sep 17 00:00:00 2001 From: cyhhao Date: Fri, 24 Feb 2023 14:27:16 +0800 Subject: [PATCH 2/2] add ns --- contracts/nameservice/NameService.sol | 42 +++++++++++++++++++++++++++ scripts/deploy-ns.ts | 31 ++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 contracts/nameservice/NameService.sol create mode 100644 scripts/deploy-ns.ts diff --git a/contracts/nameservice/NameService.sol b/contracts/nameservice/NameService.sol new file mode 100644 index 0000000..b2fc7f2 --- /dev/null +++ b/contracts/nameservice/NameService.sol @@ -0,0 +1,42 @@ +//SPDX-License-Identifier: GPL-3.0 +pragma solidity ^0.8.0; + +contract Git3NameService { + mapping(string => address) public nameHub; + mapping(string => address) public nameOwner; + string[] public nameList; + + mapping(address => mapping(string => string)) public HubRecords; + + constructor() {} + + modifier onlyHubOwner(string memory name) { + require(nameOwner[name] == msg.sender, "Only name owner can do this"); + _; + } + + function registerHub(string memory name, address hub) public { + require(nameHub[name] == address(0), "Name already registered"); + nameHub[name] = hub; + nameOwner[name] = msg.sender; + nameList.push(name); + } + + function nameListLength() public view returns (uint256) { + return nameList.length; + } + + function rebindHubAddress( + string memory name, + address hub + ) public onlyHubOwner(name) { + nameHub[name] = hub; + } + + function transferNameOwner( + string memory name, + address newOwner + ) public onlyHubOwner(name) { + nameOwner[name] = newOwner; + } +} diff --git a/scripts/deploy-ns.ts b/scripts/deploy-ns.ts new file mode 100644 index 0000000..653e564 --- /dev/null +++ b/scripts/deploy-ns.ts @@ -0,0 +1,31 @@ +import { ethers } from "hardhat"; + +async function main() { + let provider = ethers.provider; + let [operator] = await ethers.getSigners(); + let nonce = await operator.getTransactionCount(); + console.log(operator.address, nonce, await operator.getBalance()); + + let price = await provider.getFeeData(); + let net = await provider.getNetwork(); + console.log(price, net.chainId); + + const Nameservice = await ethers.getContractFactory("Git3NameService"); + const ns = await Nameservice.deploy({ + nonce: nonce, + type: 2, + maxFeePerGas: price.maxFeePerGas!, + maxPriorityFeePerGas: price.maxPriorityFeePerGas!, + }); + + let receipt = await ns.deployed(); + console.log(receipt.deployTransaction.hash); + console.log("NS Contract", ns.address); +} + +// We recommend this pattern to be able to use async/await everywhere +// and properly handle errors. +main().catch((error) => { + console.error(error); + process.exitCode = 1; +});