-
Notifications
You must be signed in to change notification settings - Fork 30
/
13_BankCollectorClient.sol
51 lines (41 loc) · 1.72 KB
/
13_BankCollectorClient.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
pragma tvm-solidity >= 0.72.0;
pragma AbiHeader expire;
import "13_Interfaces.sol";
// This contract implements 'IBankClient' interface.
contract BankClient is IBankClient {
address public bankCollector;
uint public debtAmount;
constructor(address _bankCollector) {
// 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();
bankCollector = _bankCollector;
}
// Modifier that allows public function to be called only by message signed with owner's pubkey.
modifier onlyOwnerAndAccept {
require(msg.pubkey() == tvm.pubkey(), 102);
tvm.accept();
_;
}
// Modifier that allows public function to accept external calls only from bank collecor.
modifier onlyCollector {
// Runtime function to obtain message sender address.
require(msg.sender == bankCollector, 101);
// 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();
_;
}
function demandDebt(coins amount) external override onlyCollector {
IBankCollector(msg.sender).receivePayment{value: amount}();
}
function obtainDebtAmount() external view onlyOwnerAndAccept {
IBankCollector(bankCollector).getDebtAmount{value: 0.5 ever}();
}
function setDebtAmount(coins amount) external override onlyCollector {
debtAmount = amount;
}
}