Skip to content

Commit

Permalink
polygon integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakeally committed Jun 16, 2023
1 parent f95f941 commit 89236a5
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 93 deletions.
22 changes: 18 additions & 4 deletions android/src/main/kotlin/africa/ejara/trustdart/WalletHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import TRX
import XTZ
import XLM
import BNB
import BSC
//import BSC
import DOGE
import MATIC
//import MATIC

import africa.ejara.trustdart.utils.WalletError
import africa.ejara.trustdart.utils.WalletValidateResponse
import wallet.core.jni.CoinType
import wallet.core.jni.HDWallet

class WalletHandler {
Expand All @@ -28,11 +29,24 @@ class WalletHandler {
"NEAR" to NEAR(),
"XLM" to XLM(),
"BNB" to BNB(),
"BSC" to BSC(),
"BSC" to ETH(),
"DOGE" to DOGE(),
"MATIC" to MATIC(),
"MATIC" to ETH(),
)
}
// val coins = mapOf(
// "BTC" to BTC(),
// "ETH" to ETH("ETH", CoinType.ETHEREUM),
// "XTZ" to XTZ(),
// "TRX" to TRX(),
// "SOL" to SOL(),
// "NEAR" to NEAR(),
// "XLM" to XLM(),
// "BNB" to BNB(),
// "BSC" to ETH("BSC", CoinType.SMARTCHAIN),
// "DOGE" to DOGE(),
// "MATIC" to ETH("MATIC", CoinType.POLYGON),
// )

fun getCoin(coin: String?): Coin {
return coins[coin]!!
Expand Down
41 changes: 0 additions & 41 deletions android/src/main/kotlin/africa/ejara/trustdart/coins/BSC.kt

This file was deleted.

59 changes: 58 additions & 1 deletion android/src/main/kotlin/africa/ejara/trustdart/coins/ETH.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
import africa.ejara.trustdart.Coin
import com.google.protobuf.ByteString
import wallet.core.java.AnySigner
import africa.ejara.trustdart.Numeric
import africa.ejara.trustdart.utils.toHexByteArray
import wallet.core.jni.CoinType
import wallet.core.jni.HDWallet
import wallet.core.jni.proto.Ethereum.SigningOutput
import wallet.core.jni.proto.Ethereum

class ETH : Coin("ETH", CoinType.ETHEREUM)
open class ETH: Coin("ETH", CoinType.ETHEREUM) {

override fun signTransaction(
path: String,
txData: Map<String, Any>,
mnemonic: String,
passphrase: String
): String? {
val wallet = HDWallet(mnemonic, passphrase)
val cmd: String? = txData["cmd"] as String?
val signingInput = Ethereum.SigningInput.newBuilder()

signingInput.apply {
privateKey = ByteString.copyFrom(wallet.getKey(coinType, path).data())
toAddress = txData["toAddress"] as String
chainId = ByteString.copyFrom((txData["chainId"] as String).toHexByteArray())
nonce = ByteString.copyFrom((txData["nonce"] as String).toHexByteArray())
gasPrice = ByteString.copyFrom((txData["gasPrice"] as String).toHexByteArray())
gasLimit = ByteString.copyFrom((txData["gasLimit"] as String).toHexByteArray())
}
when (cmd) {
"ERC20" -> {

var transaction = Ethereum.Transaction.newBuilder().apply {
erc20Transfer = Ethereum.Transaction.ERC20Transfer.newBuilder().apply {
to = txData["contractAddress"] as String
amount = ByteString.copyFrom((txData["amount"] as String).toHexByteArray())
}.build()
}.build()

signingInput.transaction = transaction
}
else -> {
var transaction = Ethereum.Transaction.newBuilder().apply {
transfer = Ethereum.Transaction.Transfer.newBuilder().apply {
amount = ByteString.copyFrom((txData["amount"] as String).toHexByteArray())
}.build()
}.build()


signingInput.setTransaction(transaction)
}

}
val sign = AnySigner.sign(signingInput.build(), coinType, SigningOutput.parser())

return Numeric.toHexString(sign.encoded.toByteArray())

}

}
39 changes: 0 additions & 39 deletions android/src/main/kotlin/africa/ejara/trustdart/coins/MATIC.kt

This file was deleted.

39 changes: 31 additions & 8 deletions example/lib/operations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,37 @@ Map<String, dynamic> operations = {
"fees": 5000,
"changeAddress": "D9pvhnWknRza2HTXhY5WT29D4kvYzTZQAF",
},
'MATIC': {
"chainID": "0x01",
"nonce": "0x00",
"gasPrice": "0x07FF684650",
"gasLimit": "0x5208",
"toAddress": "0xC894F1dCE55358ef44D760d8B1fb3397F5b1c24b",
"amount": "0x0DE0B6B3A7640000",
},
// 'MATIC': {
// "chainID": "0x89",
// "nonce": "0x00",
// "gasPrice": "0x07FF684650",
// "gasLimit": "0x5208",
// "toAddress": "0xC894F1dCE55358ef44D760d8B1fb3397F5b1c24b",
// "amount": "0x0DE0B6B3A7640000",
// },
//............Polygon USDC test........
// 'MATIC': {
// "cmd": "ERC20",
// "chainID": "0x89",
// "nonce": "0x00",
// "gasPrice": "0x07FF684650",
// "gasLimit": "0x5208",
// "toAddress": "0xC894F1dCE55358ef44D760d8B1fb3397F5b1c24b",
// "amount": "0x0DE0B6B3A7640000",
// "contractAddress": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"
// },

//............Polygon USDT test........
// 'MATIC': {
// "cmd": "ERC20",
// "chainID": "0x89",
// "nonce": "0x00",
// "gasPrice": "0x07FF684650",
// "gasLimit": "0x5208",
// "toAddress": "0xC894F1dCE55358ef44D760d8B1fb3397F5b1c24b",
// "amount": "0x0DE0B6B3A7640000",
// "contractAddress": "0xc2132D05D31c914a87C6611C10748AEb04B58e8F"
// },
};

// ignore: inference_failure_on_function_return_type
Expand Down

0 comments on commit 89236a5

Please sign in to comment.