Skip to content

Commit 5fbe606

Browse files
feat(core): add isBabbageOutput method to TransactionOutput class
1 parent 9c6375d commit 5fbe606

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/core/src/Serialization/TransactionBody/TransactionOutput.ts

+10
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,16 @@ export class TransactionOutput {
304304
this.#scriptRef = script;
305305
}
306306

307+
/**
308+
* Checks if the output is formatted as legacy array or babbage map.
309+
*
310+
* @returns true if the output is babbage format, false otherwise.
311+
*/
312+
isBabbageOutput(): boolean {
313+
const reader = new CborReader(this.toCbor());
314+
return reader.peekState() === CborReaderState.StartMap;
315+
}
316+
307317
/**
308318
* Gets the size of the serialized map.
309319
*

packages/core/test/Serialization/TransactionBody/TransactionOutput.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -396,5 +396,14 @@ describe('TransactionOutput', () => {
396396
expect(output.toCore()).toEqual(basicOutput);
397397
});
398398
});
399+
400+
describe('isBabbageOutput', () => {
401+
it('cant distinguish a babbage output from a legacy output', () => {
402+
const babbageOut = TransactionOutput.fromCbor(babbageAllFieldsCbor);
403+
const legacyOutput = TransactionOutput.fromCbor(legacyOutputNoDatumCbor);
404+
expect(babbageOut.isBabbageOutput()).toBe(true);
405+
expect(legacyOutput.isBabbageOutput()).toBe(false);
406+
});
407+
});
399408
});
400409
});

0 commit comments

Comments
 (0)