Skip to content

Commit

Permalink
nfts, global, transaction set up
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaeppy414 committed Jul 31, 2023
1 parent 54dcc33 commit cd18e4f
Show file tree
Hide file tree
Showing 6 changed files with 1,055 additions and 470 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/src/main/java/com/example/android_sdk/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() {
getString(R.string.kthulu_database_driver_class_name)
)

val networkArray = arrayOf("ethereum", "cypress", "polygon", "bnb")
val accountArray = arrayOf("0x7760E0243cA9BAA630412865DF7b39AfbA42Ff0f", "0x7760E0243cA9BAA630412865DF7b39AfbA42Ff0f")
// val networkArray = arrayOf("ethereum", "cypress", "polygon", "bnb")
// val accountArray = arrayOf("0x7760E0243cA9BAA630412865DF7b39AfbA42Ff0f", "0x7760E0243cA9BAA630412865DF7b39AfbA42Ff0f")
// val accountsAddtess = "0x1C3c32DFB8cBe1E144d5e79eB41392e535405C40"
// Using coroutines to avoid blocking the UI thread
launch {
withContext(Dispatchers.IO) {
// account()
// transaction()
// var getNFTsByWalletTest = getNFTsByWallet(networkArray, account)
var getNFTsByWalletTest = getNFTsByWallet(networkArray, accountArray)
println("getNFTsByWalletTest ===== " + getNFTsByWalletTest)
// var getNFTsByWalletTest = getNFTsByWallet(networkArray, accountArray)
// println("getNFTsByWalletTest ===== " + getNFTsByWalletTest)
// var getNFTTransaction = getNFTTransaction("ethereum", "0x3296379a4F0fFEcE6Da595d1206f3dD85fC08508", "9072")
// println("getNFTTransaction ==== " + getNFTTransaction)
// var gas = getEstimateGas("ethereum", "baseFee")
Expand Down
56 changes: 55 additions & 1 deletion app/src/main/java/com/example/android_sdk/global.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import java.security.spec.X509EncodedKeySpec
import java.util.Base64
import javax.crypto.Cipher

public val addrTransferGoerli = "0x25df7c4d54ce69faf37352cbe98e2d3f9281eaf7"
public val addrBridgeGoerli = "0x25df7c4d54ce69faf37352cbe98e2d3f9281eaf7"


// Create RSA key
fun generateRSAKeyPair() : KeyPair {
Expand Down Expand Up @@ -126,7 +129,8 @@ suspend fun getEstimateGas(
symbol: String? = null,
owner: String? = null,
baseURI: String? = null,
uriType: String? = null
uriType: String? = null,
tokenURI: String? = null
): BigInteger = withContext(Dispatchers.IO) {
val rpcUrl = when (network) {
"ethereum" -> "https://mainnet.infura.io/v3/02c509fda7da4fed882ac537046cfd66"
Expand Down Expand Up @@ -192,6 +196,31 @@ suspend fun getEstimateGas(
result = BigInteger.ZERO
}
}
"deployERC20" ->
if (name != null && symbol != null && fromAddress != null && owner != null) {
val function = Function(
"deployWrapped20",
listOf(Utf8String(name), Utf8String(symbol), Address(owner)),
emptyList()
)
val encodedFunction = FunctionEncoder.encode(function)

try {
result = web3.ethEstimateGas(
Transaction.createFunctionCallTransaction(
fromAddress,
BigInteger.ONE,
gasPrice,
BigInteger.ZERO, // temporary gasLimit
addrBridgeGoerli,
encodedFunction // data
)
).send().amountUsed
} catch (ex: Exception) {
// Handle the exception appropriately
result = BigInteger.ZERO
}
}
"transferERC721" ->
if (tokenAddress != null && toAddress != null && fromAddress != null && tokenId != null) {
val function = Function(
Expand Down Expand Up @@ -299,6 +328,31 @@ suspend fun getEstimateGas(
result = BigInteger.ZERO
}
}
"mintERC721" ->
if (fromAddress != null && toAddress != null && tokenURI != null && tokenId != null && tokenAddress != null) {
val function = Function(
"mint",
listOf(Address(toAddress), Uint256(BigInteger(tokenId)), Utf8String(tokenURI)),
emptyList()
)
val encodedFunction = FunctionEncoder.encode(function)

try {
result = web3.ethEstimateGas(
Transaction.createFunctionCallTransaction(
fromAddress,
BigInteger.ONE,
gasPrice,
BigInteger.ZERO, // temporary gasLimit
tokenAddress,
encodedFunction // data
)
).send().amountUsed
} catch (ex: Exception) {
// Handle the exception appropriately
result = BigInteger.ZERO
}
}
}
BigDecimal(result).multiply(BigDecimal(1.2)).setScale(0, RoundingMode.DOWN).toBigInteger()
}
Loading

0 comments on commit cd18e4f

Please sign in to comment.