WIN-8498: Refactor FLRP Transaction Builders for Better Code Organization #7839
+1,409
−2,218
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WIN-8498: Refactor FLRP Transaction Builders for Better Code Organization
This PR refactors the FLRP transaction builders to consolidate common properties and methods into base classes, reducing code duplication and improving maintainability.
🔄 Changes Overview
1. Consolidated Common Properties to Base Classes
context()TransactionBuildertransaction._contextfeeState()ExportInPTxBuilder,ImportInPTxBuilderAtomicTransactionBuildertransaction._feeStateamount()ExportInPTxBuilder,ExportInCTxBuilderAtomicTransactionBuildertransaction._amountutxos()ExportInPTxBuilder,ImportInPTxBuilderTransactionBuilder2. Added Validation for UTXO Balance
ExportInPTxBuilder: Validates thattotalUtxoAmount >= amountbefore buildingImportInCTxBuilder: Validates thattotalUtxoAmount > feeto ensure import can pay feesImportInPTxBuilder: Validates thattotalUtxoAmount > 03. Standardized Error Types
All validation errors now consistently use
BuildTransactionErrorinstead of genericError.📁 Files Modified
transaction.ts_feeState: FlrpFeeStateand_amount: bigintpublic propertiesatomicTransactionBuilder.tsfeeState()andamount()setter methodsExportInPTxBuilder.ts_amount,_feeState,amount(),feeState(),utxos()- now uses base classExportInCTxBuilder.ts_amount,_context,amount(),context()- now uses base class; fixedutxos()method signatureImportInPTxBuilder.ts_feeState,_context,feeState(),context(),utxos()- now uses base classImportInCTxBuilder.ts_context,context()- now uses base class; added UTXO balance validation✅ Benefits
context(),feeState(), andamount()are now in base classesBuildTransactionErrorfor validation failures🧪 Testing
All existing unit tests pass. The refactoring maintains backward compatibility - the public API remains unchanged.