-
Notifications
You must be signed in to change notification settings - Fork 30
/
10_Wallet.sol
43 lines (38 loc) · 1.61 KB
/
10_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
40
41
42
43
pragma tvm-solidity >= 0.72.0;
pragma AbiHeader expire;
/// @title Simple wallet
contract Wallet {
/*
Exception codes:
100 - message sender is not a wallet owner.
101 - invalid transfer value.
*/
/// @dev Contract constructor.
constructor() {
// check that contract's public key is set
require(tvm.pubkey() != 0, 101);
// Check that message has signature (msg.pubkey() is not zero) and message is signed with the owner's private key
require(msg.pubkey() == tvm.pubkey(), 102);
tvm.accept();
}
// Modifier that allows function to accept external call only if it was signed
// with contract owner's public key.
modifier checkOwnerAndAccept {
// Check that inbound message was signed with owner's public key.
// Runtime function that obtains sender's public key.
require(msg.pubkey() == tvm.pubkey(), 100);
// Runtime function that allows contract to process inbound messages spending
// its own resources (it's necessary if contract should process all inbound messages,
// not only those that carry value with them).
tvm.accept();
_;
}
/// @dev Allows to transfer tons to the destination account.
/// @param dest Transfer target address.
/// @param value Nanoevers value to transfer.
/// @param bounce Flag that enables bounce message in case of target contract error.
function sendTransaction(address dest, coins value, bool bounce) external view checkOwnerAndAccept {
// Runtime function that allows to make a transfer with arbitrary settings.
dest.transfer(value, bounce, 0);
}
}