-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
49 lines (45 loc) · 1.51 KB
/
index.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
var axios = require("axios")
module.exports = {
// getPublicChain() method returns all blockchain data except private transactions.
// Use this method to perform analysis, block and node validation.
getPublicChain () {
return axios.get(`https://iotappbe.com:5001/test`)
.then((response) => {
let chain = response.data;
return chain.slice().reverse()
})
.catch((error) => {
console.log("API error: " + error);
})
},
// getPrivateChain() method returns all private blockchain data for a given write key.
// Use this method to get and display all transactions signed to your dapp.
getPrivateChain (key1, key2) {
return axios.post('https://iotappbe.com:5001/passkeys', {
privKey1: key1,
privKey2: key2,
})
.then((response) => {
let privateChain = response.data;
return privateChain.slice().reverse();
})
.catch((error) => {
console.log("API error: " + error);
})
},
//getLastTx() method returns the last transaction in the private chain for a given write key.
// Use this method to get and display the latest incoming data for your dapp.
getLatestTx (key1, key2) {
return axios.post('https://iotappbe.com:5001/passkeys', {
privKey1: key1,
privKey2: key2,
})
.then((response) => {
let lastBlock = response.data;
return [lastBlock.slice(-1)[0]]
})
.catch((error) => {
console.log("API error: " + error);
})
}
}