11import { EntryStatus , distance } from '@chainsafe/discv5'
22import { ENR } from '@chainsafe/enr'
3- import { bigIntToHex , bytesToHex , hexToBytes , short } from '@ethereumjs/util'
3+ import { bigIntToHex , bytesToHex , hexToBytes , PrefixedHexString , short } from '@ethereumjs/util'
44import {
55 ContentLookup ,
66 FoundContent ,
@@ -735,7 +735,7 @@ export class portal {
735735 const [ contentKey ] = params
736736 this . logger ( `Received historyLocalContent request for ${ contentKey } ` )
737737
738- const res = await this . _history . findContentLocally ( hexToBytes ( contentKey ) )
738+ const res = await this . _history . findContentLocally ( hexToBytes ( contentKey as PrefixedHexString ) )
739739 this . logger . extend ( 'historyLocalContent' ) (
740740 `request returned ${ res !== undefined ? res . length : 'null' } bytes` ,
741741 )
@@ -754,7 +754,7 @@ export class portal {
754754 const [ contentKey ] = params
755755 this . logger ( `Received stateLocalContent request for ${ contentKey } ` )
756756
757- const res = await this . _state . findContentLocally ( hexToBytes ( contentKey ) )
757+ const res = await this . _state . findContentLocally ( hexToBytes ( contentKey as PrefixedHexString ) )
758758 this . logger . extend ( 'stateLocalContent' ) ( `request returned ${ res ?. length } bytes` )
759759 this . logger . extend ( 'stateLocalContent' ) (
760760 `${ res !== undefined ? bytesToHex ( res ) : 'content not found' } ` ,
@@ -771,7 +771,7 @@ export class portal {
771771 const [ contentKey ] = params
772772 this . logger . extend ( 'beaconLocalContent' ) ( `Received request for ${ contentKey } ` )
773773
774- const content = await this . _beacon . findContentLocally ( hexToBytes ( contentKey ) )
774+ const content = await this . _beacon . findContentLocally ( hexToBytes ( contentKey as PrefixedHexString ) )
775775 this . logger . extend ( 'beaconLocalContent' ) (
776776 `request returned ${ content !== undefined ? content . length : 'null' } bytes` ,
777777 )
@@ -787,7 +787,7 @@ export class portal {
787787
788788 // portal_*Store
789789 async historyStore ( params : [ string , string ] ) {
790- const [ contentKey , content ] = params . map ( ( param ) => hexToBytes ( param ) )
790+ const [ contentKey , content ] = params . map ( ( param ) => hexToBytes ( param as PrefixedHexString ) )
791791 try {
792792 await this . _history . store ( contentKey , content )
793793 return true
@@ -798,8 +798,8 @@ export class portal {
798798 async stateStore ( params : [ string , string ] ) {
799799 const [ contentKey , content ] = params
800800 try {
801- const contentKeyBytes = hexToBytes ( contentKey )
802- await this . _state . store ( contentKeyBytes , hexToBytes ( content ) )
801+ const contentKeyBytes = hexToBytes ( contentKey as PrefixedHexString )
802+ await this . _state . store ( contentKeyBytes , hexToBytes ( content as PrefixedHexString ) )
803803 this . logger ( `stored ${ contentKey } in state network db` )
804804 return true
805805 } catch {
@@ -808,7 +808,7 @@ export class portal {
808808 }
809809 }
810810 async beaconStore ( params : [ string , string ] ) {
811- const [ contentKey , content ] = params . map ( ( param ) => hexToBytes ( param ) )
811+ const [ contentKey , content ] = params . map ( ( param ) => hexToBytes ( param as PrefixedHexString ) )
812812 try {
813813 await this . _beacon . store ( contentKey , content )
814814 return true
@@ -819,7 +819,7 @@ export class portal {
819819 }
820820 // portal_*PutContent
821821 async historyPutContent ( params : [ string , string ] ) {
822- const [ contentKey , content ] = params . map ( ( param ) => hexToBytes ( param ) )
822+ const [ contentKey , content ] = params . map ( ( param ) => hexToBytes ( param as PrefixedHexString ) )
823823 const contentId = this . _history . contentKeyToId ( contentKey )
824824 const d = distance ( contentId , this . _client . discv5 . enr . nodeId )
825825 let storedLocally = false
@@ -841,7 +841,7 @@ export class portal {
841841 }
842842 }
843843 async statePutContent ( params : [ string , string ] ) {
844- const [ contentKey , content ] = params . map ( ( param ) => hexToBytes ( param ) )
844+ const [ contentKey , content ] = params . map ( ( param ) => hexToBytes ( param as PrefixedHexString ) )
845845 const contentId = this . _state . contentKeyToId ( contentKey )
846846 const d = distance ( contentId , this . _client . discv5 . enr . nodeId )
847847 let storedLocally = false
@@ -863,7 +863,7 @@ export class portal {
863863 }
864864 }
865865 async beaconPutContent ( params : [ string , string ] ) {
866- const [ contentKey , content ] = params . map ( ( param ) => hexToBytes ( param ) )
866+ const [ contentKey , content ] = params . map ( ( param ) => hexToBytes ( param as PrefixedHexString ) )
867867 const contentId = this . _beacon . contentKeyToId ( contentKey )
868868 const d = distance ( contentId , this . _client . discv5 . enr . nodeId )
869869 let storedLocally = false
@@ -892,7 +892,7 @@ export class portal {
892892 this . logger . extend ( 'findContent' ) (
893893 `received request to send request to ${ shortId ( nodeId ) } for contentKey ${ contentKey } ` ,
894894 )
895- const res = await this . _history . sendFindContent ( ENR . decodeTxt ( enr ) , hexToBytes ( contentKey ) )
895+ const res = await this . _history . sendFindContent ( ENR . decodeTxt ( enr ) , hexToBytes ( contentKey as PrefixedHexString ) )
896896 if ( res === undefined ) {
897897 this . logger . extend ( 'findContent' ) ( 'request returned undefined' )
898898 return undefined
@@ -924,7 +924,7 @@ export class portal {
924924 this . logger . extend ( 'findContent' ) (
925925 `received request to send request to ${ shortId ( nodeId ) } for contentKey ${ contentKey } ` ,
926926 )
927- const res = await this . _state . sendFindContent ( ENR . decodeTxt ( enr ) , hexToBytes ( contentKey ) )
927+ const res = await this . _state . sendFindContent ( ENR . decodeTxt ( enr ) , hexToBytes ( contentKey as PrefixedHexString ) )
928928 if ( res === undefined ) {
929929 this . logger . extend ( 'findContent' ) ( 'request returned type: ENRS' )
930930 return { enrs : [ ] }
@@ -957,7 +957,7 @@ export class portal {
957957 }
958958 }
959959
960- const res = await this . _beacon . sendFindContent ( ENR . decodeTxt ( enr ) , hexToBytes ( contentKey ) )
960+ const res = await this . _beacon . sendFindContent ( ENR . decodeTxt ( enr ) , hexToBytes ( contentKey as PrefixedHexString ) )
961961
962962 if ( res === undefined ) {
963963 this . logger . extend ( 'findContent' ) ( 'request returned type: ENRS' )
@@ -983,7 +983,7 @@ export class portal {
983983 async historyGetContent ( params : [ string ] ) {
984984 const [ contentKey ] = params
985985 this . logger . extend ( 'historyGetContent' ) ( `request received for ${ contentKey } ` )
986- const lookup = new ContentLookup ( this . _history , hexToBytes ( contentKey ) )
986+ const lookup = new ContentLookup ( this . _history , hexToBytes ( contentKey as PrefixedHexString ) )
987987 const res = await lookup . startLookup ( )
988988 if ( res === undefined ) {
989989 this . logger . extend ( 'historyGetContent' ) ( 'request returned { enrs: [] }' )
@@ -1010,7 +1010,7 @@ export class portal {
10101010 async stateGetContent ( params : [ string ] ) {
10111011 const [ contentKey ] = params
10121012 this . logger . extend ( 'stateGetContent' ) ( `request received for ${ contentKey } ` )
1013- const lookup = new ContentLookup ( this . _state , hexToBytes ( contentKey ) )
1013+ const lookup = new ContentLookup ( this . _state , hexToBytes ( contentKey as PrefixedHexString ) )
10141014 const res = await lookup . startLookup ( )
10151015 if ( ! res ) {
10161016 this . logger . extend ( 'stateGetContent' ) ( 'request returned { enrs: [] }' )
@@ -1037,7 +1037,7 @@ export class portal {
10371037 async beaconGetContent ( params : [ string ] ) {
10381038 const [ contentKey ] = params
10391039 this . logger . extend ( 'beaconGetContent' ) ( `request received for ${ contentKey } ` )
1040- const lookup = new ContentLookup ( this . _beacon , hexToBytes ( contentKey ) )
1040+ const lookup = new ContentLookup ( this . _beacon , hexToBytes ( contentKey as PrefixedHexString ) )
10411041 const res = await lookup . startLookup ( )
10421042 this . logger . extend ( 'beaconGetContent' ) ( `request returned ${ JSON . stringify ( res ) } ` )
10431043 if ( ! res ) {
@@ -1067,7 +1067,7 @@ export class portal {
10671067 async historyTraceGetContent ( params : [ string ] ) {
10681068 const [ contentKey ] = params
10691069 this . logger . extend ( 'historyTraceGetContent' ) ( `request received for ${ contentKey } ` )
1070- const lookup = new ContentLookup ( this . _history , hexToBytes ( contentKey ) , true )
1070+ const lookup = new ContentLookup ( this . _history , hexToBytes ( contentKey as PrefixedHexString ) , true )
10711071 const res = await lookup . startLookup ( )
10721072 this . logger . extend ( 'historyTraceGetContent' ) ( `request returned ${ JSON . stringify ( res ) } ` )
10731073 if ( ! res ) {
@@ -1096,7 +1096,7 @@ export class portal {
10961096 async beaconTraceGetContent ( params : [ string ] ) {
10971097 const [ contentKey ] = params
10981098 this . logger . extend ( 'beaconTraceGetContent' ) ( `request received for ${ contentKey } ` )
1099- const lookup = new ContentLookup ( this . _history , hexToBytes ( contentKey ) , true )
1099+ const lookup = new ContentLookup ( this . _history , hexToBytes ( contentKey as PrefixedHexString ) , true )
11001100 const res = await lookup . startLookup ( )
11011101 this . logger . extend ( 'beaconTraceGetContent' ) ( `request returned ${ JSON . stringify ( res ) } ` )
11021102 if ( ! res ) {
@@ -1125,7 +1125,7 @@ export class portal {
11251125 async stateTraceGetContent ( params : [ string ] ) {
11261126 const [ contentKey ] = params
11271127 this . logger . extend ( 'stateTraceGetContent' ) ( `request received for ${ contentKey } ` )
1128- const lookup = new ContentLookup ( this . _history , hexToBytes ( contentKey ) , true )
1128+ const lookup = new ContentLookup ( this . _history , hexToBytes ( contentKey as PrefixedHexString ) , true )
11291129 const res = await lookup . startLookup ( )
11301130 this . logger . extend ( 'stateTraceGetContent' ) ( `request returned ${ JSON . stringify ( res ) } ` )
11311131 if ( ! res ) {
@@ -1157,8 +1157,8 @@ export class portal {
11571157 params : [ string , [ string , string ] [ ] ] ,
11581158 ) : Promise < string | ReturnType < typeof this . _history . sendOffer > > {
11591159 const [ enrHex , contentItems ] = params
1160- const contentKeys = contentItems . map ( ( item ) => hexToBytes ( item [ 0 ] ) )
1161- const contentValues = contentItems . map ( ( item ) => hexToBytes ( item [ 1 ] ) )
1160+ const contentKeys = contentItems . map ( ( item ) => hexToBytes ( item [ 0 ] as PrefixedHexString ) )
1161+ const contentValues = contentItems . map ( ( item ) => hexToBytes ( item [ 1 ] as PrefixedHexString ) )
11621162 const enr = ENR . decodeTxt ( enrHex )
11631163 const res = await this . _history . sendOffer ( enr , contentKeys , contentValues )
11641164 if ( res === undefined ) {
@@ -1170,8 +1170,8 @@ export class portal {
11701170 params : [ string , [ string , string ] [ ] ] ,
11711171 ) : Promise < string | ReturnType < typeof this . _state . sendOffer > > {
11721172 const [ enrHex , contentItems ] = params
1173- const contentKeys = contentItems . map ( ( item ) => hexToBytes ( item [ 0 ] ) )
1174- const contentValues = contentItems . map ( ( item ) => hexToBytes ( item [ 1 ] ) )
1173+ const contentKeys = contentItems . map ( ( item ) => hexToBytes ( item [ 0 ] as PrefixedHexString ) )
1174+ const contentValues = contentItems . map ( ( item ) => hexToBytes ( item [ 1 ] as PrefixedHexString ) )
11751175 const enr = ENR . decodeTxt ( enrHex )
11761176 const res = await this . _state . sendOffer ( enr , contentKeys , contentValues )
11771177 if ( res === undefined ) {
@@ -1183,8 +1183,8 @@ export class portal {
11831183 params : [ string , [ string , string ] [ ] ] ,
11841184 ) : Promise < string | ReturnType < typeof this . _beacon . sendOffer > > {
11851185 const [ enrHex , contentItems ] = params
1186- const contentKeys = contentItems . map ( ( item ) => hexToBytes ( item [ 0 ] ) )
1187- const contentValues = contentItems . map ( ( item ) => hexToBytes ( item [ 1 ] ) )
1186+ const contentKeys = contentItems . map ( ( item ) => hexToBytes ( item [ 0 ] as PrefixedHexString ) )
1187+ const contentValues = contentItems . map ( ( item ) => hexToBytes ( item [ 1 ] as PrefixedHexString ) )
11881188 const enr = ENR . decodeTxt ( enrHex )
11891189 const res = await this . _beacon . sendOffer ( enr , contentKeys , contentValues )
11901190 if ( res === undefined ) {
@@ -1197,13 +1197,13 @@ export class portal {
11971197 async historyGossip ( params : [ string , string ] ) {
11981198 const [ contentKey , content ] = params
11991199 this . logger ( `historyGossip request received for ${ contentKey } ` )
1200- const res = await this . _history . gossipContent ( hexToBytes ( contentKey ) , hexToBytes ( content ) )
1200+ const res = await this . _history . gossipContent ( hexToBytes ( contentKey as PrefixedHexString ) , hexToBytes ( content as PrefixedHexString ) )
12011201 return res
12021202 }
12031203 async stateGossip ( params : [ string , string ] ) {
12041204 const [ contentKey , content ] = params
12051205 this . logger ( `stateGossip request received for ${ contentKey } ` )
1206- const res = await this . _state . gossipContent ( hexToBytes ( contentKey ) , hexToBytes ( content ) )
1206+ const res = await this . _state . gossipContent ( hexToBytes ( contentKey as PrefixedHexString ) , hexToBytes ( content as PrefixedHexString ) )
12071207 return res
12081208 }
12091209
0 commit comments