@@ -179,15 +179,31 @@ class Transaction {
179179 } ) ;
180180 }
181181 weight ( ) {
182- const base = this . __byteLength ( false ) ;
183- const total = this . __byteLength ( true ) ;
182+ const base = this . byteLength ( false ) ;
183+ const total = this . byteLength ( true ) ;
184184 return base * 3 + total ;
185185 }
186186 virtualSize ( ) {
187187 return Math . ceil ( this . weight ( ) / 4 ) ;
188188 }
189- byteLength ( ) {
190- return this . __byteLength ( true ) ;
189+ byteLength ( _ALLOW_WITNESS = true ) {
190+ const hasWitnesses = _ALLOW_WITNESS && this . hasWitnesses ( ) ;
191+ return (
192+ ( hasWitnesses ? 10 : 8 ) +
193+ varuint . encodingLength ( this . ins . length ) +
194+ varuint . encodingLength ( this . outs . length ) +
195+ this . ins . reduce ( ( sum , input ) => {
196+ return sum + 40 + varSliceSize ( input . script ) ;
197+ } , 0 ) +
198+ this . outs . reduce ( ( sum , output ) => {
199+ return sum + 8 + varSliceSize ( output . script ) ;
200+ } , 0 ) +
201+ ( hasWitnesses
202+ ? this . ins . reduce ( ( sum , input ) => {
203+ return sum + vectorSize ( input . witness ) ;
204+ } , 0 )
205+ : 0 )
206+ ) ;
191207 }
192208 clone ( ) {
193209 const newTx = new Transaction ( ) ;
@@ -269,7 +285,7 @@ class Transaction {
269285 txTmp . ins [ inIndex ] . script = ourScript ;
270286 }
271287 // serialize and hash
272- const buffer = Buffer . allocUnsafe ( txTmp . __byteLength ( false ) + 4 ) ;
288+ const buffer = Buffer . allocUnsafe ( txTmp . byteLength ( false ) + 4 ) ;
273289 buffer . writeInt32LE ( hashType , buffer . length - 4 ) ;
274290 txTmp . __toBuffer ( buffer , 0 , false ) ;
275291 return bcrypto . hash256 ( buffer ) ;
@@ -386,27 +402,8 @@ class Transaction {
386402 typeforce ( types . tuple ( types . Number , [ types . Buffer ] ) , arguments ) ;
387403 this . ins [ index ] . witness = witness ;
388404 }
389- __byteLength ( _ALLOW_WITNESS ) {
390- const hasWitnesses = _ALLOW_WITNESS && this . hasWitnesses ( ) ;
391- return (
392- ( hasWitnesses ? 10 : 8 ) +
393- varuint . encodingLength ( this . ins . length ) +
394- varuint . encodingLength ( this . outs . length ) +
395- this . ins . reduce ( ( sum , input ) => {
396- return sum + 40 + varSliceSize ( input . script ) ;
397- } , 0 ) +
398- this . outs . reduce ( ( sum , output ) => {
399- return sum + 8 + varSliceSize ( output . script ) ;
400- } , 0 ) +
401- ( hasWitnesses
402- ? this . ins . reduce ( ( sum , input ) => {
403- return sum + vectorSize ( input . witness ) ;
404- } , 0 )
405- : 0 )
406- ) ;
407- }
408- __toBuffer ( buffer , initialOffset , _ALLOW_WITNESS ) {
409- if ( ! buffer ) buffer = Buffer . allocUnsafe ( this . __byteLength ( _ALLOW_WITNESS ) ) ;
405+ __toBuffer ( buffer , initialOffset , _ALLOW_WITNESS = false ) {
406+ if ( ! buffer ) buffer = Buffer . allocUnsafe ( this . byteLength ( _ALLOW_WITNESS ) ) ;
410407 let offset = initialOffset || 0 ;
411408 function writeSlice ( slice ) {
412409 offset += slice . copy ( buffer , offset ) ;
0 commit comments