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 {
4040 DepositSol = 'DepositSol' ,
4141 WithdrawStake = 'WithdrawStake' ,
4242 Approve = 'Approve' ,
43+ CustomInstruction = 'CustomInstruction' ,
4344}
4445
4546// Internal instructions types
@@ -87,6 +88,7 @@ export const VALID_SYSTEM_INSTRUCTION_TYPES: ValidInstructionTypes[] = [
8788 ValidInstructionTypesEnum . Approve ,
8889 ValidInstructionTypesEnum . DepositSol ,
8990 ValidInstructionTypesEnum . WithdrawStake ,
91+ ValidInstructionTypesEnum . CustomInstruction ,
9092] ;
9193
9294/** 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 =
222222 | 'SetPriorityFee'
223223 | 'MintTo'
224224 | 'Burn'
225- | 'Approve' ;
225+ | 'Approve'
226+ | 'CustomInstruction' ;
226227
227228export type StakingAuthorizeParams = {
228229 stakingAddress : string ;
Original file line number Diff line number Diff line change @@ -59,6 +59,8 @@ export class TransactionBuilderFactory extends BaseTransactionBuilderFactory {
5959 return this . getStakingDelegateBuilder ( tx ) ;
6060 case TransactionType . CloseAssociatedTokenAccount :
6161 return this . getCloseAtaInitializationBuilder ( tx ) ;
62+ case TransactionType . CustomTx :
63+ return this . getCustomInstructionBuilder ( tx ) ;
6264 default :
6365 throw new InvalidTransactionError ( 'Invalid transaction' ) ;
6466 }
Original file line number Diff line number Diff line change @@ -344,7 +344,7 @@ export function getTransactionType(transaction: SolTransaction): TransactionType
344344 } else if ( matchTransactionTypeByInstructionsOrder ( instructions , ataCloseInstructionIndexes ) ) {
345345 return TransactionType . CloseAssociatedTokenAccount ;
346346 } else {
347- throw new NotSupported ( 'Invalid transaction, transaction not supported or invalid' ) ;
347+ return TransactionType . CustomTx ;
348348 }
349349}
350350
@@ -371,8 +371,8 @@ export function getInstructionType(instruction: TransactionInstruction): ValidIn
371371 instructionTypeMap . set ( TokenInstruction . Approve , 'Approve' ) ;
372372 instructionTypeMap . set ( TokenInstruction . TransferChecked , 'TokenTransfer' ) ;
373373 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' ;
376376 }
377377 return validInstruction ;
378378 case STAKE_POOL_PROGRAM_ID . toString ( ) :
@@ -397,9 +397,7 @@ export function getInstructionType(instruction: TransactionInstruction): ValidIn
397397 case COMPUTE_BUDGET :
398398 return 'SetPriorityFee' ;
399399 default :
400- throw new NotSupported (
401- 'Invalid transaction, instruction program id not supported: ' + instruction . programId . toString ( )
402- ) ;
400+ return 'CustomInstruction' ;
403401 }
404402}
405403
Original file line number Diff line number Diff line change @@ -235,16 +235,14 @@ describe('SOL util library', function () {
235235 } ) ;
236236 Utils . getInstructionType ( transferInstruction ) . should . equal ( 'Transfer' ) ;
237237 } ) ;
238- it ( 'should fail for invalid type ' , function ( ) {
238+ it ( 'should fallback to customInstruction for unsupported instructionType ' , function ( ) {
239239 const voteAddress = 'Vote111111111111111111111111111111111111111' ;
240240 const invalidInstruction = new TransactionInstruction ( {
241241 keys : [ ] ,
242242 programId : new PublicKey ( voteAddress ) ,
243243 data : Buffer . from ( 'random memo' ) ,
244244 } ) ;
245- should ( ( ) => Utils . getInstructionType ( invalidInstruction ) ) . throwError (
246- 'Invalid transaction, instruction program id not supported: ' + voteAddress
247- ) ;
245+ Utils . getInstructionType ( invalidInstruction ) . should . equal ( 'CustomInstruction' ) ;
248246 } ) ;
249247 } ) ;
250248
You can’t perform that action at this time.
0 commit comments