This repository has been archived by the owner on Aug 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
helloblock.js
77 lines (71 loc) · 1.93 KB
/
helloblock.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
// Here we hold all the interactions with the blockchain.
var helloblock = new function () {
this.retrieveAllBalances = function(addresses, callback) {
var url = HELLOBLOCK_URL + '/v1/addresses?';
var addrs = []
for(i = 0; i < addresses.length; i++) {
addrs.push('addresses=' + addresses[i])
}
url = url + addrs.join('&')
$.ajax({
url: url,
success: function(res) {
callback(res.data.addresses)
},
error:function (xhr, opt, err) {
if (onError)
onError(err);
}}
)
}
this.getUnspentOutputs = function(address, callback) {
var url = HELLOBLOCK_URL + '/v1/addresses/' + address + '/unspents?limit=10';
$.ajax({
url: url,
success: function(res) {
callback(res.data.unspents);
},
error:function (xhr, opt, err) {
if (onError)
onError(err);
}}
)
}
this.sendTX = function(tx, callback) {
var url = HELLOBLOCK_URL + '/v1/transactions'
$.ajax({
type: 'post',
url: url,
data: {rawTxHex: tx},
success: function(res) {
var msg = 'Transaction complete!\n';
console.log( msg, res );
if (callback) {
var detail = 'txHash: ' + res.data.transaction.txHash;
callback( msg + detail );
}
},
error: function(xhr, opt, err) {
alert("Failed! ", err )
}
});
}
this.faucetWithdrawal = function(toAddress, value, callback) {
var url = HELLOBLOCK_URL + '/v1/faucet/withdrawal'
var data = {
value: value,
toAddress: toAddress
}
$.ajax({
type: 'post',
url: url,
data: data,
success: function(res) {
if (callback) callback(res);
},
error: function(xhr, opt, err) {
alert("Faucet withdrawal failed! ", err )
}
});
}
}