@@ -43,12 +43,14 @@ import {
4343} from './types.js'
4444import type { TNibbles } from './types.js'
4545import {
46- AccountTrieNodeContentKey ,
47- ContractCodeContentKey ,
48- StateNetworkContentId ,
49- StorageTrieNodeContentKey ,
46+ decodeAccountTrieNodeContentKey ,
47+ decodeContractCodeContentKey ,
48+ decodeStorageTrieNodeContentKey ,
49+ encodeAccountTrieNodeContentKey ,
50+ encodeStorageTrieNodeContentKey ,
5051 extractAccountProof ,
5152 nextOffer ,
53+ stateNetworkContentIdFromBytes ,
5254} from './util.js'
5355
5456export class StateNetwork extends BaseNetwork {
@@ -67,7 +69,7 @@ export class StateNetwork extends BaseNetwork {
6769 }
6870
6971 public contentKeyToId = ( contentKey : Uint8Array ) : string => {
70- return bytesToUnprefixedHex ( StateNetworkContentId . fromBytes ( contentKey ) )
72+ return bytesToUnprefixedHex ( stateNetworkContentIdFromBytes ( contentKey ) )
7173 }
7274
7375 /**
@@ -181,10 +183,10 @@ export class StateNetwork extends BaseNetwork {
181183 await this . gossipContent ( contentKey , content )
182184 } else {
183185 if ( contentType === StateNetworkContentType . AccountTrieNode ) {
184- const { nodeHash } = AccountTrieNodeContentKey . decode ( contentKey )
186+ const { nodeHash } = decodeAccountTrieNodeContentKey ( contentKey )
185187 this . manager . trie . db . local . set ( bytesToUnprefixedHex ( nodeHash ) , bytesToHex ( contentKey ) )
186188 } else if ( contentType === StateNetworkContentType . ContractTrieNode ) {
187- const { nodeHash } = StorageTrieNodeContentKey . decode ( contentKey )
189+ const { nodeHash } = decodeStorageTrieNodeContentKey ( contentKey )
188190 this . manager . trie . db . local . set ( bytesToUnprefixedHex ( nodeHash ) , bytesToHex ( contentKey ) )
189191 }
190192 await this . db . put ( contentKey , content )
@@ -202,7 +204,7 @@ export class StateNetwork extends BaseNetwork {
202204 ) : Promise < {
203205 stored : number
204206 } > {
205- const { path } = AccountTrieNodeContentKey . decode ( contentKey )
207+ const { path } = decodeAccountTrieNodeContentKey ( contentKey )
206208 const { proof, blockHash } = AccountTrieNodeOffer . deserialize ( content )
207209 const interested = await this . storeInterestedAccountTrieNodes ( path , proof )
208210 void this . forwardAccountTrieOffer ( path , proof , blockHash )
@@ -235,11 +237,11 @@ export class StateNetwork extends BaseNetwork {
235237 `${ i } Path: [${ newpaths } ] - ${ curNode . constructor . name } : ${ bytesToHex ( nodeHash ) . slice ( 0 , 8 ) } ...` ,
236238 )
237239 i ++
238- const contentKey = AccountTrieNodeContentKey . encode ( {
240+ const contentKey = encodeAccountTrieNodeContentKey ( {
239241 nodeHash,
240242 path : packNibbles ( newpaths ) ,
241243 } )
242- const contentId = StateNetworkContentId . fromBytes ( contentKey )
244+ const contentId = stateNetworkContentIdFromBytes ( contentKey )
243245 const in_radius = distance ( bytesToUnprefixedHex ( contentId ) , this . enr . nodeId ) < this . nodeRadius
244246 if ( in_radius ) {
245247 const dbContent = AccountTrieNodeRetrieval . serialize ( {
@@ -264,7 +266,7 @@ export class StateNetwork extends BaseNetwork {
264266 const { nodes, newpaths } = nextOffer ( path , proof )
265267 const content = AccountTrieNodeOffer . serialize ( { blockHash, proof : [ ...nodes ] } )
266268 const nodeHash = new Trie ( { useKeyHashing : true } ) [ 'hash' ] ( nodes [ nodes . length - 1 ] )
267- const contentKey = AccountTrieNodeContentKey . encode ( {
269+ const contentKey = encodeAccountTrieNodeContentKey ( {
268270 nodeHash,
269271 path : packNibbles ( newpaths ) ,
270272 } )
@@ -298,7 +300,7 @@ export class StateNetwork extends BaseNetwork {
298300 ) : Promise < {
299301 stored : number
300302 } > {
301- const { addressHash, path } = StorageTrieNodeContentKey . decode ( contentKey )
303+ const { addressHash, path } = decodeStorageTrieNodeContentKey ( contentKey )
302304 const { blockHash, accountProof, storageProof } = StorageTrieNodeOffer . deserialize ( content )
303305 const interested = await this . storeInterestedStorageTrieNodes ( path , storageProof , addressHash )
304306 await this . receiveAccountTrieNodeOffer (
@@ -339,12 +341,12 @@ export class StateNetwork extends BaseNetwork {
339341 `${ i } Path: [${ newpaths } ] - ${ curNode . constructor . name } : ${ bytesToHex ( nodeHash ) . slice ( 0 , 8 ) } ...` ,
340342 )
341343 i ++
342- const contentKey = StorageTrieNodeContentKey . encode ( {
344+ const contentKey = encodeStorageTrieNodeContentKey ( {
343345 nodeHash,
344346 path : packNibbles ( newpaths ) ,
345347 addressHash,
346348 } )
347- const contentId = StateNetworkContentId . fromBytes ( contentKey )
349+ const contentId = stateNetworkContentIdFromBytes ( contentKey )
348350 const in_radius = distance ( bytesToUnprefixedHex ( contentId ) , this . enr . nodeId ) < this . nodeRadius
349351 if ( in_radius ) {
350352 const dbContent = StorageTrieNodeRetrieval . serialize ( {
@@ -378,7 +380,7 @@ export class StateNetwork extends BaseNetwork {
378380 storageProof : [ ...nodes ] ,
379381 } )
380382 const nodeHash = new Trie ( { useKeyHashing : true } ) [ 'hash' ] ( nodes [ nodes . length - 1 ] )
381- const contentKey = StorageTrieNodeContentKey . encode ( {
383+ const contentKey = encodeStorageTrieNodeContentKey ( {
382384 nodeHash,
383385 path : packNibbles ( newpaths ) ,
384386 addressHash,
@@ -387,7 +389,7 @@ export class StateNetwork extends BaseNetwork {
387389 return { content, contentKey }
388390 }
389391 async receiveContractCodeOffer ( contentKey : Uint8Array , content : Uint8Array ) {
390- const { addressHash, codeHash } = ContractCodeContentKey . decode ( contentKey )
392+ const { addressHash, codeHash } = decodeContractCodeContentKey ( contentKey )
391393 const { accountProof, blockHash, code } = ContractCodeOffer . deserialize ( content )
392394 const codeContent = ContractRetrieval . serialize ( { code } )
393395 this . manager . trie . db . local . set ( bytesToUnprefixedHex ( codeHash ) , bytesToHex ( contentKey ) )
0 commit comments