@@ -21,16 +21,16 @@ const level = require('level-mem')
21
21
const semaphore = require ( 'semaphore' )
22
22
23
23
export default class Blockchain {
24
- _common : any
25
- _genesis : any
26
- _headBlock : any
27
- _headHeader : any
28
- _heads : any
29
- _initDone : boolean
30
- _initLock : any
31
- _putSemaphore : any
32
- _staleHeadBlock : any
33
- _staleHeads : any
24
+ private _common : Common
25
+ private _genesis : any
26
+ private _headBlock : any
27
+ private _headHeader : any
28
+ private _heads : any
29
+ private _initDone : boolean
30
+ private _initLock : any
31
+ private _putSemaphore : any
32
+ private _staleHeadBlock : any
33
+ private _staleHeads : any
34
34
35
35
db : any
36
36
dbManager : DBManager
@@ -91,7 +91,7 @@ export default class Blockchain {
91
91
* hashes of the headerchain head, blockchain head, genesis block and iterator
92
92
* heads.
93
93
*/
94
- _init ( cb : any ) : void {
94
+ private _init ( cb : any ) : void {
95
95
const self = this
96
96
97
97
async . waterfall (
@@ -148,7 +148,7 @@ export default class Blockchain {
148
148
/**
149
149
* Sets the default genesis block
150
150
*/
151
- _setCanonicalGenesisBlock ( cb : any ) : void {
151
+ private _setCanonicalGenesisBlock ( cb : any ) : void {
152
152
const genesisBlock = new Block ( null , { common : this . _common } )
153
153
genesisBlock . setGenesisParams ( )
154
154
this . _putBlockOrHeader ( genesisBlock , cb , true )
@@ -259,7 +259,7 @@ export default class Blockchain {
259
259
} )
260
260
}
261
261
262
- _putBlockOrHeader ( item : any , cb : any , isGenesis ?: boolean ) {
262
+ private _putBlockOrHeader ( item : any , cb : any , isGenesis ?: boolean ) {
263
263
const self = this
264
264
const isHeader = item instanceof Block . Header
265
265
let block = isHeader ? new Block ( [ item . raw , [ ] , [ ] ] , { common : item . _common } ) : item
@@ -523,7 +523,7 @@ export default class Blockchain {
523
523
)
524
524
}
525
525
526
- _saveHeadOps ( ) {
526
+ private _saveHeadOps ( ) {
527
527
return [
528
528
{
529
529
type : 'put' ,
@@ -549,14 +549,14 @@ export default class Blockchain {
549
549
]
550
550
}
551
551
552
- _saveHeads ( cb : any ) {
552
+ private _saveHeads ( cb : any ) {
553
553
this . _batchDbOps ( this . _saveHeadOps ( ) , cb )
554
554
}
555
555
556
556
/**
557
557
* Delete canonical number assignments for specified number and above
558
558
*/
559
- _deleteStaleAssignments ( number : BN , headHash : Buffer , ops : any , cb : any ) {
559
+ private _deleteStaleAssignments ( number : BN , headHash : Buffer , ops : any , cb : any ) {
560
560
const key = numberToHashKey ( number )
561
561
562
562
this . _numberToHash ( number , ( err ?: any , hash ?: Buffer ) => {
@@ -586,7 +586,7 @@ export default class Blockchain {
586
586
}
587
587
588
588
// overwrite stale canonical number assignments
589
- _rebuildCanonical ( header : any , ops : any , cb : any ) {
589
+ private _rebuildCanonical ( header : any , ops : any , cb : any ) {
590
590
const self = this
591
591
const hash = header . hash ( )
592
592
const number = new BN ( header . number )
@@ -677,7 +677,7 @@ export default class Blockchain {
677
677
} )
678
678
}
679
679
680
- _delBlock ( blockHash : Buffer | typeof Block , cb : any ) {
680
+ private _delBlock ( blockHash : Buffer | typeof Block , cb : any ) {
681
681
const self = this
682
682
const dbOps : any [ ] = [ ]
683
683
let blockHeader = null
@@ -734,7 +734,7 @@ export default class Blockchain {
734
734
}
735
735
}
736
736
737
- _delChild ( hash : Buffer , number : BN , headHash : Buffer , ops : any , cb : any ) {
737
+ private _delChild ( hash : Buffer , number : BN , headHash : Buffer , ops : any , cb : any ) {
738
738
const self = this
739
739
740
740
// delete header, body, hash to number mapping and td
@@ -798,7 +798,7 @@ export default class Blockchain {
798
798
} )
799
799
}
800
800
801
- _iterator ( name : string , func : any , cb : any ) {
801
+ private _iterator ( name : string , func : any , cb : any ) {
802
802
const self = this
803
803
const blockHash = self . _heads [ name ] || self . _genesis
804
804
let blockNumber : any
@@ -851,28 +851,28 @@ export default class Blockchain {
851
851
/**
852
852
* Executes multiple db operations in a single batch call
853
853
*/
854
- _batchDbOps ( dbOps : any , cb : any ) : void {
854
+ private _batchDbOps ( dbOps : any , cb : any ) : void {
855
855
util . callbackify ( this . dbManager . batch . bind ( this . dbManager ) ) ( dbOps , cb )
856
856
}
857
857
858
858
/**
859
859
* Performs a block hash to block number lookup
860
860
*/
861
- _hashToNumber ( hash : Buffer , cb : any ) : void {
861
+ private _hashToNumber ( hash : Buffer , cb : any ) : void {
862
862
util . callbackify ( this . dbManager . hashToNumber . bind ( this . dbManager ) ) ( hash , cb )
863
863
}
864
864
865
865
/**
866
866
* Performs a block number to block hash lookup
867
867
*/
868
- _numberToHash ( number : BN , cb : any ) : void {
868
+ private _numberToHash ( number : BN , cb : any ) : void {
869
869
util . callbackify ( this . dbManager . numberToHash . bind ( this . dbManager ) ) ( number , cb )
870
870
}
871
871
872
872
/**
873
873
* Helper function to lookup a block by either hash only or a hash and number pair
874
874
*/
875
- _lookupByHashNumber ( hash : Buffer , number : BN , cb : any , next : any ) : void {
875
+ private _lookupByHashNumber ( hash : Buffer , number : BN , cb : any , next : any ) : void {
876
876
if ( typeof number === 'function' ) {
877
877
cb = number
878
878
return this . _hashToNumber ( hash , ( err ?: any , number ?: BN ) => {
@@ -888,7 +888,7 @@ export default class Blockchain {
888
888
/**
889
889
* Gets a header by hash and number. Header can exist outside the canonical chain
890
890
*/
891
- _getHeader ( hash : Buffer , number : any , cb ?: any ) : void {
891
+ private _getHeader ( hash : Buffer , number : any , cb ?: any ) : void {
892
892
this . _lookupByHashNumber (
893
893
hash ,
894
894
number ,
@@ -905,7 +905,7 @@ export default class Blockchain {
905
905
/**
906
906
* Gets a header by number. Header must be in the canonical chain
907
907
*/
908
- _getCanonicalHeader ( number : BN , cb : any ) : void {
908
+ private _getCanonicalHeader ( number : BN , cb : any ) : void {
909
909
this . _numberToHash ( number , ( err : Error | undefined , hash : Buffer ) => {
910
910
if ( err ) {
911
911
return cb ( err )
@@ -917,7 +917,7 @@ export default class Blockchain {
917
917
/**
918
918
* Gets total difficulty for a block specified by hash and number
919
919
*/
920
- _getTd ( hash : any , number : any , cb ?: any ) : void {
920
+ private _getTd ( hash : any , number : any , cb ?: any ) : void {
921
921
this . _lookupByHashNumber (
922
922
hash ,
923
923
number ,
@@ -931,7 +931,7 @@ export default class Blockchain {
931
931
)
932
932
}
933
933
934
- _lockUnlock ( fn : any , cb : any ) : void {
934
+ private _lockUnlock ( fn : any , cb : any ) : void {
935
935
const self = this
936
936
this . _putSemaphore . take ( ( ) => {
937
937
fn ( after )
0 commit comments