Skip to content

Commit

Permalink
ADD: verify sig
Browse files Browse the repository at this point in the history
  • Loading branch information
cctv2206 committed Jan 8, 2024
1 parent ab81266 commit 91da5c2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions contracts/gptmining/GptMiner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity >=0.8.2 <0.9.0;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import "./GPTPower.sol";

contract GPTMiner is Ownable {
Expand Down Expand Up @@ -46,6 +48,15 @@ contract GPTMiner is Ownable {
return Math.min(block.timestamp, periodFinish);
}

function genMessageHash(address minerAddress) public pure returns (bytes32){
return keccak256(abi.encodePacked("GPTMiner:", minerAddress));
}

function verify(address minerAddress, bytes memory _signature) public pure returns (address) {
bytes32 _msgHash = MessageHashUtils.toEthSignedMessageHash(genMessageHash(minerAddress));
return ECDSA.recover(_msgHash, _signature);
}

function rewardPerToken() public view returns (uint256) {
if (totalSupply == 0) {
return rewardPerTokenStored;
Expand Down

0 comments on commit 91da5c2

Please sign in to comment.