File tree Expand file tree Collapse file tree 5 files changed +12
-11
lines changed Expand file tree Collapse file tree 5 files changed +12
-11
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ export enum ValidInstructionTypesEnum {
40
40
DepositSol = 'DepositSol' ,
41
41
WithdrawStake = 'WithdrawStake' ,
42
42
Approve = 'Approve' ,
43
+ CustomInstruction = 'CustomInstruction' ,
43
44
}
44
45
45
46
// Internal instructions types
@@ -87,6 +88,7 @@ export const VALID_SYSTEM_INSTRUCTION_TYPES: ValidInstructionTypes[] = [
87
88
ValidInstructionTypesEnum . Approve ,
88
89
ValidInstructionTypesEnum . DepositSol ,
89
90
ValidInstructionTypesEnum . WithdrawStake ,
91
+ ValidInstructionTypesEnum . CustomInstruction ,
90
92
] ;
91
93
92
94
/** Const to check the order of the Wallet Init instructions when decode */
Original file line number Diff line number Diff line change @@ -222,7 +222,8 @@ export type ValidInstructionTypes =
222
222
| 'SetPriorityFee'
223
223
| 'MintTo'
224
224
| 'Burn'
225
- | 'Approve' ;
225
+ | 'Approve'
226
+ | 'CustomInstruction' ;
226
227
227
228
export type StakingAuthorizeParams = {
228
229
stakingAddress : string ;
Original file line number Diff line number Diff line change @@ -59,6 +59,8 @@ export class TransactionBuilderFactory extends BaseTransactionBuilderFactory {
59
59
return this . getStakingDelegateBuilder ( tx ) ;
60
60
case TransactionType . CloseAssociatedTokenAccount :
61
61
return this . getCloseAtaInitializationBuilder ( tx ) ;
62
+ case TransactionType . CustomTx :
63
+ return this . getCustomInstructionBuilder ( tx ) ;
62
64
default :
63
65
throw new InvalidTransactionError ( 'Invalid transaction' ) ;
64
66
}
Original file line number Diff line number Diff line change @@ -344,7 +344,7 @@ export function getTransactionType(transaction: SolTransaction): TransactionType
344
344
} else if ( matchTransactionTypeByInstructionsOrder ( instructions , ataCloseInstructionIndexes ) ) {
345
345
return TransactionType . CloseAssociatedTokenAccount ;
346
346
} else {
347
- throw new NotSupported ( 'Invalid transaction, transaction not supported or invalid' ) ;
347
+ return TransactionType . CustomTx ;
348
348
}
349
349
}
350
350
@@ -371,8 +371,8 @@ export function getInstructionType(instruction: TransactionInstruction): ValidIn
371
371
instructionTypeMap . set ( TokenInstruction . Approve , 'Approve' ) ;
372
372
instructionTypeMap . set ( TokenInstruction . TransferChecked , 'TokenTransfer' ) ;
373
373
const validInstruction = instructionTypeMap . get ( decodedInstruction . data . instruction ) ;
374
- if ( validInstruction === undefined ) {
375
- throw new Error ( `Unsupported token instruction type ${ decodedInstruction . data . instruction } ` ) ;
374
+ if ( ! validInstruction ) {
375
+ return 'CustomInstruction' ;
376
376
}
377
377
return validInstruction ;
378
378
case STAKE_POOL_PROGRAM_ID . toString ( ) :
@@ -397,9 +397,7 @@ export function getInstructionType(instruction: TransactionInstruction): ValidIn
397
397
case COMPUTE_BUDGET :
398
398
return 'SetPriorityFee' ;
399
399
default :
400
- throw new NotSupported (
401
- 'Invalid transaction, instruction program id not supported: ' + instruction . programId . toString ( )
402
- ) ;
400
+ return 'CustomInstruction' ;
403
401
}
404
402
}
405
403
Original file line number Diff line number Diff line change @@ -235,16 +235,14 @@ describe('SOL util library', function () {
235
235
} ) ;
236
236
Utils . getInstructionType ( transferInstruction ) . should . equal ( 'Transfer' ) ;
237
237
} ) ;
238
- it ( 'should fail for invalid type ' , function ( ) {
238
+ it ( 'should fallback to customInstruction for unsupported instructionType ' , function ( ) {
239
239
const voteAddress = 'Vote111111111111111111111111111111111111111' ;
240
240
const invalidInstruction = new TransactionInstruction ( {
241
241
keys : [ ] ,
242
242
programId : new PublicKey ( voteAddress ) ,
243
243
data : Buffer . from ( 'random memo' ) ,
244
244
} ) ;
245
- should ( ( ) => Utils . getInstructionType ( invalidInstruction ) ) . throwError (
246
- 'Invalid transaction, instruction program id not supported: ' + voteAddress
247
- ) ;
245
+ Utils . getInstructionType ( invalidInstruction ) . should . equal ( 'CustomInstruction' ) ;
248
246
} ) ;
249
247
} ) ;
250
248
You can’t perform that action at this time.
0 commit comments