├── .gitignore ├── package.json ├── hardhat.config.js ├── scripts └── deploy.js ├── README.md └── contracts ├── OpenZeppelin_v5_0_0 └── openzeppelin-contracts │ └── contracts │ ├── utils │ └── Context.sol │ └── access │ └── Ownable.sol └── Registry.sol /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | cache 3 | artifacts 4 | package-lock.json 5 | env.sh -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hardhat-project", 3 | "devDependencies": { 4 | "@nomicfoundation/hardhat-toolbox": "^3.0.0", 5 | "hardhat": "^2.19.0" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /hardhat.config.js: -------------------------------------------------------------------------------- 1 | require("@nomicfoundation/hardhat-toolbox"); 2 | 3 | const RPCUrl = "https://mainnet.cybermiles.io" 4 | const priKey = "Your-private-key" 5 | 6 | module.exports = { 7 | solidity: "0.8.20", 8 | networks: { 9 | cybermiles: { 10 | url: RPCUrl, 11 | accounts:[priKey] 12 | } 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /scripts/deploy.js: -------------------------------------------------------------------------------- 1 | const hre = require("hardhat"); 2 | async function main() { 3 | 4 | const RegistryFactory = await hre.ethers.getContractFactory("Registry"); 5 | const registry = await RegistryFactory.deploy(); 6 | 7 | console.log(`Deployed to ${registry.target}`); 8 | } 9 | 10 | main().catch((error) => { 11 | console.error(error); 12 | process.exitCode = 1; 13 | }); 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gaianet-protocol 2 | 3 | ## Prerequisites 4 | 5 | - Node.js 6 | - NPM 7 | 8 | ## Deploy the contract 9 | 10 | The first step, clone the project and install the dependency. 11 | ``` 12 | git clone https://github.com/grorge123/gaianet-protocol.git 13 | cd gaianet-protocol 14 | npm install 15 | ``` 16 | You can edit the `hardhat.config.js` to choose which network and account to deploy the contract. 17 | In the example, we use CyberMiles chain to demo. 18 | 19 | Next step, run the following command to run the deploy script. 20 | ``` 21 | npx hardhat run scripts/deploy.js --network cybermiles 22 | ``` 23 | 24 | Then you can see the contract address. 25 | ``` 26 | Deployed to 0x30BB7f0ff7Cd36765e85d4f2100376ecBA194aa1 27 | ``` 28 | -------------------------------------------------------------------------------- /contracts/OpenZeppelin_v5_0_0/openzeppelin-contracts/contracts/utils/Context.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol) 3 | 4 | pragma solidity ^0.8.20; 5 | 6 | /** 7 | * @dev Provides information about the current execution context, including the 8 | * sender of the transaction and its data. While these are generally available 9 | * via msg.sender and msg.data, they should not be accessed in such a direct 10 | * manner, since when dealing with meta-transactions the account sending and 11 | * paying for execution may not be the actual sender (as far as an application 12 | * is concerned). 13 | * 14 | * This contract is only required for intermediate, library-like contracts. 15 | */ 16 | abstract contract Context { 17 | function _msgSender() internal view virtual returns (address) { 18 | return msg.sender; 19 | } 20 | 21 | function _msgData() internal view virtual returns (bytes calldata) { 22 | return msg.data; 23 | } 24 | 25 | function _contextSuffixLength() internal view virtual returns (uint256) { 26 | return 0; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /contracts/Registry.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.20; 3 | import './OpenZeppelin_v5_0_0/openzeppelin-contracts/contracts/access/Ownable.sol'; 4 | 5 | /** 6 | * @title OtomicMarket 7 | * @dev OtomicMarket logic 8 | */ 9 | contract Registry is Ownable { 10 | 11 | 12 | struct Node { 13 | string name; 14 | string description; 15 | string url; 16 | bool status; 17 | } 18 | 19 | mapping (address => Node) contractList; 20 | 21 | /** 22 | * @dev Initialize Registry necessary parameters. 23 | */ 24 | constructor() Ownable(msg.sender){ 25 | } 26 | 27 | modifier onlyOwnerOrCreator(address sender, address nodeAddress) { 28 | require(sender == owner() || sender == nodeAddress, "Only node creator or owner can call it."); 29 | _; 30 | } 31 | 32 | /** 33 | * @dev Query Node information. 34 | * @param nodeAddress The address of this node. 35 | */ 36 | 37 | function queryNode(address nodeAddress) public view returns (Node memory) { 38 | return contractList[nodeAddress]; 39 | } 40 | 41 | /** 42 | * @dev Update exist node. 43 | */ 44 | function updateNode(address nodeAddress, string calldata name, string calldata description, string calldata url, bool status) 45 | public 46 | onlyOwnerOrCreator(msg.sender, nodeAddress) { 47 | contractList[nodeAddress].name = name; 48 | contractList[nodeAddress].description = description; 49 | contractList[nodeAddress].url = url; 50 | contractList[nodeAddress].status = status; 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /contracts/OpenZeppelin_v5_0_0/openzeppelin-contracts/contracts/access/Ownable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol) 3 | 4 | pragma solidity ^0.8.20; 5 | 6 | import {Context} from "../utils/Context.sol"; 7 | 8 | /** 9 | * @dev Contract module which provides a basic access control mechanism, where 10 | * there is an account (an owner) that can be granted exclusive access to 11 | * specific functions. 12 | * 13 | * The initial owner is set to the address provided by the deployer. This can 14 | * later be changed with {transferOwnership}. 15 | * 16 | * This module is used through inheritance. It will make available the modifier 17 | * `onlyOwner`, which can be applied to your functions to restrict their use to 18 | * the owner. 19 | */ 20 | abstract contract Ownable is Context { 21 | address private _owner; 22 | 23 | /** 24 | * @dev The caller account is not authorized to perform an operation. 25 | */ 26 | error OwnableUnauthorizedAccount(address account); 27 | 28 | /** 29 | * @dev The owner is not a valid owner account. (eg. `address(0)`) 30 | */ 31 | error OwnableInvalidOwner(address owner); 32 | 33 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 34 | 35 | /** 36 | * @dev Initializes the contract setting the address provided by the deployer as the initial owner. 37 | */ 38 | constructor(address initialOwner) { 39 | if (initialOwner == address(0)) { 40 | revert OwnableInvalidOwner(address(0)); 41 | } 42 | _transferOwnership(initialOwner); 43 | } 44 | 45 | /** 46 | * @dev Throws if called by any account other than the owner. 47 | */ 48 | modifier onlyOwner() { 49 | _checkOwner(); 50 | _; 51 | } 52 | 53 | /** 54 | * @dev Returns the address of the current owner. 55 | */ 56 | function owner() public view virtual returns (address) { 57 | return _owner; 58 | } 59 | 60 | /** 61 | * @dev Throws if the sender is not the owner. 62 | */ 63 | function _checkOwner() internal view virtual { 64 | if (owner() != _msgSender()) { 65 | revert OwnableUnauthorizedAccount(_msgSender()); 66 | } 67 | } 68 | 69 | /** 70 | * @dev Leaves the contract without owner. It will not be possible to call 71 | * `onlyOwner` functions. Can only be called by the current owner. 72 | * 73 | * NOTE: Renouncing ownership will leave the contract without an owner, 74 | * thereby disabling any functionality that is only available to the owner. 75 | */ 76 | function renounceOwnership() public virtual onlyOwner { 77 | _transferOwnership(address(0)); 78 | } 79 | 80 | /** 81 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 82 | * Can only be called by the current owner. 83 | */ 84 | function transferOwnership(address newOwner) public virtual onlyOwner { 85 | if (newOwner == address(0)) { 86 | revert OwnableInvalidOwner(address(0)); 87 | } 88 | _transferOwnership(newOwner); 89 | } 90 | 91 | /** 92 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 93 | * Internal function without access restriction. 94 | */ 95 | function _transferOwnership(address newOwner) internal virtual { 96 | address oldOwner = _owner; 97 | _owner = newOwner; 98 | emit OwnershipTransferred(oldOwner, newOwner); 99 | } 100 | } 101 | --------------------------------------------------------------------------------