-
Notifications
You must be signed in to change notification settings - Fork 1
/
rideSharing.sol
51 lines (42 loc) · 1.26 KB
/
rideSharing.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
pragma solidity ^0.4.21;
contract RideSharing {
address public driver;
uint public escrow;
bool public driverTrip;
bool public riderTrip;
mapping (address => uint) public balances;
mapping (address => address) public driverRider;
// This is the constructor whose code is
// run only when the contract is created.
constructor() public {
driver = msg.sender;
}
function establishDeal(address rider, uint amount) public {
if (msg.sender != driver) return;
balances[rider] = amount;
driverRider[driver] = rider;
holdInEscrow(rider, amount);
}
function holdInEscrow(address rider, uint amount) public {
balances[rider] -= amount;
escrow = amount;
}
function driverCompletesTrip() public{
if (msg.sender != driver) return;
driverTrip = true;
if(riderTrip && driverTrip){
releaseEscrow();
}
}
function riderAcceptsEndOfTrip() public {
if(msg.sender == driver) return;
riderTrip = true;
if(riderTrip && driverTrip){
releaseEscrow();
}
}
function releaseEscrow() private {
balances[driver] += escrow;
escrow = 0; // effectively destroying escrow
}
}