-
Notifications
You must be signed in to change notification settings - Fork 0
/
marketplace.sol
38 lines (29 loc) · 1.02 KB
/
marketplace.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
// SPDX-License-Identifier: MIT-Modern-Variant
pragma solidity >0.7.0 <0.9.0;
contract Marketplace {
address public seller;
address public buyer;
mapping (address => uint) public balances;
event ListItem(address seller, uint price);
event PurchasedItem(address seller, address buyer, uint price);
enum StateType {
ItemAvailable,
ItemPurchased
}
StateType public State;
constructor() {
seller = msg.sender;
State = StateType.ItemAvailable;
}
function initial_balance(address partecipant, uint amount) public {
require(msg.sender == partecipant, "You can update just your own balance");
balances[partecipant] = amount;
}
function buy(address seller, address buyer, uint price) public payable {
require(price <= balances[buyer], "Insufficient balance");
State = StateType.ItemPurchased;
balances[buyer] -= price;
balances[seller] += price;
emit PurchasedItem(seller, buyer, msg.value);
}
}