@@ -235,7 +235,7 @@ export class CellOutput extends mol.Entity.Base<CellOutputLike, CellOutput>() {
235235
236236 /**
237237 * Creates a CellOutput instance from a CellOutputLike object.
238- * This method supports automatic capacity calculation when capacity is 0 or omitted.
238+ * This method supports automatic capacity calculation when outputData is provided and capacity is 0 or omitted.
239239 *
240240 * @param cellOutput - A CellOutputLike object or an instance of CellOutput.
241241 * @param outputData - Optional output data used for automatic capacity calculation.
@@ -262,19 +262,20 @@ export class CellOutput extends mol.Entity.Base<CellOutputLike, CellOutput>() {
262262 cellOutput : CellOutputLike ,
263263 outputData ?: HexLike | null ,
264264 ) : CellOutput {
265- if ( cellOutput instanceof CellOutput ) {
266- return cellOutput ;
267- }
268-
269- const output = new CellOutput (
270- numFrom ( cellOutput . capacity ?? 0 ) ,
271- Script . from ( cellOutput . lock ) ,
272- apply ( Script . from , cellOutput . type ) ,
273- ) ;
265+ const output = ( ( ) => {
266+ if ( cellOutput instanceof CellOutput ) {
267+ return cellOutput ;
268+ }
269+ return new CellOutput (
270+ numFrom ( cellOutput . capacity ?? 0 ) ,
271+ Script . from ( cellOutput . lock ) ,
272+ apply ( Script . from , cellOutput . type ) ,
273+ ) ;
274+ } ) ( ) ;
274275
275- if ( output . capacity === Zero ) {
276+ if ( output . capacity === Zero && outputData != null ) {
276277 output . capacity = fixedPointFrom (
277- output . occupiedSize + bytesFrom ( outputData ?? "0x" ) . length ,
278+ output . occupiedSize + bytesFrom ( outputData ) . length ,
278279 ) ;
279280 }
280281
@@ -365,9 +366,11 @@ export class CellAny {
365366 return cell ;
366367 }
367368
369+ const outputData = hexFrom ( cell . outputData ?? "0x" ) ;
370+
368371 return new CellAny (
369- CellOutput . from ( cell . cellOutput , cell . outputData ) ,
370- hexFrom ( cell . outputData ?? "0x" ) ,
372+ CellOutput . from ( cell . cellOutput , outputData ) ,
373+ outputData ,
371374 apply ( OutPoint . from , cell . outPoint ?? cell . previousOutput ) ,
372375 ) ;
373376 }
0 commit comments