generated from scaffold-eth/scaffold-eth
-
Notifications
You must be signed in to change notification settings - Fork 13
/
YourContract.sol
60 lines (50 loc) · 2.12 KB
/
YourContract.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
pragma solidity ^0.8.13;
//SPDX-License-Identifier: MIT
import "./Delegatable.sol";
import "@openzeppelin/contracts/access/Ownable.sol"; //https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol
contract YourContract is Ownable, Delegatable {
constructor(string memory name) Delegatable(name, "1") {}
string public purpose = "Building Unstoppable Apps!!!";
function setPurpose(string calldata newPurpose) onlyOwner public {
purpose = newPurpose;
}
mapping (string => bool) isPhisher;
function claimIfPhisher (string calldata identifier, bool isAccused) onlyOwner public {
isPhisher[identifier] = isAccused;
}
/**
* This is boilerplate that must be added to any Delegatable contract if it also inherits
* from another class that also implements _msgSender().
*/
function _msgSender () internal view override(Delegatable, Context) returns (address sender) {
if(msg.sender == address(this)) {
bytes memory array = msg.data;
uint256 index = msg.data.length;
assembly {
// Load the 32 bytes word from memory with the address on the lower 20 bytes, and mask those.
sender := and(mload(add(array, index)), 0xffffffffffffffffffffffffffffffffffffffff)
}
} else {
sender = msg.sender;
}
return sender;
}
/**
* This is a recommended method to implement. Most contracts will not intend to delegate all of their functionality.
* Rather than rely on an external caveat in these cases, we recommend having a "base caveat" that you interpret locally.
* This one simply disallows the ownership functions.
*/
function enforceCaveat(
bytes calldata terms,
Transaction calldata transaction,
bytes32 delegationHash
) public pure returns (bool) {
// Owner methods are not delegatable in this contract:
bytes4 targetSig = bytes4(transaction.data[0:4]);
// transferOwnership(address newOwner)
require(targetSig != 0xf2fde38b, "transferOwnership is not delegatable");
// renounceOwnership()
require(targetSig != 0x79ba79d8, "renounceOwnership is not delegatable");
return true;
}
}