@@ -1009,13 +1009,17 @@ export class Xlm extends BaseCoin {
10091009 return trustlineOperations ;
10101010 }
10111011
1012+ isChangeTrustOperation ( operation : stellar . Operation ) : operation is stellar . Operation . ChangeTrust {
1013+ return operation . type && operation . type === 'changeTrust' ;
1014+ }
1015+
10121016 getTrustlineOperationLineOrThrow ( operation : stellar . Operation ) : stellar . Asset | stellar . LiquidityPoolAsset {
1013- if ( operation . type === 'changeTrust' && operation . line ) return operation . line ;
1017+ if ( this . isChangeTrustOperation ( operation ) && operation . line ) return operation . line ;
10141018 throw new Error ( 'Invalid operation - expected changeTrust operation with line property' ) ;
10151019 }
10161020
10171021 getTrustlineOperationLimitOrThrow ( operation : stellar . Operation ) : string {
1018- if ( operation . type === 'changeTrust' && operation . limit ) return operation . limit ;
1022+ if ( this . isChangeTrustOperation ( operation ) && operation . limit ) return operation . limit ;
10191023 throw new Error ( 'Invalid operation - expected changeTrust operation with limit property' ) ;
10201024 }
10211025
@@ -1088,21 +1092,24 @@ export class Xlm extends BaseCoin {
10881092 return issuer ;
10891093 }
10901094
1091- // first to verify
1092- verifyTxType ( txParams : TransactionParams , operations : stellar . Operation [ ] ) : void {
1095+ verifyTxType ( operations : stellar . Operation [ ] ) : void {
10931096 operations . forEach ( ( operation ) => {
1094- if ( ! operation . type ) throw new Error ( 'Missing operation type on token enablement' ) ;
1095- if ( operation . type !== 'changeTrust' )
1096- throw new Error ( `Invalid operation on token enablement: expected changeTrust, got ${ operation . type } ` ) ;
1097+ if ( ! this . isChangeTrustOperation ( operation ) )
1098+ throw new Error (
1099+ ! operation . type
1100+ ? 'Missing operation type on token enablements'
1101+ : `Invalid operation on token enablement: expected changeTrust, got ${ operation . type } `
1102+ ) ;
10971103 } ) ;
10981104 }
10991105
11001106 verifyAssetType ( txParams : TransactionParams , operations : stellar . Operation [ ] ) : void {
11011107 operations . forEach ( ( operation ) => {
11021108 const line = this . getTrustlineOperationLineOrThrow ( operation ) ;
1103- const assetType = line . getAssetType ( ) ;
1104- if ( assetType === 'liquidity_pool_shares' )
1109+ if ( ! this . isOperationLineOfAssetType ( line ) ) {
1110+ const assetType = line . getAssetType ( ) ;
11051111 throw new Error ( `Invalid asset type on token enablement: got ${ assetType } ` ) ;
1112+ }
11061113 } ) ;
11071114 }
11081115
@@ -1185,8 +1192,7 @@ export class Xlm extends BaseCoin {
11851192
11861193 if ( txParams . type === 'enabletoken' && verification . verifyTokenEnablement ) {
11871194 const trustlineOperations = this . getTrustlineOperationsOrThrow ( tx . operations , txParams , 'recipients' ) ;
1188- this . verifyTxType ( txParams , trustlineOperations ) ;
1189-
1195+ this . verifyTxType ( trustlineOperations ) ;
11901196 this . verifyAssetType ( txParams , trustlineOperations ) ;
11911197 this . verifyTokenIssuer ( txParams , trustlineOperations ) ;
11921198 this . verifyTokenName ( txParams , trustlineOperations ) ;
0 commit comments