diff --git a/android/src/main/kotlin/africa/ejara/trustdart/coins/NEAR.kt b/android/src/main/kotlin/africa/ejara/trustdart/coins/NEAR.kt index ef149d3..70153d0 100644 --- a/android/src/main/kotlin/africa/ejara/trustdart/coins/NEAR.kt +++ b/android/src/main/kotlin/africa/ejara/trustdart/coins/NEAR.kt @@ -38,9 +38,9 @@ class NEAR : Coin("NEAR", CoinType.NEAR) { signerId = txData["signerID"] as String nonce = txData["nonce"]!!.toLong() receiverId = txData["receiverID"] as String - addActionsBuilder().apply { - transfer = transferAction - } + addActionsBuilder().apply { + transfer = transferAction + } blockHash = ByteString.copyFrom(Base58.decodeNoCheck(txData["blockHash"] as String)) privateKey = ByteString.copyFrom(secretKey.data()) }.build() diff --git a/android/src/main/kotlin/africa/ejara/trustdart/coins/XTZ.kt b/android/src/main/kotlin/africa/ejara/trustdart/coins/XTZ.kt index acd91aa..07de6bd 100644 --- a/android/src/main/kotlin/africa/ejara/trustdart/coins/XTZ.kt +++ b/android/src/main/kotlin/africa/ejara/trustdart/coins/XTZ.kt @@ -5,15 +5,16 @@ import africa.ejara.trustdart.utils.toHex import africa.ejara.trustdart.utils.toHexBytes import africa.ejara.trustdart.utils.toLong import android.util.Log -import wallet.core.jni.CoinType -import wallet.core.jni.HDWallet -import wallet.core.jni.Hash -import wallet.core.jni.proto.Tezos.* import com.google.protobuf.ByteString import org.json.JSONObject -import wallet.core.jni.CoinType.TEZOS import wallet.core.java.AnySigner +import wallet.core.jni.CoinType +import wallet.core.jni.CoinType.TEZOS +import wallet.core.jni.HDWallet +import wallet.core.jni.Hash import wallet.core.jni.proto.Tezos +import wallet.core.jni.proto.Tezos.* + class XTZ : Coin("XTZ", CoinType.TEZOS) { @@ -51,6 +52,27 @@ class XTZ : Coin("XTZ", CoinType.TEZOS) { val privateKey = wallet.getKey(coinType, path) val txHash: String? val publicKey = privateKey.publicKeyEd25519.data() + val isRevealed = txData["isRevealed"] as Boolean? + var revealOperation: Tezos.Operation = Operation.newBuilder().build() + val listOfAllOperations = mutableListOf(); + + if(isRevealed == false){ + val revealOperationData = RevealOperationData.newBuilder() + .setPublicKey(ByteString.copyFrom(publicKey)) + + revealOperation = Operation.newBuilder() + .setSource(txData["source"] as String) + .setFee(txData["reveal_fee"]!!.toLong()) + .setCounter(txData["reveal_counter"]!!.toLong()) + .setGasLimit(txData["reveal_gasLimit"]!!.toLong()) + .setStorageLimit(txData["reveal_storageLimit"]!!.toLong()) + .setKind(Operation.OperationKind.REVEAL) + .setRevealOperationData(revealOperationData) + .build() + + listOfAllOperations.add(revealOperation) + } + when (cmd) { "FA2" -> { val transferInfos = Txs.newBuilder() @@ -89,29 +111,14 @@ class XTZ : Coin("XTZ", CoinType.TEZOS) { .setTransactionOperationData(transactionData) .build() + listOfAllOperations.add(transaction) + val operationList = OperationList.newBuilder() .setBranch(txData["branch"] as String) - .addOperations(transaction) - .build() - - if(txData["revealed"] == false){ - val revealOperationData = RevealOperationData.newBuilder() - .setPublicKey(ByteString.copyFrom(publicKey)) + .addAllOperations(listOfAllOperations) + .build(); - val reveal = Operation.newBuilder() - .setSource(txData["source"] as String) - .setFee(txData["fee"]!!.toLong()) - .setCounter(txData["counter"]!!.toLong()) - .setGasLimit(txData["gasLimit"]!!.toLong()) - .setStorageLimit(txData["storageLimit"]!!.toLong()) - .setKind(Operation.OperationKind.REVEAL) - .setRevealOperationData(revealOperationData) - .build() - - operationList.operationsList.add(reveal) - } - - val signingInput = SigningInput.newBuilder() + val signingInput = SigningInput.newBuilder() .setPrivateKey(ByteString.copyFrom(privateKey.data())) .setOperationList(operationList) .build() @@ -120,7 +127,6 @@ class XTZ : Coin("XTZ", CoinType.TEZOS) { txHash = Numeric.toHexString(result.encoded.toByteArray()) } "FA12" -> { - val operationList: Tezos.OperationListOrBuilder val fa12 = FA12Parameters.newBuilder() .setEntrypoint("transfer") .setFrom(txData["senderAddress"] as String) @@ -148,33 +154,12 @@ class XTZ : Coin("XTZ", CoinType.TEZOS) { .setTransactionOperationData(transactionData) .build() + listOfAllOperations.add(transaction) - if(txData["revealed"] == false){ - val revealOperationData = RevealOperationData.newBuilder() - .setPublicKey(ByteString.copyFrom(publicKey)) - - val reveal = Operation.newBuilder() - .setSource(txData["source"] as String) - .setFee(txData["fee"]!!.toLong()) - .setCounter(txData["counter"]!!.toLong()) - .setGasLimit(txData["gasLimit"]!!.toLong()) - .setStorageLimit(txData["storageLimit"]!!.toLong()) - .setKind(Operation.OperationKind.REVEAL) - .setRevealOperationData(revealOperationData) - .build() - - operationList = OperationList.newBuilder() - .setBranch(txData["branch"] as String) - .addOperations(reveal) - .addOperations(transaction) - .build() - } - else{ - operationList = OperationList.newBuilder() + val operationList = OperationList.newBuilder() .setBranch(txData["branch"] as String) - .addOperations(transaction) - .build() - } + .addAllOperations(listOfAllOperations) + .build(); val signingInput = SigningInput.newBuilder() .setPrivateKey(ByteString.copyFrom(privateKey.data())) diff --git a/example/lib/operations.dart b/example/lib/operations.dart index 5af8119..5d17e5a 100644 --- a/example/lib/operations.dart +++ b/example/lib/operations.dart @@ -6,40 +6,40 @@ import 'package:trustdart/trustdart.dart'; import 'package:trustdart_example/coins.dart'; Map operations = { - // 'XTZ': { - // "operationList": { - // "branch": "BL8euoCWqNCny9AR3AKjnpi38haYMxjei1ZqNHuXMn19JSQnoWp", - // "operations": [ - // { - // "source": "tz1XVJ8bZUXs7r5NV8dHvuiBhzECvLRLR3jW", - // "fee": 1272, - // "counter": 30738, - // "gasLimit": 10100, - // "storageLimit": 257, - // "kind": 107, - // "revealOperationData": { - // "publicKey": "8z6GkG6TaQVnpYr2gc6r8Q/mS7m0Qf6Ef9VinW8mKXM=" - // } - // }, - // { - // "source": "tz1XVJ8bZUXs7r5NV8dHvuiBhzECvLRLR3jW", - // "fee": 1272, - // "counter": 30739, - // "gasLimit": 10100, - // "storageLimit": 257, - // "kind": 108, - // "transactionOperationData": { - // "destination": "tz1XVJ8bZUXs7r5NV8dHvuiBhzECvLRLR3jW", - // "amount": 1 - // } - // } - // ] - // } - // }, + 'XTZ': { + "operationList": { + "branch": "BL8euoCWqNCny9AR3AKjnpi38haYMxjei1ZqNHuXMn19JSQnoWp", + "operations": [ + { + "source": "tz1XVJ8bZUXs7r5NV8dHvuiBhzECvLRLR3jW", + "fee": 1272, + "counter": 30738, + "gasLimit": 10100, + "storageLimit": 257, + "kind": 107, + "revealOperationData": { + "publicKey": "8z6GkG6TaQVnpYr2gc6r8Q/mS7m0Qf6Ef9VinW8mKXM=" + } + }, + { + "source": "tz1XVJ8bZUXs7r5NV8dHvuiBhzECvLRLR3jW", + "fee": 1272, + "counter": 30739, + "gasLimit": 10100, + "storageLimit": 257, + "kind": 108, + "transactionOperationData": { + "destination": "tz1XVJ8bZUXs7r5NV8dHvuiBhzECvLRLR3jW", + "amount": 1 + } + } + ] + } + }, // 'XTZ': { // "cmd": "FA2", - // "revealed": false, + // "isRevealed": false, // "amount": "10", // "tokenId": "1", // "toAddress": "tz1ioz62kDw6Gm5HApeQtc1PGmN2wPBtJKUP", @@ -48,27 +48,35 @@ Map operations = { // "transactionAmount": 0, // "source": "tz1ioz62kDw6Gm5HApeQtc1PGmN2wPBtJKUP", // "fee": 100000, - // "counter": 2993173, + // "counter": 2993174, // "gasLimit": 100000, // "storageLimit": 0, // "branch": "BKvEAX9HXfJZWYfTQbR1C7B3ADoKY6a1aKVRF7qQqvc9hS8Rr3m", + // "reveal_fee": 100000, + // "reveal_counter": 2993173, + // "reveal_gasLimit": 100000, + // "reveal_storageLimit": 0, + // }, + // 'XTZ': { + // "cmd": "FA12", + // "isRevealed": false, + // "branch": "BL8euoCWqNCny9AR3AKjnpi38haYMxjei1ZqNHuXMn19JSQnoWp", + // "transactionAmount": 0, + // "destination": "KT1DYk1XDzHredJq1EyNkDindiWDqZyekXGj", + // "senderAddress": "tz1ioz62kDw6Gm5HApeQtc1PGmN2wPBtJKUP", + // "toAddress": "tz1ioz62kDw6Gm5HApeQtc1PGmN2wPBtJKUP", + // "value": "123", + // "amount": "0", + // "source": "tz1ioz62kDw6Gm5HApeQtc1PGmN2wPBtJKUP", + // "fee": 100000, + // "counter": 2993173, + // "gasLimit": 100000, + // "storageLimit": 0, + // "reveal_fee": 100000, + // "reveal_counter": 2993173, + // "reveal_gasLimit": 100000, + // "reveal_storageLimit": 0, // }, - 'XTZ': { - "cmd": "FA12", - "revealed": false, - "branch": "BL8euoCWqNCny9AR3AKjnpi38haYMxjei1ZqNHuXMn19JSQnoWp", - "transactionAmount": 0, - "destination": "KT1DYk1XDzHredJq1EyNkDindiWDqZyekXGj", - "senderAddress": "tz1ioz62kDw6Gm5HApeQtc1PGmN2wPBtJKUP", - "toAddress": "tz1ioz62kDw6Gm5HApeQtc1PGmN2wPBtJKUP", - "value": "123", - "amount": "0", - "source": "tz1ioz62kDw6Gm5HApeQtc1PGmN2wPBtJKUP", - "fee": 100000, - "counter": 2993173, - "gasLimit": 100000, - "storageLimit": 0, - }, 'ETH': { "chainId": "AQ==", "gasPrice": "1pOkAA==", diff --git a/ios/Classes/coins/XTZ.swift b/ios/Classes/coins/XTZ.swift index 8d046a6..4637c44 100644 --- a/ios/Classes/coins/XTZ.swift +++ b/ios/Classes/coins/XTZ.swift @@ -34,12 +34,30 @@ class XTZ: Coin { let privateKey = HDWallet(mnemonic: mnemonic, passphrase: passphrase)!.getKey(coin: self.coinType, derivationPath: path) let publicKey = privateKey.getPublicKeyEd25519().data + let isRevealed = txData["isRevealed"] as! Bool? + var revealOperation: TezosOperation = TezosOperation() + var listOfAllOperations: [TezosOperation] = [] + if(isRevealed == false){ + + var revealOperationData = TezosRevealOperationData() + revealOperationData.publicKey = publicKey + + revealOperation = TezosOperation() + revealOperation.source = txData["source"] as! String; + revealOperation.fee = txData["reveal_fee"] as! Int64 + revealOperation.counter = txData["reveal_counter"] as! Int64 + revealOperation.gasLimit = txData["reveal_gasLimit"] as! Int64 + revealOperation.storageLimit = txData["reveal_storageLimit"] as! Int64 + revealOperation.kind = .reveal + revealOperation.revealOperationData = revealOperationData + + listOfAllOperations.append(revealOperation) + } switch(cmd){ case "FA2": var operationList = TezosOperationList() operationList.branch = txData["branch"] as! String - var revealed = txData["revealed"] as! Bool let transferInfos = TezosTxs.with{ $0.to = txData["toAddress"] as! String @@ -67,24 +85,8 @@ class XTZ: Coin { $0.transactionOperationData = transactionOperationData } - if(revealed == false){ - - var revealOperationData = TezosRevealOperationData() - revealOperationData.publicKey = publicKey - - var revealOperation = TezosOperation() - revealOperation.source = txData["source"] as! String; - revealOperation.fee = txData["fee"] as! Int64 - revealOperation.counter = txData["counter"] as! Int64 - revealOperation.gasLimit = txData["gasLimit"] as! Int64 - revealOperation.storageLimit = txData["storageLimit"] as! Int64 - revealOperation.kind = .reveal - revealOperation.revealOperationData = revealOperationData - - operationList.operations = [ transactionOperation, revealOperation ] - }else{ - operationList.operations = [ transactionOperation ] - } + listOfAllOperations.append(transactionOperation) + operationList.operations = listOfAllOperations let input = TezosSigningInput.with { @@ -93,10 +95,9 @@ class XTZ: Coin { } let output: TezosSigningOutput = AnySigner.sign(input: input, coin: .tezos) - txHash = output.encoded.hexString + case "FA12": - var revealed = txData["revealed"] as! Bool var operationList = TezosOperationList() operationList.branch = txData["branch"] as! String @@ -119,24 +120,8 @@ class XTZ: Coin { $0.transactionOperationData = transactionOperationData } - if(revealed == false){ - var revealOperationData = TezosRevealOperationData() - revealOperationData.publicKey = publicKey - - var revealOperation = TezosOperation() - revealOperation.source = txData["source"] as! String; - revealOperation.fee = txData["fee"] as! Int64 - revealOperation.counter = txData["counter"] as! Int64 - revealOperation.gasLimit = txData["gasLimit"] as! Int64 - revealOperation.storageLimit = txData["storageLimit"] as! Int64 - revealOperation.kind = .reveal - revealOperation.revealOperationData = revealOperationData - - operationList.operations = [ transactionOperation, revealOperation ] - - }else{ - operationList.operations = [ transactionOperation ] - } + listOfAllOperations.append(transactionOperation) + operationList.operations = listOfAllOperations let input = TezosSigningInput.with { $0.operationList = operationList