From 0dfd474c34a1b2679c80ecd316c89d5a8d0f8453 Mon Sep 17 00:00:00 2001 From: Simon McLoughlin Date: Wed, 3 Apr 2024 11:25:14 +0100 Subject: [PATCH] for now, don't allow Extractors to parse a multi send in a single transaction as a send. Because we only have the ability to extract + display a single. Need to fallback to batch or generic UI --- .../Factories/OperationFactory.swift | 12 +++- .../Factories/OperationFactoryTests.swift | 11 ++++ ...tory-extractor-multiple-send-in-param.json | 65 +++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 Tests/KukaiCoreSwiftTests/Stubs/operation-factory-extractor-multiple-send-in-param.json diff --git a/Sources/KukaiCoreSwift/Factories/OperationFactory.swift b/Sources/KukaiCoreSwift/Factories/OperationFactory.swift index 6ebe574a..66dc313e 100644 --- a/Sources/KukaiCoreSwift/Factories/OperationFactory.swift +++ b/Sources/KukaiCoreSwift/Factories/OperationFactory.swift @@ -570,6 +570,7 @@ public class OperationFactory { */ public static func tokenIdAndAmountFromTransferMichelson(michelson: Any) -> (rpcAmount: String, tokenId: Decimal?, destination: String)? { if let michelsonDict = michelson as? [String: Any] { + // FA1.2 let rpcAmountString = michelsonDict.michelsonArgsArray()?.michelsonPair(atIndex: 1)?.michelsonArgsArray()?.michelsonInt(atIndex: 1) let rpcDestinationString = michelsonDict.michelsonArgsArray()?.michelsonPair(atIndex: 1)?.michelsonArgsArray()?.michelsonString(atIndex: 0) ?? "" @@ -581,9 +582,18 @@ public class OperationFactory { } } else if let michelsonArray = michelson as? [[String: Any]] { + // FA2 + let outerContainerArray = michelsonArray[0].michelsonArgsUnknownArray()?.michelsonArray(atIndex: 1) + + // For now, we only support sending 1 item per transaction. The FA2 standard allows for multiple items to be passed in via an array + // If thats the case we simply return nil, to mark it as an unknwon type until we can get a better handle on extractions + guard outerContainerArray?.count == 1 else { + return nil + } + + let argsArray1 = outerContainerArray?.michelsonPair(atIndex: 0)?.michelsonArgsArray() - let argsArray1 = michelsonArray[0].michelsonArgsUnknownArray()?.michelsonArray(atIndex: 1)?.michelsonPair(atIndex: 0)?.michelsonArgsArray() let rpcDestination = argsArray1?.michelsonString(atIndex: 0) let argsArray2 = argsArray1?.michelsonPair(atIndex: 1)?.michelsonArgsArray() diff --git a/Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift b/Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift index 0789b694..cd9340c9 100644 --- a/Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift +++ b/Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift @@ -743,4 +743,15 @@ class OperationFactoryTests: XCTestCase { XCTAssert(details1?.tokenId == nil, details1?.tokenId?.description ?? "-") XCTAssert(details1?.destination == "KT18iSHoRW1iogamADWwQSDoZa3QkN4izkqj", details1?.destination ?? "-") } + + func testExtractorsMultiSendInListParam() { + let decoder = JSONDecoder() + + let jsonData = MockConstants.jsonStub(fromFilename: "operation-factory-extractor-multiple-send-in-param") + let jsonOperations = (try? decoder.decode([OperationTransaction].self, from: jsonData)) ?? [] + XCTAssert(jsonOperations.count > 0) + + let details1 = OperationFactory.Extractor.isFaTokenTransfer(operations: jsonOperations) // operation is multiple sends in a single michelson param, for now, thats not supported as a "send" + XCTAssert(details1 == nil) + } } diff --git a/Tests/KukaiCoreSwiftTests/Stubs/operation-factory-extractor-multiple-send-in-param.json b/Tests/KukaiCoreSwiftTests/Stubs/operation-factory-extractor-multiple-send-in-param.json new file mode 100644 index 00000000..74bbed73 --- /dev/null +++ b/Tests/KukaiCoreSwiftTests/Stubs/operation-factory-extractor-multiple-send-in-param.json @@ -0,0 +1,65 @@ +[ + { + "amount": "0", + "counter": "24122766", + "destination": "KT1U6EHmNxJTkvaWJ4ThczG4FSDaHC21ssvi", + "fee": "0", + "gas_limit": "1040000", + "kind": "transaction", + "parameters": { + "entrypoint": "transfer", + "value": [ + { + "args": [ + { + "string": "tz1Nzj8BKu3F6KhyaJYZXEfXkyN51HBNJixi" + }, + [ + { + "args": [ + { + "string": "tz1burnburnburnburnburnburnburjAYjjX" + }, + { + "args": [ + { + "int": "1445926" + }, + { + "int": "1" + } + ], + "prim": "Pair" + } + ], + "prim": "Pair" + }, + { + "args": [ + { + "string": "tz1burnburnburnburnburnburnburjAYjjX" + }, + { + "args": [ + { + "int": "1545568" + }, + { + "int": "1" + } + ], + "prim": "Pair" + } + ], + "prim": "Pair" + } + ] + ], + "prim": "Pair" + } + ] + }, + "source": "tz1Nzj8BKu3F6KhyaJYZXEfXkyN51HBNJixi", + "storage_limit": "60000" + } +] \ No newline at end of file