Skip to content

Commit 479a3fb

Browse files
author
Audio
committed
refactor: replace querystring with URLSearchParams
1 parent feec1cf commit 479a3fb

File tree

7 files changed

+81
-72
lines changed

7 files changed

+81
-72
lines changed

lib/account.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const querystring = require('querystring');
21
module.exports = function(getRequest, apiKey) {
32
return {
43
/**
@@ -36,7 +35,7 @@ module.exports = function(getRequest, apiKey) {
3635
queryObject.address = address;
3736
}
3837

39-
var query = querystring.stringify(queryObject);
38+
var query = new URLSearchParams(queryObject).toString();
4039
return getRequest(query);
4140
},
4241
/**
@@ -55,10 +54,10 @@ module.exports = function(getRequest, apiKey) {
5554
address = address.join(',');
5655
action = 'balancemulti';
5756
}
58-
59-
var query = querystring.stringify({
57+
const queryObject = {
6058
module, action, tag, address, apiKey
61-
});
59+
};
60+
var query = new URLSearchParams(queryObject).toString();
6261
return getRequest(query);
6362
},
6463
/**
@@ -103,7 +102,7 @@ module.exports = function(getRequest, apiKey) {
103102
queryObject.endblock = endblock;
104103
}
105104

106-
const query = querystring.stringify(queryObject);
105+
var query = new URLSearchParams(queryObject).toString();
107106

108107
return getRequest(query);
109108
},
@@ -142,11 +141,10 @@ module.exports = function(getRequest, apiKey) {
142141
if (!sort) {
143142
sort = 'asc';
144143
}
145-
146-
var query = querystring.stringify({
144+
const queryObject = {
147145
module, action, startblock, endblock, page, offset, sort, address, apiKey
148-
});
149-
146+
};
147+
var query = new URLSearchParams(queryObject).toString();
150148
return getRequest(query);
151149
},
152150
/**
@@ -158,9 +156,11 @@ module.exports = function(getRequest, apiKey) {
158156
getminedblocks(address) {
159157
const module = 'account';
160158
const action = 'getminedblocks';
161-
var query = querystring.stringify({
159+
160+
const queryObject = {
162161
module, action, address, apiKey
163-
});
162+
}
163+
var query = new URLSearchParams(queryObject).toString();
164164
return getRequest(query);
165165
},
166166
/**
@@ -207,8 +207,8 @@ module.exports = function(getRequest, apiKey) {
207207
if (contractaddress) {
208208
queryObject.contractaddress = contractaddress;
209209
}
210-
211-
return getRequest(querystring.stringify(queryObject));
210+
var query = new URLSearchParams(queryObject).toString();
211+
return getRequest(query);
212212
},
213213

214214
/**
@@ -255,8 +255,8 @@ module.exports = function(getRequest, apiKey) {
255255
if (contractaddress) {
256256
queryObject.contractaddress = contractaddress;
257257
}
258-
259-
return getRequest(querystring.stringify(queryObject));
258+
var query = new URLSearchParams(queryObject).toString();
259+
return getRequest(query);
260260
}
261261
};
262262
};

lib/block.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const querystring = require('querystring');
21
module.exports = function(getRequest, apiKey) {
32
return {
43
/**
@@ -12,10 +11,11 @@ module.exports = function(getRequest, apiKey) {
1211
const action = 'getblockreward';
1312
if (!blockno) {
1413
blockno = 0;
15-
}
16-
var query = querystring.stringify({
14+
}
15+
const queryObject = {
1716
module, action, address, blockno, apiKey
18-
});
17+
}
18+
var query = new URLSearchParams(queryObject).toString();
1919
return getRequest(query);
2020
}
2121
};

lib/contract.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const querystring = require('querystring');
21
module.exports = function(getRequest, apiKey) {
32
return {
43
/**
@@ -14,10 +13,10 @@ module.exports = function(getRequest, apiKey) {
1413
const module = 'contract';
1514
const action = 'getabi';
1615

17-
var query = querystring.stringify({
16+
const queryObject = {
1817
module, action, address, apiKey
19-
});
20-
18+
};
19+
var query = new URLSearchParams(queryObject).toString();
2120
return getRequest(query);
2221
},
2322
/**
@@ -32,15 +31,11 @@ module.exports = function(getRequest, apiKey) {
3231
getsourcecode(address) {
3332
const module = 'contract';
3433
const action = 'getsourcecode';
35-
36-
var query = querystring.stringify({
34+
const queryObject = {
3735
module, action, address, apiKey
38-
});
39-
36+
};
37+
var query = new URLSearchParams(queryObject).toString();
4038
return getRequest(query);
41-
},
42-
43-
44-
39+
}
4540
};
4641
};

lib/log.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const querystring = require('querystring');
21
module.exports = function(getRequest, apiKey) {
32
return {
43
/**
@@ -80,7 +79,7 @@ module.exports = function(getRequest, apiKey) {
8079
if (topic3) {
8180
params.topic3 = topic3;
8281
}
83-
var query = querystring.stringify(params);
82+
var query = new URLSearchParams(params).toString();
8483
return getRequest(query);
8584
}
8685
};

lib/proxy.js

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const querystring = require('querystring');
21
module.exports =function(getRequest, apiKey) {
32
return {
43
/**
@@ -10,9 +9,10 @@ module.exports =function(getRequest, apiKey) {
109
eth_blockNumber() {
1110
const module = 'proxy';
1211
const action = 'eth_blockNumber';
13-
var query = querystring.stringify({
12+
const queryObject = {
1413
module, action, apiKey
15-
});
14+
};
15+
var query = new URLSearchParams(queryObject).toString();
1616
return getRequest(query);
1717
},
1818
/**
@@ -26,9 +26,10 @@ module.exports =function(getRequest, apiKey) {
2626
const module = 'proxy';
2727
const action = 'eth_getBlockByNumber';
2828
const boolean = true;
29-
var query = querystring.stringify({
29+
const queryObject = {
3030
module, action, tag, apiKey, boolean
31-
});
31+
};
32+
var query = new URLSearchParams(queryObject).toString();
3233
return getRequest(query);
3334
},
3435
/**
@@ -42,9 +43,10 @@ module.exports =function(getRequest, apiKey) {
4243
eth_getUncleByBlockNumberAndIndex(tag, index) {
4344
const module = 'proxy';
4445
const action = 'eth_getUncleByBlockNumberAndIndex';
45-
var query = querystring.stringify({
46+
const queryObject = {
4647
module, action, apiKey, tag, index
47-
});
48+
};
49+
var query = new URLSearchParams(queryObject).toString();
4850
return getRequest(query);
4951
},
5052
/**
@@ -57,9 +59,10 @@ module.exports =function(getRequest, apiKey) {
5759
eth_getBlockTransactionCountByNumber(tag) {
5860
const module = 'proxy';
5961
const action = 'eth_getBlockTransactionCountByNumber';
60-
var query = querystring.stringify({
62+
const queryObject = {
6163
module, action, apiKey, tag
62-
});
64+
};
65+
var query = new URLSearchParams(queryObject).toString();
6366
return getRequest(query);
6467
},
6568
/**
@@ -72,9 +75,10 @@ module.exports =function(getRequest, apiKey) {
7275
eth_getTransactionByHash(txhash) {
7376
const module = 'proxy';
7477
const action = 'eth_getTransactionByHash';
75-
var query = querystring.stringify({
78+
const queryObject = {
7679
module, action, apiKey, txhash
77-
});
80+
};
81+
var query = new URLSearchParams(queryObject).toString();
7882
return getRequest(query);
7983
},
8084
/**
@@ -88,9 +92,10 @@ module.exports =function(getRequest, apiKey) {
8892
eth_getTransactionByBlockNumberAndIndex(tag, index) {
8993
const module = 'proxy';
9094
const action = 'eth_getTransactionByBlockNumberAndIndex';
91-
var query = querystring.stringify({
95+
const queryObject = {
9296
module, action, apiKey, tag, index
93-
});
97+
};
98+
var query = new URLSearchParams(queryObject).toString();
9499
return getRequest(query);
95100
},
96101
/**
@@ -103,9 +108,10 @@ module.exports =function(getRequest, apiKey) {
103108
eth_getTransactionCount(address) {
104109
const module = 'proxy';
105110
const action = 'eth_getTransactionCount';
106-
var query = querystring.stringify({
111+
const queryObject = {
107112
module, action, apiKey, address
108-
});
113+
};
114+
var query = new URLSearchParams(queryObject).toString();
109115
return getRequest(query);
110116
},
111117
/**
@@ -118,9 +124,10 @@ module.exports =function(getRequest, apiKey) {
118124
eth_sendRawTransaction(hex) {
119125
const module = 'proxy';
120126
const action = 'eth_sendRawTransaction';
121-
var query = querystring.stringify({
127+
const queryObject = {
122128
module, action, apiKey, hex
123-
});
129+
};
130+
var query = new URLSearchParams(queryObject).toString();
124131
return getRequest(query);
125132
},
126133
/**
@@ -133,9 +140,11 @@ module.exports =function(getRequest, apiKey) {
133140
eth_getTransactionReceipt(txhash) {
134141
const module = 'proxy';
135142
const action = 'eth_getTransactionReceipt';
136-
var query = querystring.stringify({
143+
144+
const queryObject = {
137145
module, action, apiKey, txhash
138-
});
146+
};
147+
var query = new URLSearchParams(queryObject).toString();
139148
return getRequest(query);
140149
},
141150
/**
@@ -150,9 +159,10 @@ module.exports =function(getRequest, apiKey) {
150159
eth_call(to, data, tag) {
151160
const module = 'proxy';
152161
const action = 'eth_call';
153-
var query = querystring.stringify({
162+
const queryObject = {
154163
module, action, apiKey, to, data, tag
155-
});
164+
};
165+
var query = new URLSearchParams(queryObject).toString();
156166
return getRequest(query);
157167
},
158168
/**
@@ -166,9 +176,10 @@ module.exports =function(getRequest, apiKey) {
166176
eth_getCode(address, tag) {
167177
const module = 'proxy';
168178
const action = 'eth_getCode';
169-
var query = querystring.stringify({
179+
const queryObject = {
170180
module, action, apiKey, address, tag
171-
});
181+
};
182+
var query = new URLSearchParams(queryObject).toString();
172183
return getRequest(query);
173184
},
174185
/**
@@ -183,9 +194,10 @@ module.exports =function(getRequest, apiKey) {
183194
eth_getStorageAt(address, position, tag) {
184195
const module = 'proxy';
185196
const action = 'eth_getStorageAt';
186-
var query = querystring.stringify({
197+
const queryObject = {
187198
module, action, apiKey, address, position, tag
188-
});
199+
}
200+
var query = new URLSearchParams(queryObject).toString();
189201
return getRequest(query);
190202
},
191203
/**
@@ -196,9 +208,10 @@ module.exports =function(getRequest, apiKey) {
196208
eth_gasPrice() {
197209
const module = 'proxy';
198210
const action = 'eth_gasPrice';
199-
var query = querystring.stringify({
211+
const queryObject = {
200212
module, action, apiKey
201-
});
213+
};
214+
var query = new URLSearchParams(queryObject).toString();
202215
return getRequest(query);
203216
},
204217
/**
@@ -219,9 +232,10 @@ module.exports =function(getRequest, apiKey) {
219232
eth_estimateGas(to, value, gasPrice, gas) {
220233
const module = 'proxy';
221234
const action = 'eth_estimateGas';
222-
var query = querystring.stringify({
235+
const queryObject = {
223236
module, action, apiKey, to, value, gasPrice, gas
224-
});
237+
}
238+
var query = new URLSearchParams(queryObject).toString();
225239
return getRequest(query);
226240
},
227241
};

lib/stats.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const querystring = require('querystring');
21
module.exports = function(getRequest, apiKey) {
32
return {
43
/**
@@ -25,7 +24,7 @@ module.exports = function(getRequest, apiKey) {
2524
params.contractaddress = contractaddress;
2625
}
2726

28-
var query = querystring.stringify(params);
27+
var query = new URLSearchParams(params).toString();
2928
return getRequest(query);
3029
},
3130

@@ -37,9 +36,10 @@ module.exports = function(getRequest, apiKey) {
3736
ethsupply() {
3837
const module = 'stats';
3938
const action = 'ethsupply';
40-
var query = querystring.stringify({
39+
const queryObject = {
4140
module, action, apiKey
42-
});
41+
}
42+
var query = new URLSearchParams(queryObject).toString();
4343
return getRequest(query);
4444
},
4545

@@ -52,9 +52,10 @@ module.exports = function(getRequest, apiKey) {
5252
ethprice() {
5353
const module = 'stats';
5454
const action = 'ethprice';
55-
var query = querystring.stringify({
55+
const queryOBject = {
5656
module, action, apiKey
57-
});
57+
};
58+
var query = new URLSearchParams(queryObject).toString();
5859
return getRequest(query);
5960
}
6061
};

0 commit comments

Comments
 (0)