Skip to content

Commit

Permalink
feat: add count function for miners and submissions (#216)
Browse files Browse the repository at this point in the history
Co-authored-by: hunjixin <16705420332lee@gmai.com>
  • Loading branch information
hunjixin and hunjixin authored Jul 1, 2024
1 parent c9fb71a commit eb8d9db
Show file tree
Hide file tree
Showing 3 changed files with 329 additions and 10 deletions.
243 changes: 243 additions & 0 deletions hardhat/.openzeppelin/unknown-412346.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,249 @@
},
"namespaces": {}
}
},
"2fd905ca8e6c89f7922d3c38962d4cf3205f6bee5797b13e6d5d9618bec33b4d": {
"address": "0x67d269191c92Caf3cD7723F116c85e6E9bf55933",
"txHash": "0xf69f1ee4c496366c981349e7563aa6d1396906bb3e51b4d69d128bd125c1f3ea",
"layout": {
"solcVersion": "0.8.21",
"storage": [
{
"label": "_initialized",
"offset": 0,
"slot": "0",
"type": "t_uint8",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:63",
"retypedFrom": "bool"
},
{
"label": "_initializing",
"offset": 1,
"slot": "0",
"type": "t_bool",
"contract": "Initializable",
"src": "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol:68"
},
{
"label": "__gap",
"offset": 0,
"slot": "1",
"type": "t_array(t_uint256)50_storage",
"contract": "ContextUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol:36"
},
{
"label": "_owner",
"offset": 0,
"slot": "51",
"type": "t_address",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:22"
},
{
"label": "__gap",
"offset": 0,
"slot": "52",
"type": "t_array(t_uint256)49_storage",
"contract": "OwnableUpgradeable",
"src": "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol:94"
},
{
"label": "targetDifficulty",
"offset": 0,
"slot": "101",
"type": "t_uint256",
"contract": "LilypadPow",
"src": "contracts/LilypadPow.sol:29"
},
{
"label": "powSubmissions",
"offset": 0,
"slot": "102",
"type": "t_mapping(t_address,t_array(t_struct(POWSubmission)4860_storage)dyn_storage)",
"contract": "LilypadPow",
"src": "contracts/LilypadPow.sol:31"
},
{
"label": "miners",
"offset": 0,
"slot": "103",
"type": "t_array(t_address)dyn_storage",
"contract": "LilypadPow",
"src": "contracts/LilypadPow.sol:32"
},
{
"label": "lastChallenges",
"offset": 0,
"slot": "104",
"type": "t_mapping(t_address,t_struct(Challenge)4869_storage)",
"contract": "LilypadPow",
"src": "contracts/LilypadPow.sol:34"
},
{
"label": "validProofs",
"offset": 0,
"slot": "105",
"type": "t_uint256",
"contract": "LilypadPow",
"src": "contracts/LilypadPow.sol:35"
},
{
"label": "startTime",
"offset": 0,
"slot": "106",
"type": "t_uint256",
"contract": "LilypadPow",
"src": "contracts/LilypadPow.sol:36"
},
{
"label": "window_start",
"offset": 0,
"slot": "107",
"type": "t_uint256",
"contract": "LilypadPow",
"src": "contracts/LilypadPow.sol:38"
},
{
"label": "window_end",
"offset": 0,
"slot": "108",
"type": "t_uint256",
"contract": "LilypadPow",
"src": "contracts/LilypadPow.sol:39"
}
],
"types": {
"t_address": {
"label": "address",
"numberOfBytes": "20"
},
"t_array(t_address)dyn_storage": {
"label": "address[]",
"numberOfBytes": "32"
},
"t_array(t_struct(POWSubmission)4860_storage)dyn_storage": {
"label": "struct LilypadPow.POWSubmission[]",
"numberOfBytes": "32"
},
"t_array(t_uint256)49_storage": {
"label": "uint256[49]",
"numberOfBytes": "1568"
},
"t_array(t_uint256)50_storage": {
"label": "uint256[50]",
"numberOfBytes": "1600"
},
"t_bool": {
"label": "bool",
"numberOfBytes": "1"
},
"t_bytes32": {
"label": "bytes32",
"numberOfBytes": "32"
},
"t_mapping(t_address,t_array(t_struct(POWSubmission)4860_storage)dyn_storage)": {
"label": "mapping(address => struct LilypadPow.POWSubmission[])",
"numberOfBytes": "32"
},
"t_mapping(t_address,t_struct(Challenge)4869_storage)": {
"label": "mapping(address => struct LilypadPow.Challenge)",
"numberOfBytes": "32"
},
"t_string_storage": {
"label": "string",
"numberOfBytes": "32"
},
"t_struct(Challenge)4869_storage": {
"label": "struct LilypadPow.Challenge",
"members": [
{
"label": "challenge",
"type": "t_bytes32",
"offset": 0,
"slot": "0"
},
{
"label": "difficulty",
"type": "t_uint256",
"offset": 0,
"slot": "1"
},
{
"label": "nodeId",
"type": "t_string_storage",
"offset": 0,
"slot": "2"
},
{
"label": "timestamp",
"type": "t_uint256",
"offset": 0,
"slot": "3"
}
],
"numberOfBytes": "128"
},
"t_struct(POWSubmission)4860_storage": {
"label": "struct LilypadPow.POWSubmission",
"members": [
{
"label": "walletAddress",
"type": "t_address",
"offset": 0,
"slot": "0"
},
{
"label": "nodeId",
"type": "t_string_storage",
"offset": 0,
"slot": "1"
},
{
"label": "nonce",
"type": "t_uint256",
"offset": 0,
"slot": "2"
},
{
"label": "start_timestamp",
"type": "t_uint256",
"offset": 0,
"slot": "3"
},
{
"label": "complete_timestamp",
"type": "t_uint256",
"offset": 0,
"slot": "4"
},
{
"label": "challenge",
"type": "t_bytes32",
"offset": 0,
"slot": "5"
},
{
"label": "difficulty",
"type": "t_uint256",
"offset": 0,
"slot": "6"
}
],
"numberOfBytes": "224"
},
"t_uint256": {
"label": "uint256",
"numberOfBytes": "32"
},
"t_uint8": {
"label": "uint8",
"numberOfBytes": "1"
}
},
"namespaces": {}
}
}
}
}
30 changes: 22 additions & 8 deletions hardhat/contracts/LilypadPow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.6;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

contract LilypadPow is Initializable, OwnableUpgradeable {
contract LilypadPow is Initializable, OwnableUpgradeable {
struct POWSubmission {
address walletAddress;
string nodeId;
Expand All @@ -26,8 +26,8 @@ contract LilypadPow is Initializable, OwnableUpgradeable {
// this difficulty was calculate with this tool https://github.com/hunjixin/pow-tool/tree/main/difficulty
// Theoretically A machine with a hash rate of 8M has a probability of no more than 0.01% of not finding a nonce that meets the difficulty within 20 blocks.
// However, this issue has not been well validated in practice. it can solve nonce within one minute most of the time.
uint256 public targetDifficulty;// =
//555460709263765739036470010701196062214039696708679004195670928130048;
uint256 public targetDifficulty; // =
//555460709263765739036470010701196062214039696708679004195670928130048;
mapping(address => POWSubmission[]) public powSubmissions;
address[] public miners;

Expand All @@ -47,13 +47,25 @@ contract LilypadPow is Initializable, OwnableUpgradeable {
targetDifficulty = 555460709263765739036470010701196062214039696708679004195670928130048;
}

function getMinerCount() public view returns (uint256) {
return miners.length;
}

function getMiners() public view returns (address[] memory) {
return miners;
}

function getMinerPowSubmissions(address addr) public view returns (POWSubmission[] memory) {
function getMinerPowSubmissionCount(
address addr
) public view returns (uint256) {
return powSubmissions[addr].length;
}

function getMinerPowSubmissions(
address addr
) public view returns (POWSubmission[] memory) {
return powSubmissions[addr];
}
}

// generateChallenge gen a byte32 value as challenge value, Sc store this one for verify
function generateChallenge(string calldata nodeId) external {
Expand All @@ -74,7 +86,7 @@ contract LilypadPow is Initializable, OwnableUpgradeable {
}

function change_difficulty(uint256 difficulty) public onlyOwner {
targetDifficulty = difficulty;
targetDifficulty = difficulty;
}

function calculate_difficulty() public view returns (uint256) {
Expand Down Expand Up @@ -109,7 +121,9 @@ contract LilypadPow is Initializable, OwnableUpgradeable {

validProofs++;

POWSubmission[] storage onwMinerPowSubmissions = powSubmissions[msg.sender];
POWSubmission[] storage onwMinerPowSubmissions = powSubmissions[
msg.sender
];
if (onwMinerPowSubmissions.length == 0) {
miners.push(msg.sender);
}
Expand Down Expand Up @@ -159,4 +173,4 @@ contract LilypadPow is Initializable, OwnableUpgradeable {
);
event GenerateChallenge(bytes32 challenge, uint256 difficulty);
event NewPowRound();
}
}
Loading

0 comments on commit eb8d9db

Please sign in to comment.