-
Notifications
You must be signed in to change notification settings - Fork 3
/
clientAll.js
113 lines (102 loc) · 3.07 KB
/
clientAll.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
const superagent = require('superagent');
const node1 = "A",
node1_port = 3001,
node1_url = `http://127.0.0.1:${node1_port}/`,
node2 = "B",
node2_port = 3002,
node2_url = `http://127.0.0.1:${node2_port}/`;
//----------------------------------------注册节点----------------------------------------
superagent
.post(node1_url + 'nodes')
.query({
id: node2,
url: node2_url
}).end((err, res) => {
// Calling the end function will send the request
});
superagent
.post(node2_url + 'nodes')
.query({
id: node1,
url: node1_url
}).end((err, res) => {
// Calling the end function will send the request
});
//----------------------------------------创建交易----------------------------------------
superagent
.get(node1_url + 'blocks').end(function (err, res) {
console.log(res.text)
});
superagent
.get(node1_url + 'transactions').end(function (err, res) {
console.log(res.text)
});
//创建交易
superagent
.post(node1_url + 'transactions')
.query({
sendAddr: 'nezha',
recAddr: 'taizi',
value: 3
}).end((err, res) => {
// Calling the end function will send the request
});
superagent
.post(node1_url + 'transactions')
.query({
sendAddr: 'longwang',
recAddr: 'taizi',
value: 4
}).set('accept', 'json')
.end((err, res) => {
// Calling the end function will send the request
});
superagent
.get(node1_url + 'transactions').end(function (err, res) {
console.log(res.text)
});
//----------------------------------------节点1挖矿,挖三次----------------------------------------
superagent.get(node1_url + 'mine').end(function (err, res) {
// 抛错拦截
if (err) {
console.log(err);
}
// 等待 code
console.log(res.text)
});
superagent.get(node1_url + 'mine').end(function (err, res) {
// 抛错拦截
if (err) {
console.log(err);
}
// 等待 code
console.log(res.text)
});
superagent.get(node1_url + 'mine').end(function (err, res) {
// 抛错拦截
if (err) {
console.log(err);
}
// 等待 code
console.log(res.text)
//----------------------------------------consensus节点同步----------------------------------------
superagent
.put(node1_url + 'nodes/consensus')
.end((err, res) => {
// Calling the end function will send the request
superagent
.get(node1_url + 'blocks').end(function (err, res) {
console.log(node1_url, res.text)
});
});
superagent
.put(node2_url + 'nodes/consensus')
.end((err, res) => {
// Calling the end function will send the request
//------------------------------- 查看node2是否同步--------------------------------------------
superagent
.get(node2_url + 'blocks').end(function (err, res) {
console.log(node2_url, res.text)
});
});
});