-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathExampleDispatcherImpl.sol
41 lines (34 loc) · 1.34 KB
/
ExampleDispatcherImpl.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
import "./EIP712Dispatcher.sol";
import "./ReplayProtection.sol";
contract TransferDispatcherImplementation is
// is an EIP 712 Dispatcher
EIP712Dispatcher,
// GSN msg sender functionality
GSNMsgSender,
// choose the replay protection
BitFlipReplayProtection {
// overrides
string public constant name = "Test implementation";
string public constant version = "v0.1";
uint public constant chainId = 1;
//////////////////////////////
// EIP712Dispatcher sidecar //
// type
string public constant TRANSFER_TYPE = "transfer(uint amount,address to)";
// content hash
function encode_transfer(uint amount, address to) public pure
returns(bytes32 contentHash, string memory contentType) {
contentHash = keccak256(abi.encode(keccak256(abi.encodePacked(TRANSFER_TYPE)), amount, to));
contentType = TRANSFER_TYPE;
}
// EIP712Dispatcher sidecar //
//////////////////////////////
mapping(address => uint) balances;
function transfer(uint amount, address to) public {
address sender = _msgSender();
require(balances[sender] >= amount, "Not enough balance");
require(balances[to] + amount >= balances[to], "Overflow");
balances[sender] = balances[sender] - amount;
balances[to] = balances[to] + amount;
}
}