-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.js
141 lines (119 loc) · 3.11 KB
/
api.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var https = require('https');
// Create New User and Be Assigned a User Secret
exports.newUser = function() {
var req = https.request({
hostname: 'session.satoshidice.com',
port: 443,
path: '/userapi/adduser/',
method: 'GET'
}, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
};
// Get user alias…
exports.getUserAlias = function(userHash) {
var req = https.request({
hostname: 'session.satoshidice.com',
port: 443,
path: '/userapi/getUserAlias/?hash=' + userHash,
method: 'GET'
}, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
};
// Retreive your deposit address…
exports.getAddress = function(userHash) {
var req = https.request({
hostname: 'session.satoshidice.com',
port: 443,
path: '/userapi/useraddress/?secret=' + userHash,
method: 'GET'
}, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
};
// Retreive Your Balance
exports.getBalance = function(userHash) {
var req = https.request({
hostname: 'session.satoshidice.com',
port: 443,
path: '/userapi/userbalance/?secret=' + userHash,
method: 'GET'
}, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
};
// Initiate Game Round
exports.newRound = function(userHash, callback) {
var req = https.request({
hostname: 'session.satoshidice.com',
port: 443,
path: '/userapi/startround.php?secret=' + userHash,
method: 'GET'
}, function(res) {
res.on('data', function(d) {
callback(JSON.parse(d));
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
};
// Initiate Game Round
exports.placeBet = function(obj, callback) {
setTimeout(function () {
var req = https.request({
hostname: 'session.satoshidice.com',
port: 443,
path: '/userapi/placebet.php?secret=' + obj.userHash + '&betInSatoshis=' + obj.bet + '&id=' + obj.gameId + '&serverHash=' + obj.serverHash + '&clientRoll=' + obj.clientRoll + '&belowRollToWin=' + obj.belowRollToWin,
method: 'GET'
}, function(res) {
res.setEncoding('utf8');
var body = "";
res.on('data', function(d) {
body += d;
});
res.on('end', function() {
var json = JSON.parse(body);
callback(json);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
}, 10);
};