Skip to content

Commit

Permalink
for now, don't allow Extractors to parse a multi send in a single tra…
Browse files Browse the repository at this point in the history
…nsaction as a send. Because we only have the ability to extract + display a single. Need to fallback to batch or generic UI
  • Loading branch information
simonmcl committed Apr 3, 2024
1 parent c47576c commit 0dfd474
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/KukaiCoreSwift/Factories/OperationFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?? ""
Expand All @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions Tests/KukaiCoreSwiftTests/Factories/OperationFactoryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
]

0 comments on commit 0dfd474

Please sign in to comment.