-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathWallet.sol
39 lines (31 loc) · 1.04 KB
/
Wallet.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
// SPDX-License-Identifier: MIT
pragma solidity 0.6.10;
pragma experimental AccountAbstraction;
import { ECDSA } from "./ECDSA.sol";
account contract Wallet is ECDSA {
uint256 nonce;
address owner;
modifier paygasZero {
assembly { paygas(0) }
_;
}
function transfer(uint256 txNonce, uint256 gasPrice, address payable to, uint256 amount, bytes calldata signature) public {
assert(nonce == txNonce);
bytes32 hash = keccak256(abi.encodePacked(this, txNonce, gasPrice, to, amount));
bytes32 messageHash = toEthSignedMessageHash(hash);
address signer = recover(messageHash, signature);
require(signer == owner);
nonce = txNonce + 1;
assembly { paygas(gasPrice) }
to.transfer(amount);
}
function getNonce() public view paygasZero returns (uint256) {
return nonce;
}
function getOwner() public view paygasZero returns (address) {
return owner;
}
constructor() public payable {
owner = msg.sender;
}
}