Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
contract
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
contract
Commits
17f2e022
Commit
17f2e022
authored
Mar 01, 2024
by
贾浩@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
eba42bd4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
9 deletions
+13
-9
Witness.sol
contracts/Witness.sol
+12
-8
IWitness.sol
contracts/interface/IWitness.sol
+1
-1
No files found.
contracts/Witness.sol
View file @
17f2e022
...
...
@@ -18,15 +18,15 @@ contract Witness is IWitness, Ownable {
uint256 public lastMerkleRootUpdate; // 上次 merkle root 更新时间
// 记录每天每个 merkle root 提交次数 2023-01-01 -> hash(merkleRoot, merkleSumRoot) -> 1
mapping(
string
=> mapping(bytes32 => uint256)) public dailyMerkleRootSubmitCountMap;
mapping(
uint256
=> mapping(bytes32 => uint256)) public dailyMerkleRootSubmitCountMap;
// 记录每天每个 witness 是否已提交过
mapping(
string
=> mapping(address => bool)) public dailyMerkleRootSubmittedMap;
mapping(
uint256
=> mapping(address => bool)) public dailyMerkleRootSubmittedMap;
// 记录每天已验证的 merkle root (已超过生效阈值)
mapping(
string
=> bool) public dailyMerkleRootVerifiedMap;
mapping(
uint256
=> bool) public dailyMerkleRootVerifiedMap;
// 记录每天的 merkle root
mapping(
string
=> bytes32) public dailyMerkleRootMap;
mapping(
uint256
=> bytes32) public dailyMerkleRootMap;
// 记录每天的 merkle sum root
mapping(
string
=> bytes32) public dailyMerkleSumRootMap;
mapping(
uint256
=> bytes32) public dailyMerkleSumRootMap;
uint256 public dailyDistribution;
...
...
@@ -39,7 +39,7 @@ contract Witness is IWitness, Ownable {
_;
}
event MerkleRootChanged(
string
date, bytes32 merkleRoot, bytes32 merkleSumRoot);
event MerkleRootChanged(
uint256
date, bytes32 merkleRoot, bytes32 merkleSumRoot);
event MerkleRootThresholdChanged(uint256 merkleRootThreshold);
event MerkleRootSubmitted(address indexed addr, bytes32 merkleRoot, bytes32 merkleSumRoot, uint256 indexed count, uint256 indexed dailySubmitCount);
event DailyDistributionChanged(uint256 dailyDistribution);
...
...
@@ -49,7 +49,11 @@ contract Witness is IWitness, Ownable {
return merkleRoot;
}
function submitMerkleRoot(string calldata _date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) public onlyWitness {
function getWorkloadDistribution(uint256 dailyWorkload) view public returns (uint256) {
return dailyDistribution / dailyWorkload;
}
function submitMerkleRoot(uint256 _date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) public onlyWitness {
require(dailyMerkleRootSubmitCount <= witnessSet.length(), "Too many submissions");
require(!dailyMerkleRootSubmittedMap[_date][msg.sender], "Already submitted");
// check already verified
...
...
@@ -73,7 +77,7 @@ contract Witness is IWitness, Ownable {
emit MerkleRootSubmitted(msg.sender, _merkleRoot, _merkleSumRoot, dailyMerkleRootSubmitCountMap[_date][rootHash], dailyMerkleRootSubmitCount);
}
function _setMerkleRoot(
string calldata
_date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) internal {
function _setMerkleRoot(
uint256
_date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) internal {
merkleRoot = _merkleRoot;
merkleSumRoot = merkleSumRoot;
dailyMerkleRootMap[_date] = _merkleRoot;
...
...
contracts/interface/IWitness.sol
View file @
17f2e022
...
...
@@ -4,7 +4,7 @@ pragma solidity ^0.8.20;
interface IWitness {
function getMerkleRoot() external returns (bytes32);
function submitMerkleRoot(
string calldata
_date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) external;
function submitMerkleRoot(
uint256
_date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) external;
function getDailyDistribution() external view returns (uint256);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment