-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticket_contract.sol
67 lines (49 loc) · 1.61 KB
/
ticket_contract.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
61
62
63
64
65
66
67
pragma solidity ^0.4.21;
contract owned {
function owned() public { owner = msg.sender; }
address owner;
}
// Use `is` to derive from another contract. Derived
// contracts can access all non-private members including
// internal functions and state variables. These cannot be
// accessed externally via `this`, though.
contract mortal is owned {
function kill() public {
if (msg.sender == owner) selfdestruct(owner);
}
}
contract Ticket is mortal {
/* Define variables */
uint256 public start_gtfs_stop_id;
uint256 public start_time;
uint8 public product_id;
string public name;
address public transport_agency_address;
uint public price = 1000000000000000;
bool public ticket_active = false;
/* This runs when the contract is executed */
function Ticket( string _name, address _agency ) public {
transport_agency_address = _agency;
name = _name;
}
/* This runs when the contract is executed */
function BuyTicket(uint256 _start_gtfs_stop_id, uint8 _product_id ) public payable {
require(msg.value >= price);
start_gtfs_stop_id = _start_gtfs_stop_id;
start_time = now;
product_id = _product_id;
ticket_active = true;
//send amount to agency
transport_agency_address.transfer(price);
}
function deposit() payable public {
//deposits[msg.sender] += msg.value;
}
function isValid() public view returns (bool) {
if(!ticket_active) return false;
if (now >= start_time + 3 * 1 minutes) {
return false;
}
return true;
}
}