@@ -115,16 +115,49 @@ export class RuneUtils extends CosmosUtils {
115115 /** @inheritdoc */
116116 validateAmount ( amount : Coin ) : void {
117117 const amountBig = BigNumber ( amount . amount ) ;
118- if ( amountBig . isLessThanOrEqualTo ( 0 ) ) {
118+ if ( amountBig . isNaN ( ) || amountBig . isLessThanOrEqualTo ( 0 ) ) {
119119 throw new InvalidTransactionError ( 'transactionBuilder: validateAmount: Invalid amount: ' + amount . amount ) ;
120120 }
121+ this . validateDenomination ( amount . denom ) ;
122+ }
123+
124+ /**
125+ * Validates the gas limit and gas amount for a transaction.
126+ * @param {FeeData } gasBudget - The gas budget to validate.
127+ * @throws {InvalidTransactionError } Throws an error if the gas budget is invalid.
128+ */
129+ validateGasBudget ( gasBudget : FeeData ) : void {
130+ if ( gasBudget . gasLimit <= 0 ) {
131+ throw new InvalidTransactionError ( 'Invalid gas limit ' + gasBudget . gasLimit ) ;
132+ }
133+ this . validateGasAmountData ( gasBudget . amount ) ;
134+ }
135+
136+ /**
137+ * Validates an array of coin amounts.
138+ * @param {Coin[] } amountArray - The array of coin amounts to validate.
139+ */
140+ validateGasAmountData ( amountArray : Coin [ ] ) : void {
141+ amountArray . forEach ( ( coinAmount ) => {
142+ this . validateGasAmount ( coinAmount ) ;
143+ } ) ;
144+ }
145+
146+ validateGasAmount ( amount : Coin ) : void {
147+ const amountBig = BigNumber ( amount . amount ) ;
148+ if ( amountBig . isNaN ( ) || amountBig . isLessThan ( 0 ) ) {
149+ throw new InvalidTransactionError ( 'transactionBuilder: validateAmount: Invalid amount: ' + amount . amount ) ;
150+ }
151+ this . validateDenomination ( amount . denom ) ;
152+ }
153+
154+ validateDenomination ( amountDenom : string ) : void {
121155 if (
122156 ( this . networkType === NetworkType . TESTNET &&
123- ! constants . testnetValidDenoms . find ( ( denom ) => denom === amount . denom ) ) ||
124- ( this . networkType === NetworkType . MAINNET &&
125- ! constants . mainnetValidDenoms . find ( ( denom ) => denom === amount . denom ) )
157+ ! constants . testnetValidDenoms . find ( ( denom ) => denom === amountDenom ) ) ||
158+ ( this . networkType === NetworkType . MAINNET && ! constants . mainnetValidDenoms . find ( ( denom ) => denom === amountDenom ) )
126159 ) {
127- throw new InvalidTransactionError ( 'transactionBuilder: validateAmount: Invalid denom: ' + amount . denom ) ;
160+ throw new InvalidTransactionError ( 'transactionBuilder: validateAmount: Invalid denom: ' + amountDenom ) ;
128161 }
129162 }
130163
0 commit comments