-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathwalletexplorer.js
More file actions
61 lines (55 loc) · 1.58 KB
/
walletexplorer.js
File metadata and controls
61 lines (55 loc) · 1.58 KB
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
/***************************
walletexplorer.js
WalletExplorer.net API - WalletExplorer helps the community keep their wallets up to date by tracking what versions are in use by public services
****************************/
var querystring = require('querystring')
,https = require('https');
exports.post = post;
function post(coin,auth,version,protocol_version,wallet_version,blocks,diff,callback) {
var query = querystring.stringify({
coin:coin
,auth:auth
,version:version
,protocol_version:protocol_version
,wallet_version:wallet_version
,blocks:blocks
,diff:diff
})
,opts = {
host:'walletexplorer.net'
,method:'POST'
,port:443
,path:'/api/submit'
,headers:{
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': query.length
}
}
,stream = ''
,req = https.request(opts,
function(res){
res.setEncoding('utf8');
res.on('data', function (chunk) {
stream += chunk;
});
res.on('end',function(){
console.log('<WalletExplorer API> RESPONSE',stream);
try {
var data = JSON.parse(stream);
} catch(err) {
console.log('<WalletExplorer API> Error: WalletExplorer API Response is invalid JSON!',err,stream);
//return the error
return callback(err,null);
}
// return the result of the JSON parsing
return callback(null,data);
});
}
).on('error',function(err){
console.log('<WalletExplorer API> Error posting API data',err);
return callback(err,null);
});
console.log('<WalletExplorer API> POST',query);
req.write(query);
req.end();
}