-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconex.js
143 lines (97 loc) · 5.11 KB
/
conex.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
142
143
class Conex{
constructor(url){
this.url = url;
this.respuesta = Array();
}
async getTxUnConf () {
let urlTxsUnConfir = 'https://blockchain.info/unconfirmed-transactions?format=json';
this.url = urlTxsUnConfir;
var resTxsUnConfir = Array();
let res = await axios.get( this.url );
for (var i=0; i<res.data.txs.length; i++){
var fee_size = (res.data.txs[i].fee / res.data.txs[i].size).toFixed(2);
resTxsUnConfir.push({
hash: res.data.txs[i].hash,
time: res.data.txs[i].time,
tx_index: res.data.txs[i].tx_index,
fee: res.data.txs[i].fee,
size: res.data.txs[i].size,
fee_size: fee_size
});
}//fin de for (var i=0;
return resTxsUnConfir;
}// fin de getTxsUnConfir
async getBlock ( idBlock ) {
let urlBlock = 'https://blockchain.info/rawblock/'
this.url = urlBlock + idBlock ;
var resBlock = Array();
let res = await axios.get( this.url );
resBlock = ({
hash: res.data.hash ,
bits: res.data.bits,
prev_block: res.data.prev_block,
next_block: res.data.next_block,
fee: res.data.fee,
nonce: res.data.nonce,
size: res.data.size,
time: res.data.time,
});
this.respuesta = res;
return resBlock
}// fin de getTxsBlock
async getBlockHeight ( idBlock ) {
let urlBlock = 'https://blockchain.info/block-height/'
this.url = urlBlock + idBlock + '?format=json';
var resBlock = Array();
let res = await axios.get( this.url );
resBlock = ({
hash: res.data.blocks[0].hash ,
bits: res.data.blocks[0].bits,
prev_block: res.data.blocks[0].prev_block,
next_block: res.data.blocks[0].next_block,
fee: res.data.blocks[0].fee,
nonce: res.data.blocks[0].nonce,
size: res.data.blocks[0].size,
time: res.data.blocks[0].time,
ver: res.data.blocks[0].ver,
block_index: res.data.blocks[0].block_index,
});
return resBlock
}// fin de getTxsBlock
async getTxsBlock ( idBlock ) {
let urlTxsBlock = 'https://blockchain.info/rawblock/'
this.url = urlTxsBlock + idBlock ;
var resTxsBlock = Array();
let res = await axios.get( this.url );
for (var i=0; i<res.data.tx.length; i++){
resTxsBlock.push({
hash: res.data.tx[i].hash ,
time: res.data.tx[i].time,
inputs: res.data.tx[i].inputs,
out: res.data.tx[i].out,
});
}// fin de for (var i=0; i<res.data
this.respuesta = resTxsBlock;
}// fin de getTxsBlock
async getLastBlock(){
let urlLastBlock = 'https://blockchain.info/q/latesthash';
this.url = urlLastBlock;
let res = await axios.get( this.url )
// .then((response) => {
// return response.data;
// })
// .catch(function (error) {
// if (error.response) {
// console.log(error.response.data);
// console.log(error.response.status);
// console.log(error.response.headers);
// } else if (error.request) {
// console.log(error.request);
// } else {
// console.log('Error', error.message);
// }
// return false;
// });
return res.data;
} // fin de async getLastBlock(
} //fin de class Conex