Skip to content

Commit f7e6704

Browse files
Merge pull request #1642 from input-output-hk/fix/fix-canonical-serialzation-of-empty-outputs
2 parents afddb8f + 958c236 commit f7e6704

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class TransactionBody {
107107
writer.writeEncodedValue(hexToBytes(this.#inputs.toCbor()));
108108
}
109109

110-
if (this.#outputs !== undefined && this.#outputs.length > 0) {
110+
if (this.#outputs !== undefined) {
111111
writer.writeInt(1n);
112112
writer.writeStartArray(this.#outputs.length);
113113

@@ -421,7 +421,7 @@ export class TransactionBody {
421421
treasuryValue: this.#currentTreasuryValue,
422422
update: this.#update ? this.#update.toCore() : undefined,
423423
validityInterval:
424-
this.#ttl || this.#validityStartInterval !== undefined
424+
this.#ttl !== undefined || this.#validityStartInterval !== undefined
425425
? {
426426
invalidBefore: this.#validityStartInterval,
427427
invalidHereafter: this.#ttl
@@ -968,7 +968,7 @@ export class TransactionBody {
968968
let mapSize = 0;
969969

970970
if (this.#inputs !== undefined && this.#inputs.size() > 0) ++mapSize;
971-
if (this.#outputs !== undefined && this.#outputs.length > 0) ++mapSize;
971+
if (this.#outputs !== undefined) ++mapSize;
972972
if (this.#fee !== undefined) ++mapSize;
973973
if (this.#ttl !== undefined) ++mapSize;
974974
if (this.#certs !== undefined && this.#certs.size() > 0) ++mapSize;

packages/core/test/Serialization/Transaction.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,13 @@ describe('Transaction', () => {
143143
'2d7f290c815e061fb7c27e91d2a898bd7b454a71c9b7a26660e2257ac31ebe32'
144144
);
145145
});
146+
147+
it('can roundtrip tx with ttl 0 and no outputs', () => {
148+
const cbor = TxCBOR(
149+
'84a700818258200000000000000000000000000000000000000000000000000000000000000000000180020003000758203f5c96d4e519a27e7e62d3e19c05aa352431fccc60fc2255e7d479a2bf1a01110e81581cf120862e979a660a8a068485a930e78de8a5804aff7612895b1f77250f01a0f5a10075544f444f3a2046494c4c20494e204d455353414745'
150+
);
151+
const tx = Transaction.fromCbor(cbor).toCore();
152+
153+
expect(Transaction.fromCore(tx).toCbor()).toBe(cbor);
154+
});
146155
});

0 commit comments

Comments
 (0)