@@ -14,6 +14,7 @@ import {
1414import { Operation } from "@/ledger-parser/operation/index.ts" ;
1515import { INVALID_TRANSACTION_INDEX } from "@/ledger-parser/error.ts" ;
1616import type { Ledger } from "@/ledger-parser/ledger/index.ts" ;
17+ import { isDefined } from "@/common/type-guards/is-defined.ts" ;
1718
1819/**
1920 * Transaction class for lazy operation parsing
@@ -41,7 +42,7 @@ export class Transaction {
4142 txResult : xdr . TransactionResult ,
4243 txMeta : xdr . TransactionMeta ,
4344 txHash : Uint8Array ,
44- index : number
45+ index : number ,
4546 ) {
4647 this . ledger = ledger ;
4748 this . txEnvelope = txEnvelope ;
@@ -54,13 +55,13 @@ export class Transaction {
5455 /**
5556 * Factory method to create a Transaction from transaction result metadata
5657 *
57- * Note: Only supports TransactionMeta v4 (Lightsail archive normalizes all to v4) .
58+ * Note: Only supports TransactionMeta v4.
5859 * Envelope is NOT available in v4 meta - use fromMetaWithEnvelope for LedgerCloseMeta v2.
5960 */
6061 static fromMeta (
6162 ledger : Ledger ,
6263 txResultMeta : xdr . TransactionResultMeta ,
63- index : number
64+ index : number ,
6465 ) : Transaction {
6566 if ( index < 0 ) {
6667 throw new INVALID_TRANSACTION_INDEX ( index , ledger . sequence , - 1 ) ;
@@ -82,15 +83,12 @@ export class Transaction {
8283
8384 /**
8485 * Factory method for V2 where envelope comes from txSet separately
85- *
86- * In V2, envelopes are stored in txSet.phases, not in TransactionMeta.
87- * The Ledger class extracts them and passes them here.
8886 */
8987 static fromMetaWithEnvelope (
9088 ledger : Ledger ,
9189 txResultMeta : xdr . TransactionResultMeta ,
9290 envelope : xdr . TransactionEnvelope ,
93- index : number
91+ index : number ,
9492 ) : Transaction {
9593 if ( index < 0 ) {
9694 throw new INVALID_TRANSACTION_INDEX ( index , ledger . sequence , - 1 ) ;
@@ -106,13 +104,9 @@ export class Transaction {
106104
107105 /**
108106 * Check if transaction envelope is available
109- *
110- * Envelope availability:
111- * - LedgerCloseMeta v2: ✅ Available (from txSet)
112- * - LedgerCloseMeta v0/v1: ❌ Not available (TransactionMeta v4 doesn't include envelope)
113107 */
114108 get hasEnvelope ( ) : boolean {
115- return this . txEnvelope !== undefined ;
109+ return isDefined ( this . txEnvelope ) ;
116110 }
117111
118112 /**
@@ -134,7 +128,7 @@ export class Transaction {
134128 @memoize ( )
135129 get hash ( ) : string {
136130 return Array . from ( this . txHash , ( b ) => b . toString ( 16 ) . padStart ( 2 , "0" ) ) . join (
137- ""
131+ "" ,
138132 ) ;
139133 }
140134
@@ -186,7 +180,7 @@ export class Transaction {
186180 get sourceAccount ( ) : string {
187181 if ( ! this . txEnvelope ) {
188182 throw new Error (
189- `Cannot get source account for transaction ${ this . hash } - envelope not available`
183+ `Cannot get source account for transaction ${ this . hash } - envelope not available` ,
190184 ) ;
191185 }
192186
@@ -235,7 +229,7 @@ export class Transaction {
235229 get sequence ( ) : bigint {
236230 if ( ! this . txEnvelope ) {
237231 throw new Error (
238- `Cannot get sequence for transaction ${ this . hash } - envelope not available`
232+ `Cannot get sequence for transaction ${ this . hash } - envelope not available` ,
239233 ) ;
240234 }
241235
@@ -267,7 +261,7 @@ export class Transaction {
267261 get operations ( ) : Operation [ ] {
268262 if ( ! this . txEnvelope ) {
269263 throw new Error (
270- `Cannot get operations for transaction ${ this . hash } - envelope not available`
264+ `Cannot get operations for transaction ${ this . hash } - envelope not available` ,
271265 ) ;
272266 }
273267
0 commit comments