Skip to content

Commit

Permalink
resolve feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakeally committed May 10, 2023
1 parent 4c07ba1 commit 30d9d74
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 141 deletions.
6 changes: 3 additions & 3 deletions android/src/main/kotlin/africa/ejara/trustdart/coins/NEAR.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
87 changes: 36 additions & 51 deletions android/src/main/kotlin/africa/ejara/trustdart/coins/XTZ.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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<Tezos.Operation>();

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()
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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()))
Expand Down
104 changes: 56 additions & 48 deletions example/lib/operations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,40 @@ import 'package:trustdart/trustdart.dart';
import 'package:trustdart_example/coins.dart';

Map<String, dynamic> 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",
Expand All @@ -48,27 +48,35 @@ Map<String, dynamic> 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==",
Expand Down
63 changes: 24 additions & 39 deletions ios/Classes/coins/XTZ.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 30d9d74

Please sign in to comment.