Conditions | 1 |
Paths | 1 |
Total Lines | 333 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var assert = require('assert'); |
||
70 | describe("convertBlockTx", function() { |
||
71 | it("works", function(cb) { |
||
72 | var input = { |
||
73 | "data": { |
||
74 | "total_count": 388, |
||
75 | "page": 1, |
||
76 | "pagesize": 50, |
||
77 | "list": [ |
||
78 | { |
||
79 | "confirmations": 310251, |
||
80 | "block_height": 200000, |
||
81 | "block_time": 1348310759, |
||
82 | "created_at": 1492101215, |
||
83 | "fee": 63517500, |
||
84 | "hash": "dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10", |
||
85 | "inputs_count": 1, |
||
86 | "inputs_value": 0, |
||
87 | "is_coinbase": true, |
||
88 | "is_double_spend": false, |
||
89 | "is_sw_tx": false, |
||
90 | "weight": 768, |
||
91 | "vsize": 192, |
||
92 | "witness_hash": "dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10", |
||
93 | "lock_time": 0, |
||
94 | "outputs_count": 1, |
||
95 | "outputs_value": 5063517500, |
||
96 | "size": 192, |
||
97 | "sigops": 4, |
||
98 | "version": 1, |
||
99 | "inputs": [ |
||
100 | { |
||
101 | "prev_addresses": [], |
||
102 | "prev_position": -1, |
||
103 | "prev_tx_hash": "0000000000000000000000000000000000000000000000000000000000000000", |
||
104 | "prev_type": "NONSTANDARD", |
||
105 | "prev_value": 0, |
||
106 | "sequence": 4294967295, |
||
107 | "script_asm": "", |
||
108 | "script_hex": "03400d0302ef02062f503253482f522cfabe6d6dd90d39663d10f8fd25ec88338295d4c6ce1c90d4aeb368d8bdbadcc1da3b635801000000000000000474073e03", |
||
109 | "witness": [] |
||
110 | } |
||
111 | ], |
||
112 | "outputs": [ |
||
113 | { |
||
114 | "addresses": [ |
||
115 | "1MdYC22Gmjp2ejVPCxyYjFyWbQCYTGhGq8" |
||
116 | ], |
||
117 | "value": 5063517500, |
||
118 | "type": "P2PKH_PUBKEY", |
||
119 | "script_asm": "04b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7b OP_CHECKSIG", |
||
120 | "script_hex": "4104b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7bac", |
||
121 | "spent_by_tx": "5c76eb4dfb0941856a229833ef05b2f5c669dadc98ed2a34ea11974cacba9dc7", |
||
122 | "spent_by_tx_position": 0 |
||
123 | } |
||
124 | ] |
||
125 | }, |
||
126 | { |
||
127 | "confirmations": 310251, |
||
128 | "block_height": 200000, |
||
129 | "block_time": 1348310759, |
||
130 | "created_at": 1492101215, |
||
131 | "fee": 0, |
||
132 | "hash": "ee475443f1fbfff84ffba43ba092a70d291df233bd1428f3d09f7bd1a6054a1f", |
||
133 | "inputs_count": 1, |
||
134 | "inputs_value": 10212000000, |
||
135 | "is_coinbase": false, |
||
136 | "is_double_spend": false, |
||
137 | "is_sw_tx": false, |
||
138 | "weight": 904, |
||
139 | "vsize": 226, |
||
140 | "witness_hash": "ee475443f1fbfff84ffba43ba092a70d291df233bd1428f3d09f7bd1a6054a1f", |
||
141 | "lock_time": 0, |
||
142 | "outputs_count": 2, |
||
143 | "outputs_value": 10212000000, |
||
144 | "size": 226, |
||
145 | "sigops": 8, |
||
146 | "version": 1, |
||
147 | "inputs": [ |
||
148 | { |
||
149 | "prev_addresses": [ |
||
150 | "1CfD77hupeUvFwBPxZ2fA8iyWmVwQY22oh" |
||
151 | ], |
||
152 | "prev_position": 1, |
||
153 | "prev_tx_hash": "6e046b9c7683b5887bbde42ec358542ffe9c250306edb2d0cf386394aa96ee10", |
||
154 | "prev_type": "P2PKH", |
||
155 | "prev_value": 10212000000, |
||
156 | "sequence": 4294967295, |
||
157 | "script_asm": "3045022100e5e4749d539a163039769f52e1ebc8e6f62e39387d61e1a305bd722116cded6c022014924b745dd02194fe6b5cb8ac88ee8e9a2aede89e680dcea6169ea696e24d52[ALL] 02b4b754609b46b5d09644c2161f1767b72b93847ce8154d795f95d31031a08aa2", |
||
158 | "script_hex": "483045022100e5e4749d539a163039769f52e1ebc8e6f62e39387d61e1a305bd722116cded6c022014924b745dd02194fe6b5cb8ac88ee8e9a2aede89e680dcea6169ea696e24d52012102b4b754609b46b5d09644c2161f1767b72b93847ce8154d795f95d31031a08aa2", |
||
159 | "witness": [] |
||
160 | } |
||
161 | ], |
||
162 | "outputs": [ |
||
163 | { |
||
164 | "addresses": [ |
||
165 | "1FhNPRh1TxVidoKkWFEpdmK5RXw9vG1KUb" |
||
166 | ], |
||
167 | "value": 5586000000, |
||
168 | "type": "P2PKH", |
||
169 | "script_asm": "OP_DUP OP_HASH160 a134408afa258a50ed7a1d9817f26b63cc9002cc OP_EQUALVERIFY OP_CHECKSIG", |
||
170 | "script_hex": "76a914a134408afa258a50ed7a1d9817f26b63cc9002cc88ac", |
||
171 | "spent_by_tx": "12c7db0b0f4baae58ee1be0fd925fbbf7588ea3339f38557978015ba120ca086", |
||
172 | "spent_by_tx_position": 0 |
||
173 | }, |
||
174 | { |
||
175 | "addresses": [ |
||
176 | "1QE7Tazy1uHD1utCb1fCW6aLF3RZ1sNwd2" |
||
177 | ], |
||
178 | "value": 4626000000, |
||
179 | "type": "P2PKH", |
||
180 | "script_asm": "OP_DUP OP_HASH160 fec5b1145596b35f59f8be1daf169f3759421433 OP_EQUALVERIFY OP_CHECKSIG", |
||
181 | "script_hex": "76a914fec5b1145596b35f59f8be1daf169f375942143388ac", |
||
182 | "spent_by_tx": "6cf0a98e6290c343c8eed9373ec63329a5147a491974d3a146bdbf466978b306", |
||
183 | "spent_by_tx_position": 0 |
||
184 | } |
||
185 | ] |
||
186 | }, |
||
187 | { |
||
188 | "confirmations": 310251, |
||
189 | "block_height": 200000, |
||
190 | "block_time": 1348310759, |
||
191 | "created_at": 1492101215, |
||
192 | "fee": 0, |
||
193 | "hash": "e03a9a4b5c557f6ee3400a29ff1475d1df73e9cddb48c2391abdc391d8c1504a", |
||
194 | "inputs_count": 1, |
||
195 | "inputs_value": 9500000000, |
||
196 | "is_coinbase": false, |
||
197 | "is_double_spend": false, |
||
198 | "is_sw_tx": false, |
||
199 | "weight": 900, |
||
200 | "vsize": 225, |
||
201 | "witness_hash": "e03a9a4b5c557f6ee3400a29ff1475d1df73e9cddb48c2391abdc391d8c1504a", |
||
202 | "lock_time": 0, |
||
203 | "outputs_count": 2, |
||
204 | "outputs_value": 9500000000, |
||
205 | "size": 225, |
||
206 | "sigops": 8, |
||
207 | "version": 1, |
||
208 | "inputs": [ |
||
209 | { |
||
210 | "prev_addresses": [ |
||
211 | "1DC8mbgdVFNZn7ie6wUVGegKHsqvKkN7Qn" |
||
212 | ], |
||
213 | "prev_position": 0, |
||
214 | "prev_tx_hash": "0530375a5bf4ea9a82494fcb5ef4a61076c2af807982076fa810851f4bc31c09", |
||
215 | "prev_type": "P2PKH", |
||
216 | "prev_value": 9500000000, |
||
217 | "sequence": 4294967295, |
||
218 | "script_asm": "304402202b5869e0b4e711784daecd511f9dadf28e37113ef5054a6898d0367034afb067022014dfd2f58da949550ddc4ebb1135527cdbc48b25c6eb6388cc88231fd7ea04a9[ALL] 02fec863d4d0baf5e01a9bd9c59b790bbf683c5b7b6624d7aa7ab9405c5fdb9786", |
||
219 | "script_hex": "47304402202b5869e0b4e711784daecd511f9dadf28e37113ef5054a6898d0367034afb067022014dfd2f58da949550ddc4ebb1135527cdbc48b25c6eb6388cc88231fd7ea04a9012102fec863d4d0baf5e01a9bd9c59b790bbf683c5b7b6624d7aa7ab9405c5fdb9786", |
||
220 | "witness": [] |
||
221 | } |
||
222 | ], |
||
223 | "outputs": [ |
||
224 | { |
||
225 | "addresses": [ |
||
226 | "1HtF7xbaDwJu1j5sKpetG91xr4AZHYmJTL" |
||
227 | ], |
||
228 | "value": 9400000000, |
||
229 | "type": "P2PKH", |
||
230 | "script_asm": "OP_DUP OP_HASH160 b933036b1f143e6ee5f9038c4205f6bbe41e49cc OP_EQUALVERIFY OP_CHECKSIG", |
||
231 | "script_hex": "76a914b933036b1f143e6ee5f9038c4205f6bbe41e49cc88ac", |
||
232 | "spent_by_tx": "360c0ee799aa6e00032f87d62751d5a20cd9e6c6245f6420971647c45aca59e9", |
||
233 | "spent_by_tx_position": 0 |
||
234 | }, |
||
235 | { |
||
236 | "addresses": [ |
||
237 | "1AQHgGfYswNkput7vzGzCUUzH4wQQkWKXr" |
||
238 | ], |
||
239 | "value": 100000000, |
||
240 | "type": "P2PKH", |
||
241 | "script_asm": "OP_DUP OP_HASH160 67209ed8971b9bdf4147cd25e5f09c77f43c0dac OP_EQUALVERIFY OP_CHECKSIG", |
||
242 | "script_hex": "76a91467209ed8971b9bdf4147cd25e5f09c77f43c0dac88ac", |
||
243 | "spent_by_tx": "4f67254491474ae03d8e023fae4bf249e1f81b07efb6ea763a13c9bc7b4210b3", |
||
244 | "spent_by_tx_position": 1 |
||
245 | } |
||
246 | ] |
||
247 | }, |
||
248 | { |
||
249 | "confirmations": 310251, |
||
250 | "block_height": 200000, |
||
251 | "block_time": 1348310759, |
||
252 | "created_at": 1492101215, |
||
253 | "fee": 0, |
||
254 | "hash": "ffa0267c8f2af736858894d6f3e5081a05e2ec16dc98f78a80f376ce35077491", |
||
255 | "inputs_count": 1, |
||
256 | "inputs_value": 37325663465, |
||
257 | "is_coinbase": false, |
||
258 | "is_double_spend": false, |
||
259 | "is_sw_tx": false, |
||
260 | "weight": 1032, |
||
261 | "vsize": 258, |
||
262 | "witness_hash": "ffa0267c8f2af736858894d6f3e5081a05e2ec16dc98f78a80f376ce35077491", |
||
263 | "lock_time": 0, |
||
264 | "outputs_count": 2, |
||
265 | "outputs_value": 37325663465, |
||
266 | "size": 258, |
||
267 | "sigops": 8, |
||
268 | "version": 1, |
||
269 | "inputs": [ |
||
270 | { |
||
271 | "prev_addresses": [ |
||
272 | "1AGt1P3fhCF9MUue3dheegBZgGVHeLAtLr" |
||
273 | ], |
||
274 | "prev_position": 1, |
||
275 | "prev_tx_hash": "1fa6ecf02e5de2001e4aec6d3e90b5ef6d81aead39e7f04f303e6c8415547bba", |
||
276 | "prev_type": "P2PKH", |
||
277 | "prev_value": 37325663465, |
||
278 | "sequence": 4294967295, |
||
279 | "script_asm": "3045022001b572518fe610121b777286b424d89ba73fe503ff440458f01361a29348248b022100fa1afae0ccf3007d208605662685dd57e6940066ae6be81aa8b2af319060fceb[ALL] 04f28840b52c60c0fa041b9f4b2fa3dd00bccd71c0ab03f4db3c4295a23b117535fdd6d34787f95870d51ec245c800d851dd8509de42c47a0dc7a09300053110b8", |
||
280 | "script_hex": "483045022001b572518fe610121b777286b424d89ba73fe503ff440458f01361a29348248b022100fa1afae0ccf3007d208605662685dd57e6940066ae6be81aa8b2af319060fceb014104f28840b52c60c0fa041b9f4b2fa3dd00bccd71c0ab03f4db3c4295a23b117535fdd6d34787f95870d51ec245c800d851dd8509de42c47a0dc7a09300053110b8", |
||
281 | "witness": [] |
||
282 | } |
||
283 | ], |
||
284 | "outputs": [ |
||
285 | { |
||
286 | "addresses": [ |
||
287 | "1D5Em12TqtZtX3LJHYiGjarKCVss4nMmGP" |
||
288 | ], |
||
289 | "value": 17749527722, |
||
290 | "type": "P2PKH", |
||
291 | "script_asm": "OP_DUP OP_HASH160 846ea88b63aa1dbf265a33127f518974402870bd OP_EQUALVERIFY OP_CHECKSIG", |
||
292 | "script_hex": "76a914846ea88b63aa1dbf265a33127f518974402870bd88ac", |
||
293 | "spent_by_tx": "0e6641d59cbcbbb2df61f1f80b044642dd68916096de00f9d9e4f0106e148d2c", |
||
294 | "spent_by_tx_position": 1 |
||
295 | }, |
||
296 | { |
||
297 | "addresses": [ |
||
298 | "13b9rHKTNBMdKWmoiKM8o7Gx5zkvJwZG6x" |
||
299 | ], |
||
300 | "value": 19576135743, |
||
301 | "type": "P2PKH", |
||
302 | "script_asm": "OP_DUP OP_HASH160 1c65c81774aa85e123b0e5c51bc7cda6805f154e OP_EQUALVERIFY OP_CHECKSIG", |
||
303 | "script_hex": "76a9141c65c81774aa85e123b0e5c51bc7cda6805f154e88ac", |
||
304 | "spent_by_tx": "93ee77570a26841bc55a76a0739024b6521183a7d2fee3a0320570c41d01b76f", |
||
305 | "spent_by_tx_position": 0 |
||
306 | } |
||
307 | ] |
||
308 | }, |
||
309 | { |
||
310 | "confirmations": 310251, |
||
311 | "block_height": 200000, |
||
312 | "block_time": 1348310759, |
||
313 | "created_at": 1492101215, |
||
314 | "fee": 50000, |
||
315 | "hash": "2674c8a46b75e5a5e3287a34d7999a1e5e6f052be36f63f3cb483ec148c9b86c", |
||
316 | "inputs_count": 1, |
||
317 | "inputs_value": 946622517855, |
||
318 | "is_coinbase": false, |
||
319 | "is_double_spend": false, |
||
320 | "is_sw_tx": false, |
||
321 | "weight": 908, |
||
322 | "vsize": 227, |
||
323 | "witness_hash": "2674c8a46b75e5a5e3287a34d7999a1e5e6f052be36f63f3cb483ec148c9b86c", |
||
324 | "lock_time": 0, |
||
325 | "outputs_count": 2, |
||
326 | "outputs_value": 946622467855, |
||
327 | "size": 227, |
||
328 | "sigops": 8, |
||
329 | "version": 1, |
||
330 | "inputs": [ |
||
331 | { |
||
332 | "prev_addresses": [ |
||
333 | "14DeXEwWrpo7urTz76LgQpxXtF8SAQMTbe" |
||
334 | ], |
||
335 | "prev_position": 0, |
||
336 | "prev_tx_hash": "a8d4bb8395b6a59ff0355a145b3c0a63d42966af02c373e4c86e4d2779f514e2", |
||
337 | "prev_type": "P2PKH", |
||
338 | "prev_value": 946622517855, |
||
339 | "sequence": 4294967295, |
||
340 | "script_asm": "3046022100d9331c464433c16e59947d6d36df23cd6d29160e97e2707c27bd7641d291a3380221008b1927354afb5a1bd0412fdbde7a3141cba991342ac17505bf13452dac4a533a[ALL] 0319a9a55c1e4dfd168adae85af834ec0db91ae1c164c7286316155a9135afcee8", |
||
341 | "script_hex": "493046022100d9331c464433c16e59947d6d36df23cd6d29160e97e2707c27bd7641d291a3380221008b1927354afb5a1bd0412fdbde7a3141cba991342ac17505bf13452dac4a533a01210319a9a55c1e4dfd168adae85af834ec0db91ae1c164c7286316155a9135afcee8", |
||
342 | "witness": [] |
||
343 | } |
||
344 | ], |
||
345 | "outputs": [ |
||
346 | { |
||
347 | "addresses": [ |
||
348 | "1Fg7BsVkTk1gWnWTpgyb26Zo6NGNsx2gcQ" |
||
349 | ], |
||
350 | "value": 945815591855, |
||
351 | "type": "P2PKH", |
||
352 | "script_asm": "OP_DUP OP_HASH160 a0f7260313ab5798391cb610bc4fe0a6be883d59 OP_EQUALVERIFY OP_CHECKSIG", |
||
353 | "script_hex": "76a914a0f7260313ab5798391cb610bc4fe0a6be883d5988ac", |
||
354 | "spent_by_tx": "981db136c4efaa9f91db680bf16aa2e38a0bc13e70f56d5f10b1b86903973f51", |
||
355 | "spent_by_tx_position": 0 |
||
356 | }, |
||
357 | { |
||
358 | "addresses": [ |
||
359 | "1Q22kYfL81iaAZZLj4epvUQ3yLv57Mgd56" |
||
360 | ], |
||
361 | "value": 806876000, |
||
362 | "type": "P2PKH", |
||
363 | "script_asm": "OP_DUP OP_HASH160 fc7cc53ddff31d4c6b18ea7331b80f2b76d7a45d OP_EQUALVERIFY OP_CHECKSIG", |
||
364 | "script_hex": "76a914fc7cc53ddff31d4c6b18ea7331b80f2b76d7a45d88ac", |
||
365 | "spent_by_tx": "a68c971e3666c36717fe2ec80e6ebbefd5045601476d5c845b90c26c4fa2a71d", |
||
366 | "spent_by_tx_position": 9 |
||
367 | } |
||
368 | ] |
||
369 | } |
||
370 | ] |
||
371 | }, |
||
372 | "err_no": 0, |
||
373 | "err_msg": null |
||
374 | }; |
||
375 | |||
376 | var output = converter.convertBlockTx(input); |
||
377 | assert.ok("current_page" in output); |
||
378 | assert.ok("per_page" in output); |
||
379 | assert.ok("total" in output); |
||
380 | |||
381 | [ |
||
382 | ["size", "size"], |
||
383 | ["hash", "hash"], |
||
384 | ["confirmations", "confirmations"], |
||
385 | ["is_coinbase", "is_coinbase"], |
||
386 | ["total_fee", "fee"], |
||
387 | ["size", "size"], |
||
388 | ["is_double_spend", "is_double_spend"] |
||
389 | |||
390 | ].map(function(keyAssoc) { |
||
391 | var blocktrailKey = keyAssoc[0]; |
||
392 | var btccomKey = keyAssoc[1]; |
||
393 | var blockTx = output.data[0]; |
||
394 | console.log(blocktrailKey) |
||
|
|||
395 | assert.ok(blocktrailKey in blockTx); |
||
396 | console.log(input.data.list[0][btccomKey],blockTx[blocktrailKey]) |
||
397 | assert.ok(input.data.list[0][btccomKey] == blockTx[blocktrailKey]) |
||
398 | }); |
||
399 | |||
400 | cb(); |
||
401 | }) |
||
402 | }); |
||
403 | |||
839 |