-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVendingMachine.sol
More file actions
29 lines (23 loc) · 876 Bytes
/
VendingMachine.sol
File metadata and controls
29 lines (23 loc) · 876 Bytes
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
//SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.5.0 < 0.9.0;
contract VendingMachine{
address public owner;
mapping (address => uint) public donutBalances;
constructor(){
owner = msg.sender;
donutBalances[address(this)] = 100;
}
function getBalanceOfVendingMachine() public view returns{
return donutBalances[address(this)] //return no. of donuts present in vending machine
}
function restock(uint amount) public{
require(owner == msg.sender);
donutBalances[address(this)]+=amount;
}
function purchase(uint amount) payable{
require(msg.value>= amount* 1 wei, "Less amount sent");
require(donutBalances[address(this)] >= amount, "Not enough donut left");
donutBalances[address(this)]-=amount;
donutBalances[msg.sender] += amount;
}
}