Skip to content

Commit

Permalink
- add extractor for checking if delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Feb 14, 2024
1 parent 50642c4 commit 7b8b378
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/KukaiCoreSwift/Factories/OperationFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 )

Expand Down

0 comments on commit 7b8b378

Please sign in to comment.