diff --git a/.gitignore b/.gitignore
index f92e31f..a49abe1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,8 @@ build/
.idea/
pubspec.lock
org.eclipse.buildship.core.prefs
+android/.classpath
+android/.project
+example/android/.project
+example/android/.classpath
+
diff --git a/android/.classpath b/android/.classpath
deleted file mode 100644
index 4a04201..0000000
--- a/android/.classpath
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/android/.project b/android/.project
deleted file mode 100644
index 7d02108..0000000
--- a/android/.project
+++ /dev/null
@@ -1,34 +0,0 @@
-
-
- trustdart
- Project trustdart created by Buildship.
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- org.eclipse.buildship.core.gradleprojectbuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
- org.eclipse.buildship.core.gradleprojectnature
-
-
-
- 1636458420059
-
- 30
-
- org.eclipse.core.resources.regexFilterMatcher
- node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
-
-
-
-
diff --git a/android/src/main/kotlin/africa/ejara/trustdart/coins/XLM.kt b/android/src/main/kotlin/africa/ejara/trustdart/coins/XLM.kt
index bb8fef2..8a51e6a 100644
--- a/android/src/main/kotlin/africa/ejara/trustdart/coins/XLM.kt
+++ b/android/src/main/kotlin/africa/ejara/trustdart/coins/XLM.kt
@@ -12,6 +12,19 @@ import wallet.core.jni.StellarPassphrase
class XLM : Coin("XLM", CoinType.STELLAR) {
+ enum class NetworkType(val passphrase: String) {
+ MAINNET("Public Global Stellar Network ; September 2015"),
+ TESTNET("Test SDF Network ; September 2015");
+ companion object {
+ fun fromString(network: String?): NetworkType {
+ return when (network?.lowercase()) {
+ "testnet" -> TESTNET
+ else -> MAINNET // Default to mainnet
+ }
+ }
+ }
+ }
+
override fun getPublicKey(path: String, mnemonic: String, passphrase: String): String? {
val wallet = HDWallet(mnemonic, passphrase)
return wallet.getKey(coinType, path).publicKeyEd25519.data().base64String()
@@ -29,6 +42,11 @@ class XLM : Coin("XLM", CoinType.STELLAR) {
pass_phrase: String
): String? {
val cmd = txData["cmd"] as String
+ val networkType: NetworkType = {
+ val network = txData["network"] as? String
+ NetworkType.fromString(network)
+ }()
+
val secretKey = HDWallet(mnemonic, pass_phrase).getKey(coinType, path)
val txHash: String?
when (cmd) {
@@ -49,7 +67,7 @@ class XLM : Coin("XLM", CoinType.STELLAR) {
account = txData["ownerAddress"] as String
fee = txData["fee"] as Int
sequence = txData["sequence"]!!.toLong()
- passphrase = StellarPassphrase.STELLAR.toString()
+ passphrase = networkType.passphrase
opChangeTrust = operation.build()
privateKey = ByteString.copyFrom(secretKey.data())
}
@@ -58,10 +76,9 @@ class XLM : Coin("XLM", CoinType.STELLAR) {
}
"Payment" -> {
val stellarAsset = Stellar.Asset.newBuilder()
- if (txData["asset"] != null) {
-
+ if (txData["asset"] != null && txData["issuer"] != null) {
stellarAsset.apply {
- issuer = txData["ownerAddress"] as String
+ issuer = txData["issuer"] as String
alphanum4 = txData["asset"] as String
}
}
@@ -78,7 +95,7 @@ class XLM : Coin("XLM", CoinType.STELLAR) {
account = txData["ownerAddress"] as String
fee = txData["fee"] as Int
sequence = txData["sequence"]!!.toLong()
- passphrase = StellarPassphrase.STELLAR.toString()
+ passphrase = networkType.passphrase
opPayment = operation.build()
privateKey = ByteString.copyFrom(secretKey.data())
if (txData["memo"] != null) {
diff --git a/android/src/main/kotlin/africa/ejara/trustdart/utils/Extension.kt b/android/src/main/kotlin/africa/ejara/trustdart/utils/Extension.kt
index 08e07e1..4eff78c 100644
--- a/android/src/main/kotlin/africa/ejara/trustdart/utils/Extension.kt
+++ b/android/src/main/kotlin/africa/ejara/trustdart/utils/Extension.kt
@@ -29,9 +29,10 @@ fun ByteArray.base64String(): String {
}
fun Any.toLong(): Long {
- return if(this is Int){
- this.toLong()
- }else{
- this as Long
+ return when (this) {
+ is Int -> this.toLong()
+ is Long -> this
+ is String -> this.toLongOrNull() ?: throw NumberFormatException("Cannot convert $this to Long")
+ else -> throw IllegalArgumentException("Unsupported type")
}
}
\ No newline at end of file
diff --git a/example/android/.project b/example/android/.project
deleted file mode 100644
index a9d6dc2..0000000
--- a/example/android/.project
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
- android
- Project android created by Buildship.
-
-
-
-
- org.eclipse.buildship.core.gradleprojectbuilder
-
-
-
-
-
- org.eclipse.buildship.core.gradleprojectnature
-
-
-
- 1636458420017
-
- 30
-
- org.eclipse.core.resources.regexFilterMatcher
- node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__
-
-
-
-
diff --git a/example/lib/operations.dart b/example/lib/operations.dart
index acfbab8..aac348f 100644
--- a/example/lib/operations.dart
+++ b/example/lib/operations.dart
@@ -172,9 +172,14 @@ Map operations = {
"cmd": 'Payment',
"ownerAddress": "GCPP3J7CE23VF3EONOIDXDL6QODYTI3YWJ7PNMHTO77WSEXGK2TT4QPV",
"toAddress": "GBPT3GVKY727GYXTO6QAEVET3AW3EUVZZCZOCCO5B5PJXRVS3S4GD2AY",
+ "issuer": "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
+ "network": "testnet",
+ "validBefore": 1717806538278,
"amount": 2000000,
"fee": 10000,
"sequence": 183629192141733925,
+ "asset": "USDC",
+ "memo": "3476840067250060816"
},
// 'XLM': {
// "cmd": "ChangeTrust",
diff --git a/ios/Classes/coins/XLM.swift b/ios/Classes/coins/XLM.swift
index 0faa3e7..4170936 100644
--- a/ios/Classes/coins/XLM.swift
+++ b/ios/Classes/coins/XLM.swift
@@ -4,6 +4,20 @@
import WalletCore
class XLM: Coin {
+ enum NetworkType: String {
+ case mainnet
+ case testnet
+
+ var passphrase: String {
+ switch self {
+ case .mainnet:
+ return "Public Global Stellar Network ; September 2015"
+ case .testnet:
+ return "Test SDF Network ; September 2015"
+ }
+ }
+ }
+
init() {
super.init(name: "XLM", coinType: .stellar)
}
@@ -23,6 +37,14 @@ class XLM: Coin {
let cmd = txData["cmd"] as! String
var txHash: String?
+ let networkType: NetworkType = {
+ if let network = txData["network"], let type = NetworkType(rawValue: network as! String) {
+ return type
+ } else {
+ return .mainnet // Default to mainnet if network is not provided or invalid
+ }
+ }()
+
switch(cmd){
case "ChangeTrust":
let asset = StellarAsset.with {
@@ -39,12 +61,12 @@ class XLM: Coin {
$0.account = txData["ownerAddress"] as! String
$0.fee = txData["fee"] as! Int32
$0.sequence = txData["sequence"] as! Int64
- $0.passphrase = StellarPassphrase.stellar.description
+ $0.passphrase = networkType.passphrase
$0.opChangeTrust = operation
$0.privateKey = privateKey!.data
if (txData["memo"] != nil) {
$0.memoID = StellarMemoId.with {
- $0.id = txData["memo"] as! Int64
+ $0.id = Int64(txData["memo"] as! String)!
}
}
}
@@ -52,13 +74,12 @@ class XLM: Coin {
let output: StellarSigningOutput = AnySigner.sign(input: signingInput, coin: self.coinType)
txHash = output.signature
case "Payment":
-
- let asset = StellarAsset.with {
- $0.issuer = txData["ownerAddress"] as! String
- if (txData["asset"] != nil) {
- $0.alphanum4 = txData["asset"] as! String
- }
+ var asset = StellarAsset()
+ if let assetString = txData["asset"] as? String, let issuer = txData["issuer"] as? String {
+ asset.alphanum4 = assetString
+ asset.issuer = issuer
}
+
let operation = StellarOperationPayment.with {
$0.destination = txData["toAddress"] as! String
$0.amount = txData["amount"] as! Int64
@@ -71,12 +92,12 @@ class XLM: Coin {
$0.account = txData["ownerAddress"] as! String
$0.fee = txData["fee"] as! Int32
$0.sequence = txData["sequence"] as! Int64
- $0.passphrase = StellarPassphrase.stellar.description
+ $0.passphrase = networkType.passphrase
$0.opPayment = operation
$0.privateKey = privateKey!.data
if (txData["memo"] != nil) {
$0.memoID = StellarMemoId.with {
- $0.id = txData["memo"] as! Int64
+ $0.id = Int64(txData["memo"] as! String)!
}
}
}