From 5f259b5f495bba7e183d17fe77a0cfc83af7f09c Mon Sep 17 00:00:00 2001 From: Rakeally <40327144+Rakeally@users.noreply.github.com> Date: Mon, 26 Jun 2023 18:58:42 +0100 Subject: [PATCH 1/4] updated cardano implementation --- ios/Classes/coins/ADA.swift | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/ios/Classes/coins/ADA.swift b/ios/Classes/coins/ADA.swift index 524678d..b4a9abd 100644 --- a/ios/Classes/coins/ADA.swift +++ b/ios/Classes/coins/ADA.swift @@ -14,23 +14,25 @@ class ADA: Coin { let utxos: [[String: Any]] = txData["utxos"] as! [[String: Any]] var listOfUtxos: [CardanoTxInput] = [] + + var input = CardanoSigningInput.with { + $0.transferMessage.toAddress = txData["receiverAddress"] as! String + $0.transferMessage.changeAddress = txData["senderAddress"] as! String + $0.transferMessage.amount = txData["amount"] as! UInt64 + $0.ttl = txData["ttl"] as! UInt64 + } + input.privateKey.append(privateKey!.data) + for utx in utxos { - listOfUtxos.append(CardanoTxInput.with { + var utxo = CardanoTxInput.with { $0.outPoint.txHash = Data(hexString: (utx["txid"] as! String))! $0.outPoint.outputIndex = utx["index"] as! UInt64 $0.address = utx["senderAddress"] as! String - $0.amount = utx["amount"] as! UInt64 - }) + $0.amount = utx["balance"] as! UInt64 + } + input.utxos.append(utxo) } - var input = CardanoSigningInput.with { - $0.transferMessage.toAddress = txData["receiverAddress"] as! String - $0.transferMessage.changeAddress = txData["senderAddress"] as! String - $0.transferMessage.amount = txData["amount"] as! UInt64 - $0.ttl = 53333333 - $0.privateKey = [privateKey!.data] - $0.utxos = listOfUtxos - } let output: CardanoSigningOutput = AnySigner.sign(input: input, coin: .cardano) return output.encoded.hexString From 9d589245e090a2b2b4afcac8dd3a4d14c1892cf8 Mon Sep 17 00:00:00 2001 From: Rakeally <40327144+Rakeally@users.noreply.github.com> Date: Mon, 26 Jun 2023 19:49:12 +0100 Subject: [PATCH 2/4] updated cardano implementation --- example/lib/operations.dart | 2 +- ios/Classes/coins/ADA.swift | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/example/lib/operations.dart b/example/lib/operations.dart index 220e3cd..22b5301 100644 --- a/example/lib/operations.dart +++ b/example/lib/operations.dart @@ -256,7 +256,7 @@ Map operations = { "txid": "76608917328b3768b3985d057e613c7e8f14cb1f27b132a750a363ee64363a57", "index": 0, - "amount": 16900000, + "balance": 16900000, }, ], } diff --git a/ios/Classes/coins/ADA.swift b/ios/Classes/coins/ADA.swift index e2a39cf..924c017 100644 --- a/ios/Classes/coins/ADA.swift +++ b/ios/Classes/coins/ADA.swift @@ -19,7 +19,7 @@ class ADA: Coin { $0.outPoint.txHash = Data(hexString: (utx["txid"] as! String))! $0.outPoint.outputIndex = utx["index"] as! UInt64 $0.address = utx["senderAddress"] as! String - $0.amount = utx["amount"] as! UInt64 + $0.amount = utx["balance"] as! UInt64 }) } @@ -41,7 +41,6 @@ class ADA: Coin { input.utxos.append(utxo) } - let output: CardanoSigningOutput = AnySigner.sign(input: input, coin: .cardano) return output.encoded.hexString } From 82eb8bcee8126ec09138ab3adff75a5b076c8f5d Mon Sep 17 00:00:00 2001 From: Rakeally <40327144+Rakeally@users.noreply.github.com> Date: Mon, 26 Jun 2023 19:50:25 +0100 Subject: [PATCH 3/4] updated cardano implementation --- .../src/main/kotlin/africa/ejara/trustdart/coins/ADA.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android/src/main/kotlin/africa/ejara/trustdart/coins/ADA.kt b/android/src/main/kotlin/africa/ejara/trustdart/coins/ADA.kt index 178d3d0..8ecba67 100644 --- a/android/src/main/kotlin/africa/ejara/trustdart/coins/ADA.kt +++ b/android/src/main/kotlin/africa/ejara/trustdart/coins/ADA.kt @@ -29,7 +29,7 @@ class ADA : Coin("ADA", CoinType.CARDANO){ .build() val input = Cardano.SigningInput.newBuilder() .setTransferMessage(message) - .setTtl(53333333) + .setTtl(utx["ttl"]!!.toLong()) input.addPrivateKey(ByteString.copyFrom(privateKey.data())) for (utx in utxos) { @@ -37,12 +37,12 @@ class ADA : Coin("ADA", CoinType.CARDANO){ .setTxHash(ByteString.copyFrom(Numeric.hexStringToByteArray(utx["txid"] as String))) .setOutputIndex(utx["index"]!!.toLong()) .build() - val utxo1 = Cardano.TxInput.newBuilder() + val utxo = Cardano.TxInput.newBuilder() .setOutPoint(outpoint1) .setAddress(utx["senderAddress"] as String) - .setAmount(utx["amount"]!!.toLong()) + .setAmount(utx["balance"]!!.toLong()) .build() - listOfAllUtxos.add(utxo1) + listOfAllUtxos.add(utxo) } input.addAllUtxos(listOfAllUtxos) From b0d44ab480b3da0e6af38e4b62c11a98e83a0fe9 Mon Sep 17 00:00:00 2001 From: Rakeally <40327144+Rakeally@users.noreply.github.com> Date: Wed, 28 Jun 2023 18:00:56 +0100 Subject: [PATCH 4/4] resolved reviews --- .../kotlin/africa/ejara/trustdart/coins/ADA.kt | 6 +++--- example/lib/operations.dart | 1 + ios/Classes/coins/ADA.swift | 18 ++++++------------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/android/src/main/kotlin/africa/ejara/trustdart/coins/ADA.kt b/android/src/main/kotlin/africa/ejara/trustdart/coins/ADA.kt index 8ecba67..cccfea2 100644 --- a/android/src/main/kotlin/africa/ejara/trustdart/coins/ADA.kt +++ b/android/src/main/kotlin/africa/ejara/trustdart/coins/ADA.kt @@ -29,16 +29,16 @@ class ADA : Coin("ADA", CoinType.CARDANO){ .build() val input = Cardano.SigningInput.newBuilder() .setTransferMessage(message) - .setTtl(utx["ttl"]!!.toLong()) + .setTtl(txData["ttl"]!!.toLong()) input.addPrivateKey(ByteString.copyFrom(privateKey.data())) for (utx in utxos) { - val outpoint1 = Cardano.OutPoint.newBuilder() + val outpoint = Cardano.OutPoint.newBuilder() .setTxHash(ByteString.copyFrom(Numeric.hexStringToByteArray(utx["txid"] as String))) .setOutputIndex(utx["index"]!!.toLong()) .build() val utxo = Cardano.TxInput.newBuilder() - .setOutPoint(outpoint1) + .setOutPoint(outpoint) .setAddress(utx["senderAddress"] as String) .setAmount(utx["balance"]!!.toLong()) .build() diff --git a/example/lib/operations.dart b/example/lib/operations.dart index 22b5301..590e87e 100644 --- a/example/lib/operations.dart +++ b/example/lib/operations.dart @@ -249,6 +249,7 @@ Map operations = { "receiverAddress": "addr1qyk022rpw85g7c0f0wuq6zpkakgjwsftmpd99wqjj4xcsjc74pfgs7t76yuehca7hn4pcl37lsl06ccey0epe5sp4lwslxsyrw", "amount": 40000, + "ttl": 53333333, "utxos": [ { "senderAddress": diff --git a/ios/Classes/coins/ADA.swift b/ios/Classes/coins/ADA.swift index 924c017..5d3a1c9 100644 --- a/ios/Classes/coins/ADA.swift +++ b/ios/Classes/coins/ADA.swift @@ -23,25 +23,19 @@ class ADA: Coin { }) } - var input = CardanoSigningInput.with { + let input = CardanoSigningInput.with { $0.transferMessage.toAddress = txData["receiverAddress"] as! String $0.transferMessage.changeAddress = txData["senderAddress"] as! String $0.transferMessage.amount = txData["amount"] as! UInt64 $0.ttl = txData["ttl"] as! UInt64 - } - input.privateKey.append(privateKey!.data) - - for utx in utxos { - var utxo = CardanoTxInput.with { - $0.outPoint.txHash = Data(hexString: (utx["txid"] as! String))! - $0.outPoint.outputIndex = utx["index"] as! UInt64 - $0.address = utx["senderAddress"] as! String - $0.amount = utx["balance"] as! UInt64 - } - input.utxos.append(utxo) + $0.privateKey = [privateKey!.data] + $0.utxos = listOfUtxos } let output: CardanoSigningOutput = AnySigner.sign(input: input, coin: .cardano) return output.encoded.hexString } } + + +