Skip to content

Commit bd17400

Browse files
committed
initial commit
0 parents  commit bd17400

18 files changed

+925
-0
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["env"]
3+
}

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tmp/**
2+
build/**
3+
node_modules/**
4+
contracts/**
5+
migrations/1_initial_migration.js
6+
migrations/2_deploy_contracts.js

.eslintrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"env": {
4+
"browser": true,
5+
"commonjs": true,
6+
"node": true,
7+
"es6": true
8+
},
9+
"parserOptions": {
10+
"ecmaVersion": 2017,
11+
"sourceType": "module"
12+
},
13+
"rules": {
14+
"no-console": "off",
15+
"strict": ["error", "global"],
16+
"curly": "warn"
17+
}
18+
}

.gitignore

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# temp fix for npm issues
2+
package-lock.json
3+
4+
.node-xmlhttprequest-sync-*
5+
6+
build
7+
.DS_Store
8+
chaindata
9+
10+
# Logs
11+
logs
12+
*.log
13+
npm-debug.log*
14+
yarn-debug.log*
15+
yarn-error.log*
16+
17+
# Runtime data
18+
pids
19+
*.pid
20+
*.seed
21+
*.pid.lock
22+
23+
# Directory for instrumented libs generated by jscoverage/JSCover
24+
lib-cov
25+
26+
# Coverage directory used by tools like istanbul
27+
coverage
28+
29+
# nyc test coverage
30+
.nyc_output
31+
32+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
33+
.grunt
34+
35+
# Bower dependency directory (https://bower.io/)
36+
bower_components
37+
38+
# node-waf configuration
39+
.lock-wscript
40+
41+
# Compiled binary addons (http://nodejs.org/api/addons.html)
42+
build/Release
43+
44+
# Dependency directories
45+
node_modules/
46+
jspm_packages/
47+
48+
# Typescript v1 declaration files
49+
typings/
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional REPL history
58+
.node_repl_history
59+
60+
# Output of 'npm pack'
61+
*.tgz
62+
63+
# Yarn Integrity file
64+
.yarn-integrity
65+
66+
# dotenv environment variables file
67+
.env

app/assets/decent-logo.svg

Lines changed: 426 additions & 0 deletions
Loading

app/assets/decent-logo_240x66.png

13.8 KB
Loading

app/index.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>TicketSales - Ethereum tutorial app</title>
5+
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
6+
<script src="./app.js"></script>
7+
</head>
8+
<body>
9+
<h1>TicketSales</h1>
10+
<h2>Ethereum tutorial app</h2>
11+
<!-- a target="_blank" class="ui small image" href="http://www.decent.org"><img src="assets/decent-logo.svg"></a> -->
12+
13+
<h3>Event state: <span class="black"><span id="eventState">TODO</span> </span></h3>
14+
<h3>Tickets sold: <span class="black"><span id="ticketCount">TODO</span> </span></h3>
15+
<p>Account: <span ><span id="account">TODO</span> ETH</span></p>
16+
<p>Your Balance: <span class="black"><span id="balance">TODO</span> ETH</span></p>
17+
18+
<br>
19+
20+
<h3>Ticket price: <span class="black"><span id="ticketPrice">TODO</span> ETH</span></h3>
21+
<button id="buyTicket" onclick="App.buyTicket()">Buy Ticket</button>
22+
<br><br>
23+
<span id="status"></span>
24+
<br>
25+
<span class="hint"><strong>Hint:</strong> open the browser developer console to view any errors and warnings.</span>
26+
</body>
27+
</html>

app/javascripts/app.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Import the page's CSS. Webpack will know what to do with it.
2+
import "../stylesheets/app.css";
3+
4+
// Import libraries we need.
5+
import { default as Web3 } from "web3";
6+
import { default as contract } from "truffle-contract";
7+
8+
// web3 is going to be set on load event
9+
var web3;
10+
11+
// Import our contract artifacts and turn them into usable abstractions.
12+
import ticketSalesArtifacts from "../../build/contracts/TicketSales.json";
13+
var TicketSales = contract(ticketSalesArtifacts);
14+
15+
// The following code is simple to show off interacting with your contracts.
16+
// As your needs grow you will likely need to change its form and structure.
17+
// For application bootstrapping, check out window.addEventListener below.
18+
var accounts;
19+
var account;
20+
21+
window.App = {
22+
start: function() {
23+
let self = this;
24+
25+
// Bootstrap the MetaCoin abstraction for Use.
26+
TicketSales.setProvider(web3.currentProvider);
27+
28+
// Get the initial account balance so it can be displayed.
29+
web3.eth.getAccounts(function(err, accs) {
30+
if (err != null) {
31+
alert("There was an error fetching your accounts.");
32+
return;
33+
}
34+
35+
if (accs.length == 0) {
36+
alert(
37+
"Couldn't get any accounts! Make sure your Ethereum client is configured correctly."
38+
);
39+
return;
40+
}
41+
42+
accounts = accs;
43+
account = accounts[0];
44+
45+
self.refresh();
46+
});
47+
},
48+
49+
setStatus: function(message) {
50+
var status = document.getElementById("status");
51+
status.innerHTML = message;
52+
},
53+
54+
refresh: async function() {
55+
let self = this;
56+
try {
57+
//let instance = await TicketSales.deployed();
58+
let value = await web3.eth.getBalance(account);
59+
let balanceElement = document.getElementById("balance");
60+
let accountElement = document.getElementById("account");
61+
accountElement.innerHTML = account;
62+
balanceElement.innerHTML = web3.utils.fromWei(value.valueOf());
63+
} catch (e) {
64+
console.log(e);
65+
self.setStatus("Error getting balance; see log.");
66+
}
67+
},
68+
69+
buyTicket: async function() {
70+
let self = this;
71+
try {
72+
this.setStatus("Initiating transaction... (please wait)");
73+
alert("todo");
74+
//let instance = TicketSales.deployed();
75+
} catch (e) {
76+
console.log(e);
77+
self.setStatus("Error buying ticket coin; see log.");
78+
}
79+
}
80+
};
81+
82+
window.addEventListener("load", function() {
83+
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
84+
if (typeof window.web3 !== "undefined") {
85+
console.debug("Using web3 detected from external source.");
86+
web3 = new Web3(window.web3.currentProvider);
87+
} else {
88+
// throw new Error("No web3 detected.");
89+
// set the provider you want from Web3.providers
90+
console.debug(
91+
"No web3 detected. Falling back to http://localhost:8545. You should remove this fallback when you deploy live, as it's inherently insecure. Consider switching to Metamask for development. More info here: http://truffleframework.com/tutorials/truffle-and-metamask"
92+
);
93+
web3 = new Web3(
94+
new Web3.providers.HttpProvider("http://localhost:8545")
95+
);
96+
}
97+
98+
window.App.start();
99+
});

app/stylesheets/app.css

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
body {
2+
margin-left: 25%;
3+
margin-right: 25%;
4+
margin-top: 10%;
5+
font-family: "Open Sans", sans-serif;
6+
}
7+
8+
label {
9+
display: inline-block;
10+
width: 100px;
11+
}
12+
13+
input {
14+
width: 500px;
15+
padding: 5px;
16+
font-size: 16px;
17+
}
18+
19+
button {
20+
font-size: 16px;
21+
padding: 5px;
22+
}
23+
24+
h1, h2 {
25+
display: inline-block;
26+
vertical-align: middle;
27+
margin-top: 0px;
28+
margin-bottom: 10px;
29+
}
30+
31+
h2 {
32+
color: #AAA;
33+
font-size: 32px;
34+
}
35+
36+
h3 {
37+
font-weight: normal;
38+
color: #AAA;
39+
font-size: 24px;
40+
}
41+
42+
.black {
43+
color: black;
44+
}
45+
46+
#balance {
47+
color: black;
48+
}
49+
50+
.hint {
51+
color: #666;
52+
}

contracts/Migrations.sol

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
pragma solidity ^0.4.2;
2+
3+
contract Migrations {
4+
address public owner;
5+
uint public last_completed_migration;
6+
7+
modifier restricted() {
8+
if (msg.sender == owner) _;
9+
}
10+
11+
function Migrations() {
12+
owner = msg.sender;
13+
}
14+
15+
function setCompleted(uint completed) restricted {
16+
last_completed_migration = completed;
17+
}
18+
19+
function upgrade(address new_address) restricted {
20+
Migrations upgraded = Migrations(new_address);
21+
upgraded.setCompleted(last_completed_migration);
22+
}
23+
}

0 commit comments

Comments
 (0)