diff --git a/Sources/KukaiCoreSwift/Factories/OperationFactory.swift b/Sources/KukaiCoreSwift/Factories/OperationFactory.swift index 005efe93..825a9b45 100644 --- a/Sources/KukaiCoreSwift/Factories/OperationFactory.swift +++ b/Sources/KukaiCoreSwift/Factories/OperationFactory.swift @@ -404,6 +404,18 @@ public class OperationFactory { return nil } + /** + Filter and verify only 1 transaction exists thats setting a baker. If so return this operation, otherwise return false + */ + public static func isDelegate(operations: [Operation]) -> OperationDelegation? { + let filteredOperations = filterReveal(operations: operations) + if filteredOperations.count == 1, let op = filteredOperations.first as? OperationDelegation { + return op + } + + return nil + } + /** Filter and verify only 1 transaction exists thats sending a token. If so return this operation, otherwise return false */ diff --git a/Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift b/Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift index 021ee11c..7ba5e619 100644 --- a/Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift +++ b/Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift @@ -549,6 +549,7 @@ class OperationFactoryTests: XCTestCase { let dexToken = DipDupToken(symbol: "BLAH", address: "KT1def", tokenId: 123, decimals: 3, standard: .fa2, thumbnailUri: nil) let dex = DipDupExchange(name: .quipuswap, address: "KT1abc", tezPool: "100000000000", tokenPool: "1000000000", sharesTotal: "100000", midPrice: "14", token: dexToken) let swap = OperationFactory.swapXtzToToken(withDex: dex, xtzAmount: .init(fromNormalisedAmount: 14), minTokenAmount: .init(fromNormalisedAmount: 2, decimalPlaces: 3), walletAddress: "tz1abc", timeout: 60) + let delegate = OperationFactory.delegateOperation(to: "KT1abc", from: MockConstants.defaultHdWallet.address) // is single transctions @@ -567,6 +568,11 @@ class OperationFactoryTests: XCTestCase { XCTAssert( OperationFactory.Extractor.isTezTransfer(operations: MockConstants.sendOperationWithReveal) != nil ) + // Is Delegate + XCTAssert( OperationFactory.Extractor.isDelegate(operations: delegate) != nil ) + XCTAssert( OperationFactory.Extractor.isDelegate(operations: opFA1) == nil ) + + // is token transfer XCTAssert( OperationFactory.Extractor.isFaTokenTransfer(operations: xtzOp) == nil )