-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardContract.cpp
40 lines (32 loc) · 1.03 KB
/
cardContract.cpp
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
pragma solidity >=0.4.0 <0.6.0;
//Contract of credit card
contract Card {
//Address of user, who interacts with contract
address user;
//Mappings between user and funds
mapping(address => uint) funds;
//Contract constructor
constructor() public {
user = msg.sender;
}
//Method to deposit funds on the card
function deposit() public payable {
funds[msg.sender] += msg.value;
}
//Method to withdraw funds from the card
function withdraw(uint amount) public {
if (funds[msg.sender] >= amount) {
funds[msg.sender] -= amount;
msg.sender.transfer(amount);
}
}
//Method to check funds amount on the card
function checkFunds() public view returns(uint) {
return funds[msg.sender];
}
//Method to kill smart contract, if the method is called by a user, who is not the owner of the card
function kill() public {
if (msg.sender == user)
selfdestruct(user);
}
}