From 250dba3e98afaf2c750d54afe94435360e2fbe09 Mon Sep 17 00:00:00 2001 From: cyhhao Date: Fri, 24 Feb 2023 14:27:16 +0800 Subject: [PATCH] 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; +});