11import { Binary , MerkleTree , Optional , Uint8ArrayReader } from 'cafe-utility'
2+ import _debug from 'debug'
23import { Bee , BeeRequestOptions , DownloadOptions , NULL_ADDRESS , UploadOptions , UploadResult } from '..'
34import { FeedPayloadResult } from '../modules/feed'
45import { Bytes } from '../utils/bytes'
56import { BatchId , Reference } from '../utils/typed-bytes'
67
8+ const debug = _debug ( 'bee-js:manifest' )
9+
710const ENCODER = new TextEncoder ( )
811const DECODER = new TextDecoder ( )
912
@@ -80,6 +83,12 @@ export class Fork {
8083 }
8184 data . push ( this . node . selfAddress )
8285
86+ debug ( 'marshalling fork' , {
87+ prefixLength : this . prefix . length ,
88+ prefix : DECODER . decode ( this . prefix ) ,
89+ address : Binary . uint8ArrayToHex ( this . node . selfAddress ) ,
90+ } )
91+
8392 if ( this . node . metadata ) {
8493 const metadataBytes = Binary . padEndToMultiple (
8594 new Uint8Array ( [ 0x00 , 0x00 , ...ENCODER . encode ( JSON . stringify ( this . node . metadata ) ) ] ) ,
@@ -100,6 +109,12 @@ export class Fork {
100109 const prefix = reader . read ( prefixLength )
101110 reader . read ( 30 - prefixLength )
102111 const selfAddress = reader . read ( addressLength )
112+ debug ( 'unmarshalling fork' , {
113+ prefixLength,
114+ prefix : DECODER . decode ( prefix ) ,
115+ addressLength,
116+ address : Binary . uint8ArrayToHex ( selfAddress ) ,
117+ } )
103118 let metadata : Record < string , string > | undefined = undefined
104119
105120 if ( isType ( type , TYPE_WITH_METADATA ) ) {
@@ -313,6 +328,7 @@ export class MantarayNode {
313328 ) {
314329 this . selfAddress = null
315330 path = path instanceof Uint8Array ? path : ENCODER . encode ( path )
331+ debug ( 'adding fork' , { path : DECODER . decode ( path ) , reference : new Reference ( reference ) . represent ( ) } )
316332 // TODO: this should not be ignored
317333 // eslint-disable-next-line @typescript-eslint/no-this-alias
318334 let tip : MantarayNode = this
0 commit comments