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')
66module . exports = function block ( self ) {
77 return {
88 get : ( hash , callback ) => {
9- if ( typeof hash === 'string' ) {
10- hash = multihash . fromB58String ( hash )
11- }
9+ hash = cleanHash ( hash )
10+
1211 self . _blockS . getBlock ( hash , callback )
1312 } ,
1413 put : ( block , callback ) => {
@@ -24,16 +23,11 @@ module.exports = function block (self) {
2423 } )
2524 } ,
2625 del : ( hash , callback ) => {
27- if ( typeof hash === 'string' ) {
28- hash = multihash . fromB58String ( hash )
29- }
30-
26+ hash = cleanHash ( hash )
3127 self . _blockS . deleteBlock ( hash , callback )
3228 } ,
3329 stat : ( hash , callback ) => {
34- if ( typeof hash === 'string' ) {
35- hash = multihash . fromB58String ( hash )
36- }
30+ hash = cleanHash ( hash )
3731
3832 self . _blockS . getBlock ( hash , ( err , block ) => {
3933 if ( err ) {
@@ -47,3 +41,10 @@ module.exports = function block (self) {
4741 }
4842 }
4943}
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