-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
58 lines (50 loc) · 1.79 KB
/
app.js
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
'use strict'
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const config = require('./config/db');
const User = require('./models/user.js');
const port = process.env.PORT || 8080;
const apiRoutes = express.Router();
var BigNumber = require('bignumber.js');
var Web3 = require('web3');
var contract = require("truffle-contract");
var path = require('path');
var MyContractJSON = require('./Lottery.json');
// function listen(){
//
// // can be 'latest' or 'pending'
// var filter = provider.eth.filter('latest');
//
// // watch for changes
// filter.watch(function (error, result){
// if (!error)
// console.log(result);
// });
//
// return filter
// }
//
// var filter = listen();
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
var MyContract = contract(MyContractJSON);
MyContract.setProvider(new Web3.providers.HttpProvider('http://ww3.lucky9.ml'));
// Use Truffle as usual
var instance = MyContract.at('0x83aedfffd13c42b6e91ef6569e3823ed55ae58ce')
app.get('/test', function (req, res) {
res.send('Hello! The API is at http://localhost:' + port + '/api');
});
app.get('/lastWinner', function (req,res){
instance.lastWinner().then(function (lastWin){ res.send(lastWin)})
//.catch((err) => res.send(JSONerr))
});
app.get('/participantsCount', function (req,res){
instance.participantsCounter().then(function (count){res.send(count.toString())})
})
app.listen(port);
console.log('The poor are getting poorer at: http://localhost:' + port);