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
df627af6
Commit
df627af6
authored
Mar 13, 2024
by
贾浩@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename: witness -> validator
parent
17f2e022
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
28 deletions
+28
-28
Distribution.sol
contracts/Distribution.sol
+3
-3
Validator.sol
contracts/Validator.sol
+24
-24
IValidator.sol
contracts/interface/IValidator.sol
+1
-1
No files found.
contracts/Distribution.sol
View file @
df627af6
...
@@ -7,14 +7,14 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
...
@@ -7,14 +7,14 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {I
Witness} from "./interface/IWitness
.sol";
import {I
Validator} from "./interface/IValidator
.sol";
import {IDistribution} from "./interface/IDistribution.sol";
import {IDistribution} from "./interface/IDistribution.sol";
contract Distribution is IDistribution, Ownable, Pausable, ReentrancyGuard {
contract Distribution is IDistribution, Ownable, Pausable, ReentrancyGuard {
constructor() Ownable(msg.sender) {
constructor() Ownable(msg.sender) {
}
}
I
Witness public witness
;
I
Validator public validator
;
IERC20 public token = IERC20(address(0xfFb096e2B90324FFcCbaf987BdD724462c0aE18c));
IERC20 public token = IERC20(address(0xfFb096e2B90324FFcCbaf987BdD724462c0aE18c));
...
@@ -45,6 +45,6 @@ contract Distribution is IDistribution, Ownable, Pausable, ReentrancyGuard {
...
@@ -45,6 +45,6 @@ contract Distribution is IDistribution, Ownable, Pausable, ReentrancyGuard {
}
}
function _merkleRoot() internal returns (bytes32){
function _merkleRoot() internal returns (bytes32){
return
witness
.getMerkleRoot();
return
validator
.getMerkleRoot();
}
}
}
}
\ No newline at end of file
contracts/
Witness
.sol
→
contracts/
Validator
.sol
View file @
df627af6
...
@@ -4,12 +4,12 @@ pragma solidity ^0.8.20;
...
@@ -4,12 +4,12 @@ pragma solidity ^0.8.20;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {I
Witness} from "./interface/IWitness
.sol";
import {I
Validator} from "./interface/IValidator
.sol";
contract
Witness is IWitness
, Ownable {
contract
Validator is IValidator
, Ownable {
using EnumerableSet for EnumerableSet.AddressSet;
using EnumerableSet for EnumerableSet.AddressSet;
EnumerableSet.AddressSet private
witness
Set;
EnumerableSet.AddressSet private
validator
Set;
bytes32 public merkleRoot; // 当前最新的 merkle root
bytes32 public merkleRoot; // 当前最新的 merkle root
bytes32 public merkleSumRoot; // 当前最新的 merkle sum root
bytes32 public merkleSumRoot; // 当前最新的 merkle sum root
...
@@ -19,7 +19,7 @@ contract Witness is IWitness, Ownable {
...
@@ -19,7 +19,7 @@ contract Witness is IWitness, Ownable {
// 记录每天每个 merkle root 提交次数 2023-01-01 -> hash(merkleRoot, merkleSumRoot) -> 1
// 记录每天每个 merkle root 提交次数 2023-01-01 -> hash(merkleRoot, merkleSumRoot) -> 1
mapping(uint256 => mapping(bytes32 => uint256)) public dailyMerkleRootSubmitCountMap;
mapping(uint256 => mapping(bytes32 => uint256)) public dailyMerkleRootSubmitCountMap;
// 记录每天每个
witness
是否已提交过
// 记录每天每个
validator
是否已提交过
mapping(uint256 => mapping(address => bool)) public dailyMerkleRootSubmittedMap;
mapping(uint256 => mapping(address => bool)) public dailyMerkleRootSubmittedMap;
// 记录每天已验证的 merkle root (已超过生效阈值)
// 记录每天已验证的 merkle root (已超过生效阈值)
mapping(uint256 => bool) public dailyMerkleRootVerifiedMap;
mapping(uint256 => bool) public dailyMerkleRootVerifiedMap;
...
@@ -31,11 +31,11 @@ contract Witness is IWitness, Ownable {
...
@@ -31,11 +31,11 @@ contract Witness is IWitness, Ownable {
uint256 public dailyDistribution;
uint256 public dailyDistribution;
constructor() Ownable(msg.sender) {
constructor() Ownable(msg.sender) {
witness
Set.add(msg.sender); // for test
validator
Set.add(msg.sender); // for test
}
}
modifier only
Witness
() {
modifier only
Validator
() {
require(
witnessSet.contains(msg.sender), "Only witness
");
require(
validatorSet.contains(msg.sender), "Only validator
");
_;
_;
}
}
...
@@ -43,7 +43,7 @@ contract Witness is IWitness, Ownable {
...
@@ -43,7 +43,7 @@ contract Witness is IWitness, Ownable {
event MerkleRootThresholdChanged(uint256 merkleRootThreshold);
event MerkleRootThresholdChanged(uint256 merkleRootThreshold);
event MerkleRootSubmitted(address indexed addr, bytes32 merkleRoot, bytes32 merkleSumRoot, uint256 indexed count, uint256 indexed dailySubmitCount);
event MerkleRootSubmitted(address indexed addr, bytes32 merkleRoot, bytes32 merkleSumRoot, uint256 indexed count, uint256 indexed dailySubmitCount);
event DailyDistributionChanged(uint256 dailyDistribution);
event DailyDistributionChanged(uint256 dailyDistribution);
event
Witness
Changed(address indexed addr, bool indexed ok, uint256 indexed count);
event
Validator
Changed(address indexed addr, bool indexed ok, uint256 indexed count);
function getMerkleRoot() public view returns (bytes32){
function getMerkleRoot() public view returns (bytes32){
return merkleRoot;
return merkleRoot;
...
@@ -53,8 +53,8 @@ contract Witness is IWitness, Ownable {
...
@@ -53,8 +53,8 @@ contract Witness is IWitness, Ownable {
return dailyDistribution / dailyWorkload;
return dailyDistribution / dailyWorkload;
}
}
function submitMerkleRoot(uint256 _date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) public only
Witness
{
function submitMerkleRoot(uint256 _date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) public only
Validator
{
require(dailyMerkleRootSubmitCount <=
witness
Set.length(), "Too many submissions");
require(dailyMerkleRootSubmitCount <=
validator
Set.length(), "Too many submissions");
require(!dailyMerkleRootSubmittedMap[_date][msg.sender], "Already submitted");
require(!dailyMerkleRootSubmittedMap[_date][msg.sender], "Already submitted");
// check already verified
// check already verified
if (dailyMerkleRootVerifiedMap[_date]) {
if (dailyMerkleRootVerifiedMap[_date]) {
...
@@ -98,32 +98,32 @@ contract Witness is IWitness, Ownable {
...
@@ -98,32 +98,32 @@ contract Witness is IWitness, Ownable {
emit MerkleRootThresholdChanged(_merkleRootThreshold);
emit MerkleRootThresholdChanged(_merkleRootThreshold);
}
}
function set
Witness
(address addr, bool ok) public onlyOwner {
function set
Validator
(address addr, bool ok) public onlyOwner {
if (ok) {
if (ok) {
_add
Witness
(addr);
_add
Validator
(addr);
} else {
} else {
_del
Witness
(addr);
_del
Validator
(addr);
}
}
emit
WitnessChanged(addr, ok, witness
Set.length());
emit
ValidatorChanged(addr, ok, validator
Set.length());
}
}
function _add
Witness
(address addr) internal {
function _add
Validator
(address addr) internal {
bool exist =
witness
Set.contains(addr);
bool exist =
validator
Set.contains(addr);
require(!exist, "Already exist");
require(!exist, "Already exist");
witness
Set.add(addr);
validator
Set.add(addr);
}
}
function _del
Witness
(address addr) internal {
function _del
Validator
(address addr) internal {
bool exist =
witness
Set.contains(addr);
bool exist =
validator
Set.contains(addr);
require(exist, "Not exist");
require(exist, "Not exist");
witness
Set.remove(addr);
validator
Set.remove(addr);
}
}
function get
Witness
es() public view returns (address[] memory) {
function get
Validator
es() public view returns (address[] memory) {
return
witness
Set.values();
return
validator
Set.values();
}
}
function is
Witness
(address addr) public view returns (bool) {
function is
Validator
(address addr) public view returns (bool) {
return
witness
Set.contains(addr);
return
validator
Set.contains(addr);
}
}
}
}
\ No newline at end of file
contracts/interface/I
Witness
.sol
→
contracts/interface/I
Validator
.sol
View file @
df627af6
// SPDX-License-Identifier: GPL-3.0
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.20;
pragma solidity ^0.8.20;
interface I
Witness
{
interface I
Validator
{
function getMerkleRoot() external returns (bytes32);
function getMerkleRoot() external returns (bytes32);
function submitMerkleRoot(uint256 _date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) external;
function submitMerkleRoot(uint256 _date, bytes32 _merkleRoot, bytes32 _merkleSumRoot) external;
...
...
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