Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit479a3fb

Browse files
author
Audio
committed
refactor: replace querystring with URLSearchParams
1 parentfeec1cf commit479a3fb

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-
constquerystring=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-
varquery=querystring.stringify(queryObject);
38+
varquery=newURLSearchParams(queryObject).toString();
4039
returngetRequest(query);
4140
},
4241
/**
@@ -55,10 +54,10 @@ module.exports = function(getRequest, apiKey) {
5554
address=address.join(',');
5655
action='balancemulti';
5756
}
58-
59-
varquery=querystring.stringify({
57+
constqueryObject={
6058
module, action, tag, address, apiKey
61-
});
59+
};
60+
varquery=newURLSearchParams(queryObject).toString();
6261
returngetRequest(query);
6362
},
6463
/**
@@ -103,7 +102,7 @@ module.exports = function(getRequest, apiKey) {
103102
queryObject.endblock=endblock;
104103
}
105104

106-
constquery=querystring.stringify(queryObject);
105+
varquery=newURLSearchParams(queryObject).toString();
107106

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

214214
/**
@@ -255,8 +255,8 @@ module.exports = function(getRequest, apiKey) {
255255
if(contractaddress){
256256
queryObject.contractaddress=contractaddress;
257257
}
258-
259-
returngetRequest(querystring.stringify(queryObject));
258+
varquery=newURLSearchParams(queryObject).toString();
259+
returngetRequest(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-
constquerystring=require('querystring');
21
module.exports=function(getRequest,apiKey){
32
return{
43
/**
@@ -12,10 +11,11 @@ module.exports = function(getRequest, apiKey) {
1211
constaction='getblockreward';
1312
if(!blockno){
1413
blockno=0;
15-
}
16-
varquery=querystring.stringify({
14+
}
15+
constqueryObject={
1716
module, action, address, blockno, apiKey
18-
});
17+
}
18+
varquery=newURLSearchParams(queryObject).toString();
1919
returngetRequest(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-
constquerystring=require('querystring');
21
module.exports=function(getRequest,apiKey){
32
return{
43
/**
@@ -14,10 +13,10 @@ module.exports = function(getRequest, apiKey) {
1413
constmodule='contract';
1514
constaction='getabi';
1615

17-
varquery=querystring.stringify({
16+
constqueryObject={
1817
module, action, address, apiKey
19-
});
20-
18+
};
19+
varquery=newURLSearchParams(queryObject).toString();
2120
returngetRequest(query);
2221
},
2322
/**
@@ -32,15 +31,11 @@ module.exports = function(getRequest, apiKey) {
3231
getsourcecode(address){
3332
constmodule='contract';
3433
constaction='getsourcecode';
35-
36-
varquery=querystring.stringify({
34+
constqueryObject={
3735
module, action, address, apiKey
38-
});
39-
36+
};
37+
varquery=newURLSearchParams(queryObject).toString();
4038
returngetRequest(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-
constquerystring=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-
varquery=querystring.stringify(params);
82+
varquery=newURLSearchParams(params).toString();
8483
returngetRequest(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-
constquerystring=require('querystring');
21
module.exports=function(getRequest,apiKey){
32
return{
43
/**
@@ -10,9 +9,10 @@ module.exports =function(getRequest, apiKey) {
109
eth_blockNumber(){
1110
constmodule='proxy';
1211
constaction='eth_blockNumber';
13-
varquery=querystring.stringify({
12+
constqueryObject={
1413
module, action, apiKey
15-
});
14+
};
15+
varquery=newURLSearchParams(queryObject).toString();
1616
returngetRequest(query);
1717
},
1818
/**
@@ -26,9 +26,10 @@ module.exports =function(getRequest, apiKey) {
2626
constmodule='proxy';
2727
constaction='eth_getBlockByNumber';
2828
constboolean=true;
29-
varquery=querystring.stringify({
29+
constqueryObject={
3030
module, action, tag, apiKey, boolean
31-
});
31+
};
32+
varquery=newURLSearchParams(queryObject).toString();
3233
returngetRequest(query);
3334
},
3435
/**
@@ -42,9 +43,10 @@ module.exports =function(getRequest, apiKey) {
4243
eth_getUncleByBlockNumberAndIndex(tag,index){
4344
constmodule='proxy';
4445
constaction='eth_getUncleByBlockNumberAndIndex';
45-
varquery=querystring.stringify({
46+
constqueryObject={
4647
module, action, apiKey, tag, index
47-
});
48+
};
49+
varquery=newURLSearchParams(queryObject).toString();
4850
returngetRequest(query);
4951
},
5052
/**
@@ -57,9 +59,10 @@ module.exports =function(getRequest, apiKey) {
5759
eth_getBlockTransactionCountByNumber(tag){
5860
constmodule='proxy';
5961
constaction='eth_getBlockTransactionCountByNumber';
60-
varquery=querystring.stringify({
62+
constqueryObject={
6163
module, action, apiKey, tag
62-
});
64+
};
65+
varquery=newURLSearchParams(queryObject).toString();
6366
returngetRequest(query);
6467
},
6568
/**
@@ -72,9 +75,10 @@ module.exports =function(getRequest, apiKey) {
7275
eth_getTransactionByHash(txhash){
7376
constmodule='proxy';
7477
constaction='eth_getTransactionByHash';
75-
varquery=querystring.stringify({
78+
constqueryObject={
7679
module, action, apiKey, txhash
77-
});
80+
};
81+
varquery=newURLSearchParams(queryObject).toString();
7882
returngetRequest(query);
7983
},
8084
/**
@@ -88,9 +92,10 @@ module.exports =function(getRequest, apiKey) {
8892
eth_getTransactionByBlockNumberAndIndex(tag,index){
8993
constmodule='proxy';
9094
constaction='eth_getTransactionByBlockNumberAndIndex';
91-
varquery=querystring.stringify({
95+
constqueryObject={
9296
module, action, apiKey, tag, index
93-
});
97+
};
98+
varquery=newURLSearchParams(queryObject).toString();
9499
returngetRequest(query);
95100
},
96101
/**
@@ -103,9 +108,10 @@ module.exports =function(getRequest, apiKey) {
103108
eth_getTransactionCount(address){
104109
constmodule='proxy';
105110
constaction='eth_getTransactionCount';
106-
varquery=querystring.stringify({
111+
constqueryObject={
107112
module, action, apiKey, address
108-
});
113+
};
114+
varquery=newURLSearchParams(queryObject).toString();
109115
returngetRequest(query);
110116
},
111117
/**
@@ -118,9 +124,10 @@ module.exports =function(getRequest, apiKey) {
118124
eth_sendRawTransaction(hex){
119125
constmodule='proxy';
120126
constaction='eth_sendRawTransaction';
121-
varquery=querystring.stringify({
127+
constqueryObject={
122128
module, action, apiKey, hex
123-
});
129+
};
130+
varquery=newURLSearchParams(queryObject).toString();
124131
returngetRequest(query);
125132
},
126133
/**
@@ -133,9 +140,11 @@ module.exports =function(getRequest, apiKey) {
133140
eth_getTransactionReceipt(txhash){
134141
constmodule='proxy';
135142
constaction='eth_getTransactionReceipt';
136-
varquery=querystring.stringify({
143+
144+
constqueryObject={
137145
module, action, apiKey, txhash
138-
});
146+
};
147+
varquery=newURLSearchParams(queryObject).toString();
139148
returngetRequest(query);
140149
},
141150
/**
@@ -150,9 +159,10 @@ module.exports =function(getRequest, apiKey) {
150159
eth_call(to,data,tag){
151160
constmodule='proxy';
152161
constaction='eth_call';
153-
varquery=querystring.stringify({
162+
constqueryObject={
154163
module, action, apiKey, to, data, tag
155-
});
164+
};
165+
varquery=newURLSearchParams(queryObject).toString();
156166
returngetRequest(query);
157167
},
158168
/**
@@ -166,9 +176,10 @@ module.exports =function(getRequest, apiKey) {
166176
eth_getCode(address,tag){
167177
constmodule='proxy';
168178
constaction='eth_getCode';
169-
varquery=querystring.stringify({
179+
constqueryObject={
170180
module, action, apiKey, address, tag
171-
});
181+
};
182+
varquery=newURLSearchParams(queryObject).toString();
172183
returngetRequest(query);
173184
},
174185
/**
@@ -183,9 +194,10 @@ module.exports =function(getRequest, apiKey) {
183194
eth_getStorageAt(address,position,tag){
184195
constmodule='proxy';
185196
constaction='eth_getStorageAt';
186-
varquery=querystring.stringify({
197+
constqueryObject={
187198
module, action, apiKey, address, position, tag
188-
});
199+
}
200+
varquery=newURLSearchParams(queryObject).toString();
189201
returngetRequest(query);
190202
},
191203
/**
@@ -196,9 +208,10 @@ module.exports =function(getRequest, apiKey) {
196208
eth_gasPrice(){
197209
constmodule='proxy';
198210
constaction='eth_gasPrice';
199-
varquery=querystring.stringify({
211+
constqueryObject={
200212
module, action, apiKey
201-
});
213+
};
214+
varquery=newURLSearchParams(queryObject).toString();
202215
returngetRequest(query);
203216
},
204217
/**
@@ -219,9 +232,10 @@ module.exports =function(getRequest, apiKey) {
219232
eth_estimateGas(to,value,gasPrice,gas){
220233
constmodule='proxy';
221234
constaction='eth_estimateGas';
222-
varquery=querystring.stringify({
235+
constqueryObject={
223236
module, action, apiKey, to, value, gasPrice, gas
224-
});
237+
}
238+
varquery=newURLSearchParams(queryObject).toString();
225239
returngetRequest(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-
constquerystring=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-
varquery=querystring.stringify(params);
27+
varquery=newURLSearchParams(params).toString();
2928
returngetRequest(query);
3029
},
3130

@@ -37,9 +36,10 @@ module.exports = function(getRequest, apiKey) {
3736
ethsupply(){
3837
constmodule='stats';
3938
constaction='ethsupply';
40-
varquery=querystring.stringify({
39+
constqueryObject={
4140
module, action, apiKey
42-
});
41+
}
42+
varquery=newURLSearchParams(queryObject).toString();
4343
returngetRequest(query);
4444
},
4545

@@ -52,9 +52,10 @@ module.exports = function(getRequest, apiKey) {
5252
ethprice(){
5353
constmodule='stats';
5454
constaction='ethprice';
55-
varquery=querystring.stringify({
55+
constqueryOBject={
5656
module, action, apiKey
57-
});
57+
};
58+
varquery=newURLSearchParams(queryObject).toString();
5859
returngetRequest(query);
5960
}
6061
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp