Commit d7120497 authored by Sagar's avatar Sagar

initial commit

parents
Pipeline #584 failed with stages
node_modules
#Hardhat files
cache
artifacts
## install nodejs
for centos
```
sudo yum install nodejs
```
for ubuntu
```
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install nodejs
```
## instal hardhat
execute command in current dirctionary.
```
npm install --save-dev hardhat
```
## run test
```
npx hardhat test
```
// SPDX-License-Identifier: MIT
// Created by Caduceus.foundation
pragma solidity ^0.8.4;
contract ConsensusContract {
struct CommitBlockInfo {
uint256 block_number;
address miner;
bytes block_hash;
bytes state_root;
bytes receipts_root;
bytes tx_root;
}
mapping(uint256=>CommitBlockInfo) committedBlocks;
struct VirtualBlockInfo {
uint256 block_number;
uint256 block_time;
bytes batch_txs;
}
uint256 nextBlockNumber;
mapping(uint256=>VirtualBlockInfo) virtualblocks;
address private _owner;
modifier onlyOwner() {
require(msg.sender == _owner, "Only owner can do it");
_;
}
constructor() {
_owner = msg.sender;
nextBlockNumber = 1;
}
function LimitInfo() public pure returns (uint256, uint256) {
return (100,20);
}
function SubmitTx(bytes memory batchtxs) public returns (bool) {
virtualblocks[nextBlockNumber].block_number = nextBlockNumber;
virtualblocks[nextBlockNumber].block_time = block.timestamp;
virtualblocks[nextBlockNumber].batch_txs = batchtxs;
nextBlockNumber += 1;
return true;
}
function GetNewVirtualBlock(uint256 lastblock) public view returns (VirtualBlockInfo memory) {
return virtualblocks[lastblock+1];
}
function CommitBlock(CommitBlockInfo memory blockinfo) public returns (bool) {
committedBlocks[blockinfo.block_number] = blockinfo;
return true;
}
function GetConfirmedBlock(uint256 block_number) public view returns (CommitBlockInfo memory) {
return committedBlocks[block_number];
}
}
require("@nomiclabs/hardhat-waffle");
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
const balance = await network.provider.send("eth_getBalance", [account.address])
console.log(account.address, balance);
}
});
// Define mnemonic for accounts.
let mnemonic = process.env.MNEMONIC;
if (!mnemonic) {
// NOTE: this fallback is for development only!
// When using other networks, set the secret in .env.
// DO NOT commit or share your mnemonic with others!
mnemonic = 'test test test test test test test test test test test test';
}
const accounts = { mnemonic };
const { privateKey } = require('./secret.json');
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
networks: {
hardhat: {
accounts:{
accountsBalance:"800000000000000000000000"
}
},
localhost: {
url: 'http://127.0.0.1:8545',
accounts: [privateKey]
}
},
solidity: "0.8.4",
mocha: {
timeout: 400000,
},
};
This diff is collapsed.
{
"name": "hardhat-project",
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"chai": "^4.3.4",
"ethereum-waffle": "^3.4.0",
"ethers": "^5.4.2",
"hardhat": "^2.5.0"
}
}
const hre = require("hardhat");
const txargs = { gasLimit: 10000000, gasPrice: 5000000000 }
async function main() {
const accounts = await hre.ethers.getSigners();
console.log("use account ", accounts[0].address);
// We get the contract to deploy
const Sentry = await hre.ethers.getContractFactory("ConsensusContract");
const contract = await Sentry.deploy();
await contract.deployed();
console.log("sentry deployed to:", contract.address);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
{
"privateKey": "df57089febbacf7ba0bc227dafbffa9fc08a93fdc68e1e42411a14efcf23656e"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment