@@ -810,9 +810,100 @@ const pow = {
810810 c29s : createCyclePowFactory ( "c29s" , "c29s_packed_edges" )
811811} ;
812812
813- function readUInt64BufferBE ( buf , offset = 0 ) {
814- const hi = BigInt ( buf . readUInt32BE ( offset ) ) ;
815- const lo = BigInt ( buf . readUInt32BE ( offset + 4 ) ) ;
813+ function errorMessage ( error ) {
814+ return error && error . message ? error . message : String ( error ) ;
815+ }
816+
817+ function safeInspect ( value ) {
818+ if ( typeof value === "function" ) return "[Function " + ( value . name || "anonymous" ) + "]" ;
819+ if ( typeof value === "bigint" ) return value . toString ( ) + "n" ;
820+ if ( typeof value === "undefined" ) return "undefined" ;
821+ try {
822+ return JSON . stringify ( value ) ;
823+ } catch ( _error ) {
824+ try {
825+ return String ( value ) ;
826+ } catch ( _error2 ) {
827+ return "[uninspectable]" ;
828+ }
829+ }
830+ }
831+
832+ function safeGet ( value , key ) {
833+ try {
834+ return value ? value [ key ] : undefined ;
835+ } catch ( error ) {
836+ return "[threw " + errorMessage ( error ) + "]" ;
837+ }
838+ }
839+
840+ function ctorName ( value ) {
841+ const ctor = safeGet ( value , "constructor" ) ;
842+ return ctor && ctor . name ? ctor . name : typeof value ;
843+ }
844+
845+ function protoCtorName ( value ) {
846+ try {
847+ const proto = Object . getPrototypeOf ( value ) ;
848+ return proto && proto . constructor && proto . constructor . name ? proto . constructor . name : safeInspect ( proto ) ;
849+ } catch ( error ) {
850+ return "[threw " + errorMessage ( error ) + "]" ;
851+ }
852+ }
853+
854+ function describeIndexedValues ( value , offset ) {
855+ const items = [ ] ;
856+ for ( let index = offset ; index < offset + 8 ; index ++ ) {
857+ const byte = safeGet ( value , index ) ;
858+ items . push ( index + ":" + typeof byte + ":" + safeInspect ( byte ) + ":integer=" + Number . isInteger ( byte ) ) ;
859+ }
860+ return items . join ( "," ) ;
861+ }
862+
863+ function describeBufferBacking ( value , offset ) {
864+ if ( ! Buffer . isBuffer ( value ) ) return "" ;
865+ try {
866+ const backing = Buffer . from ( value . buffer , value . byteOffset , value . length ) ;
867+ const view = new DataView ( backing . buffer , backing . byteOffset , backing . byteLength ) ;
868+ return " backingDataViewHi=" + view . getUint32 ( offset , false ) +
869+ " backingDataViewLo=" + view . getUint32 ( offset + 4 , false ) +
870+ " backingBytes=" + Array . from ( backing . subarray ( offset , offset + 8 ) ) . join ( "," ) +
871+ " backingHex=" + backing . toString ( "hex" ) ;
872+ } catch ( error ) {
873+ return " backing=[threw " + errorMessage ( error ) + "]" ;
874+ }
875+ }
876+
877+ function describeLegacyNonceRead ( value , offset ) {
878+ return "receiver={" +
879+ "isBuffer:" + Buffer . isBuffer ( value ) +
880+ ",instanceofBuffer:" + ( value instanceof Buffer ) +
881+ ",ctor:" + ctorName ( value ) +
882+ ",protoCtor:" + protoCtorName ( value ) +
883+ ",length:" + safeInspect ( safeGet ( value , "length" ) ) +
884+ ",byteOffset:" + safeInspect ( safeGet ( value , "byteOffset" ) ) +
885+ ",byteLength:" + safeInspect ( safeGet ( value , "byteLength" ) ) +
886+ ",readUInt32BEOwn:" + Object . prototype . hasOwnProperty . call ( value || { } , "readUInt32BE" ) +
887+ ",readUInt32BEIsBufferProto:" + ( safeGet ( value , "readUInt32BE" ) === Buffer . prototype . readUInt32BE ) +
888+ "} indexed=[" + describeIndexedValues ( value , offset ) + "]" +
889+ describeBufferBacking ( value , offset ) ;
890+ }
891+
892+ function readUInt64BufferBE ( buf , offset = 0 , label ) {
893+ const prefix = "XTM legacy nonce read" + ( label ? " " + label : "" ) ;
894+ let hiNumber ;
895+ let loNumber ;
896+ try {
897+ hiNumber = buf . readUInt32BE ( offset ) ;
898+ loNumber = buf . readUInt32BE ( offset + 4 ) ;
899+ } catch ( error ) {
900+ throw new RangeError ( prefix + " failed: " + errorMessage ( error ) + "; " + describeLegacyNonceRead ( buf , offset ) ) ;
901+ }
902+ if ( ! Number . isInteger ( hiNumber ) || ! Number . isInteger ( loNumber ) ) {
903+ throw new RangeError ( prefix + " returned non-integer uint32 hi=" + hiNumber + " lo=" + loNumber + "; " + describeLegacyNonceRead ( buf , offset ) ) ;
904+ }
905+ const hi = BigInt ( hiNumber ) ;
906+ const lo = BigInt ( loNumber ) ;
816907 return ( ( hi << 32n ) | lo ) . toString ( 10 ) ;
817908}
818909
@@ -1256,15 +1347,15 @@ function submitXtmRxBlock(ctx) {
12561347 const xtmBlock = cloneRpcTemplate ( ctx . blockTemplate . xtm_block ) ;
12571348 const powData = ctx . blockData . slice ( XTM_T_POW_DATA_OFFSET ) ;
12581349
1259- xtmBlock . header . nonce = readUInt64BufferBE ( ctx . blockData , XTM_T_NONCE_OFFSET ) ;
1350+ xtmBlock . header . nonce = readUInt64BufferBE ( ctx . blockData , XTM_T_NONCE_OFFSET , "XTM-T" ) ;
12601351 xtmBlock . header . pow . pow_data = powData . every ( ( byte ) => byte === 0 ) ? [ ] : [ ...powData ] ;
12611352 ctx . support . rpcPortDaemon ( ctx . blockTemplate . port , "SubmitBlock" , xtmBlock , ctx . replyFn , true ) ;
12621353}
12631354
12641355function submitXtmCBlock ( ctx ) {
12651356 const xtmBlock = cloneRpcTemplate ( ctx . blockTemplate . xtm_block ) ;
12661357
1267- xtmBlock . header . nonce = readUInt64BufferBE ( ctx . blockData , 0 ) ;
1358+ xtmBlock . header . nonce = readUInt64BufferBE ( ctx . blockData , 0 , "XTM-C" ) ;
12681359 xtmBlock . header . pow . pow_data = ctx . job . c29_packed_edges ;
12691360 ctx . support . rpcPortDaemon ( ctx . blockTemplate . port , "SubmitBlock" , xtmBlock , ctx . replyFn , true ) ;
12701361}
0 commit comments