-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMYEcom.sol
60 lines (55 loc) · 2.19 KB
/
MYEcom.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
52
53
54
55
56
57
58
59
60
contract address - 0xD368e54c65D74885BEE670E80E019AD0753e14ae
//SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.5.0 < 0.9.0;
contract Ecommerce {
address payable public manager ;
constructor() {
manager = payable (msg.sender);
}
struct Product {
uint Id;
string name ;
string discription;
uint price ;
uint quantity ;
address payable seller;
address buyer;
bool delivered;
}
Product[] public list ;
modifier Contract_Distroyed {
require(DISTROYED==false , "Contract Distroyed ");
_ ;}
Product product ;
function register_product (string memory _name , string memory _disc , uint _price , uint _quantity) Contract_Distroyed public {
product.name = _name;
product.discription= _disc;
product.price= _price*10**18;
product.quantity= _quantity;
product.seller =payable ( msg.sender);
list.push ( product) ;
product.Id ++;
}
function buy (uint productid) Contract_Distroyed public payable {
require (msg.value == list[productid].price , "please pay exact product price");
require( msg.sender != list[productid].seller, "seller can not buy there own product" );
require (list[productid].quantity > 0 , " Sorry product is out of stock ");
list[productid].buyer = msg.sender;
list[productid].quantity --;
}
function delivery (uint productid) Contract_Distroyed public {
require ( list[productid].buyer == msg.sender , "only buyer can conferm the delivery of product");
list[productid].delivered=true;
list[productid].seller. transfer(list[productid].price );
// products[_productId-1].seller.transfer(products[_productId-1].price)
}
bool public DISTROYED ;
function Distroy () public {
require(msg.sender==manager," only manger can distroy");
manager.transfer(address(this).balance);
DISTROYED= true;
}
fallback( ) external payable {
payable (msg.sender).transfer(msg.value);
}
}