This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,8 @@ const multihash = require('multihashes')
6
6
module . exports = function block ( self ) {
7
7
return {
8
8
get : ( hash , callback ) => {
9
- if ( typeof hash === 'string' ) {
10
- hash = multihash . fromB58String ( hash )
11
- }
9
+ hash = cleanHash ( hash )
10
+
12
11
self . _blockS . getBlock ( hash , callback )
13
12
} ,
14
13
put : ( block , callback ) => {
@@ -24,16 +23,11 @@ module.exports = function block (self) {
24
23
} )
25
24
} ,
26
25
del : ( hash , callback ) => {
27
- if ( typeof hash === 'string' ) {
28
- hash = multihash . fromB58String ( hash )
29
- }
30
-
26
+ hash = cleanHash ( hash )
31
27
self . _blockS . deleteBlock ( hash , callback )
32
28
} ,
33
29
stat : ( hash , callback ) => {
34
- if ( typeof hash === 'string' ) {
35
- hash = multihash . fromB58String ( hash )
36
- }
30
+ hash = cleanHash ( hash )
37
31
38
32
self . _blockS . getBlock ( hash , ( err , block ) => {
39
33
if ( err ) {
@@ -47,3 +41,10 @@ module.exports = function block (self) {
47
41
}
48
42
}
49
43
}
44
+
45
+ function cleanHash ( hash ) {
46
+ if ( typeof hash === 'string' ) {
47
+ return multihash . fromB58String ( hash )
48
+ }
49
+ return hash
50
+ }
You can’t perform that action at this time.
0 commit comments