-
Notifications
You must be signed in to change notification settings - Fork 0
/
AmBros.sol
43 lines (35 loc) · 1.04 KB
/
AmBros.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
pragma solidity ^0.4.18;
contract Owned {
address public owner;
function Owned() public {
owner = msg.sender;
}
modifier onlyOwner() {
require(owner == msg.sender);
_;
}
}
contract DeliveryCondition is Owned {
enum status {Active, Done}
struct Order {
uint256 orderNumber;
uint256 shippingPrice;
address customer;
address logistic;
status stat;
}
mapping (uint256 => Order) public orders;
function confirm(uint256 orderNumber, uint256 finalPrice) public {
Order storage order = orders[orderNumber];
require(order.stat == status.Active);
uint256 returnPrice = order.shippingPrice - finalPrice;
require(this.balance >= returnPrice);
order.customer.transfer(returnPrice);
order.logistic.transfer(finalPrice);
order.stat = status.Done;
}
function newOrder(address logistic, uint256 orderNumber, uint256 shippingPrice) public payable {
require(msg.value == shippingPrice);
orders[orderNumber] = Order(orderNumber, shippingPrice, msg.sender, logistic, status.Active);
}
}