@@ -111,6 +111,10 @@ export class Flrp extends BaseCoin {
111111 this . validateImportTx ( explainedTx . inputs , params . txParams ) ;
112112 }
113113 break ;
114+ case TransactionType . AddPermissionlessDelegator :
115+ // Validate delegation transaction against both txParams and explainedTx
116+ this . validateDelegationTx ( params . txParams , explainedTx ) ;
117+ break ;
114118 default :
115119 throw new Error ( 'Tx type is not supported yet' ) ;
116120 }
@@ -166,6 +170,52 @@ export class Flrp extends BaseCoin {
166170 }
167171 }
168172
173+ /**
174+ * Validate AddPermissionlessDelegator transaction parameters.
175+ * Validates both expected txParams and the parsed explainedTx for consistency.
176+ *
177+ * @param {FlrpTransactionParams } txParams - Expected transaction parameters
178+ * @param {FlrpLib.TransactionExplanation } explainedTx - Parsed transaction explanation
179+ */
180+ validateDelegationTx ( txParams : FlrpTransactionParams , explainedTx : FlrpLib . TransactionExplanation ) : void {
181+ if ( ! txParams . stakingOptions ) {
182+ throw new Error ( 'Delegation transaction requires stakingOptions' ) ;
183+ }
184+
185+ const { nodeID, amount, durationSeconds, rewardAddress } = txParams . stakingOptions ;
186+
187+ if ( ! nodeID ) {
188+ throw new Error ( 'Delegation transaction requires nodeID' ) ;
189+ }
190+
191+ if ( ! amount ) {
192+ throw new Error ( 'Delegation transaction requires amount' ) ;
193+ }
194+
195+ if ( ! durationSeconds ) {
196+ throw new Error ( 'Delegation transaction requires durationSeconds' ) ;
197+ }
198+
199+ if ( ! rewardAddress ) {
200+ throw new Error ( 'Delegation transaction requires rewardAddress' ) ;
201+ }
202+
203+ // Validate nodeID format using utility method
204+ if ( ! utils . isValidNodeID ( nodeID ) ) {
205+ throw new Error ( `Invalid nodeID format: ${ nodeID } ` ) ;
206+ }
207+
208+ // Validate that the parsed transaction's output amount matches the expected staking amount
209+ // The outputAmount in explainedTx represents the total stake amount in the transaction
210+ if ( explainedTx . outputAmount ) {
211+ const expectedAmount = new BigNumber ( amount ) ;
212+ const actualAmount = new BigNumber ( explainedTx . outputAmount ) ;
213+ if ( ! expectedAmount . isEqualTo ( actualAmount ) ) {
214+ throw new Error ( `Delegation amount mismatch: expected ${ amount } , transaction has ${ explainedTx . outputAmount } ` ) ;
215+ }
216+ }
217+ }
218+
169219 private getBuilder ( ) : FlrpLib . TransactionBuilderFactory {
170220 return new FlrpLib . TransactionBuilderFactory ( coins . get ( this . getChain ( ) ) ) ;
171221 }
0 commit comments