From 8bdee5956f2593f86c08708aea675cac85014ded Mon Sep 17 00:00:00 2001 From: Jun Luo <4catcode@gmail.com> Date: Fri, 22 Sep 2023 16:02:34 +0800 Subject: [PATCH] set min sdk to 24 --- .github/workflows/test-deploy.yml | 2 +- android_test/app/build.gradle.kts | 4 +- .../javastellarsdkdemoapp/MainActivity.kt | 72 ++++++++++++++++++- .../ic_launcher_foreground.xml | 0 .../ic_launcher.xml | 0 .../ic_launcher_round.xml | 0 android_test/settings.gradle.kts | 1 + 7 files changed, 73 insertions(+), 6 deletions(-) rename android_test/app/src/main/res/{drawable => drawable-v24}/ic_launcher_foreground.xml (100%) rename android_test/app/src/main/res/{mipmap-anydpi => mipmap-anydpi-v26}/ic_launcher.xml (100%) rename android_test/app/src/main/res/{mipmap-anydpi => mipmap-anydpi-v26}/ic_launcher_round.xml (100%) diff --git a/.github/workflows/test-deploy.yml b/.github/workflows/test-deploy.yml index 0f94a09cc..ae76d950b 100644 --- a/.github/workflows/test-deploy.yml +++ b/.github/workflows/test-deploy.yml @@ -75,7 +75,7 @@ jobs: # minSdk and targetSdk, see ${project_root}/android_test/app/build.gradle.kts # TODO: Investigate why it is unstable on API 33. emulator: [ - { api-level: 26, target: google_apis }, + { api-level: 24, target: google_apis }, { api-level: 32, target: playstore } ] steps: diff --git a/android_test/app/build.gradle.kts b/android_test/app/build.gradle.kts index 2f7727b8d..c531c7e9c 100644 --- a/android_test/app/build.gradle.kts +++ b/android_test/app/build.gradle.kts @@ -9,7 +9,7 @@ android { defaultConfig { applicationId = "org.stellar.javastellarsdkdemoapp" - minSdk = 26 + minSdk = 24 targetSdk = 33 versionCode = 1 versionName = "1.0" @@ -59,9 +59,9 @@ dependencies { implementation("androidx.compose.ui:ui-graphics") implementation("androidx.compose.ui:ui-tooling-preview") implementation("androidx.compose.material3:material3") - implementation(files("libs/stellar-sdk.jar")) // Since we are adding local jar(libs/stellar-sdk.jar) as dependency, // gradle cannot automatically download the required third-party dependencies. + implementation(files("libs/stellar-sdk.jar")) implementation("com.squareup.okhttp3:okhttp:4.11.0") implementation("com.squareup.okhttp3:okhttp-sse:4.11.0") implementation("com.moandjiezana.toml:toml4j:0.7.2") diff --git a/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/MainActivity.kt b/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/MainActivity.kt index f82f4a30a..1f533cd99 100644 --- a/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/MainActivity.kt +++ b/android_test/app/src/main/java/org/stellar/javastellarsdkdemoapp/MainActivity.kt @@ -30,6 +30,7 @@ import org.stellar.javastellarsdkdemoapp.ui.theme.JavaStellarSDKDemoAppTheme import org.stellar.sdk.Account import org.stellar.sdk.AccountConverter import org.stellar.sdk.Address +import org.stellar.sdk.Auth import org.stellar.sdk.InvokeHostFunctionOperation import org.stellar.sdk.KeyPair import org.stellar.sdk.Network @@ -39,6 +40,8 @@ import org.stellar.sdk.TimeBounds import org.stellar.sdk.Transaction import org.stellar.sdk.TransactionBuilder import org.stellar.sdk.TransactionPreconditions +import org.stellar.sdk.federation.FederationServer +import org.stellar.sdk.scval.Scv import org.stellar.sdk.xdr.ContractExecutable import org.stellar.sdk.xdr.ContractExecutableType import org.stellar.sdk.xdr.ContractIDPreimage @@ -49,10 +52,18 @@ import org.stellar.sdk.xdr.ExtensionPoint import org.stellar.sdk.xdr.HostFunction import org.stellar.sdk.xdr.HostFunctionType import org.stellar.sdk.xdr.Int64 +import org.stellar.sdk.xdr.InvokeContractArgs import org.stellar.sdk.xdr.LedgerEntryType import org.stellar.sdk.xdr.LedgerFootprint import org.stellar.sdk.xdr.LedgerKey import org.stellar.sdk.xdr.LedgerKey.LedgerKeyAccount +import org.stellar.sdk.xdr.SorobanAddressCredentials +import org.stellar.sdk.xdr.SorobanAuthorizationEntry +import org.stellar.sdk.xdr.SorobanAuthorizedFunction +import org.stellar.sdk.xdr.SorobanAuthorizedFunctionType +import org.stellar.sdk.xdr.SorobanAuthorizedInvocation +import org.stellar.sdk.xdr.SorobanCredentials +import org.stellar.sdk.xdr.SorobanCredentialsType import org.stellar.sdk.xdr.SorobanResources import org.stellar.sdk.xdr.SorobanTransactionData import org.stellar.sdk.xdr.Uint256 @@ -129,13 +140,25 @@ private fun testSDK(): String { return try { // send request to horizon server val server = Server("https://horizon-testnet.stellar.org") - server.root() + val horizonResp = server.root() + if (horizonResp == null || horizonResp.networkPassphrase != Network.TESTNET.networkPassphrase) { + throw Exception("Query Horizon failed") + } // send request to Soroban RPC server val sorobanServer = SorobanServer("https://soroban-testnet.stellar.org:443") - sorobanServer.health + if (sorobanServer.network.passphrase != Network.TESTNET.networkPassphrase) { + throw Exception("Query Soroban Server failed") + } - // build transaction + // Test Federation + val fedResp = + FederationServer.createForDomain("lobstr.co").resolveAddress("example*lobstr.co") + if (fedResp == null || fedResp.accountId == null) { + throw Exception("Query Federation failed") + } + + // build and parse transaction val source: KeyPair = KeyPair.fromSecretSeed("SCH27VUZZ6UAKB67BDNF6FA42YMBMQCBKXWGMFD5TZ6S5ZZCZFLRXKHS") @@ -213,6 +236,49 @@ private fun testSDK(): String { .setSorobanData(sorobanDataString) .build() transaction.sign(source) + Transaction.fromEnvelopeXdr(transaction.toEnvelopeXdrBase64(), Network.TESTNET) + + // sign entry + val contractId = "CDCYWK73YTYFJZZSJ5V7EDFNHYBG4QN3VUNG2IGD27KJDDPNCZKBCBXK" + val signer = + KeyPair.fromSecretSeed("SAEZSI6DY7AXJFIYA4PM6SIBNEYYXIEM2MSOTHFGKHDW32MBQ7KVO6EN") + val validUntilLedgerSeq = 654656L + val network = Network.TESTNET + + val credentials = SorobanCredentials.Builder() + .discriminant(SorobanCredentialsType.SOROBAN_CREDENTIALS_ADDRESS) + .address( + SorobanAddressCredentials.Builder() + .address(Address(signer.accountId).toSCAddress()) + .nonce(Int64(123456789L)) + .signatureExpirationLedger(Uint32(XdrUnsignedInteger(0L))) + .signature(Scv.toVoid()) + .build() + ) + .build() + val invocation = SorobanAuthorizedInvocation.Builder() + .function( + SorobanAuthorizedFunction.Builder() + .discriminant( + SorobanAuthorizedFunctionType.SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN + ) + .contractFn( + InvokeContractArgs.Builder() + .contractAddress(Address(contractId).toSCAddress()) + .functionName(Scv.toSymbol("increment").sym) + .args(arrayOfNulls(0)) + .build() + ) + .build() + ) + .subInvocations(arrayOfNulls(0)) + .build() + val entry = SorobanAuthorizationEntry.Builder() + .credentials(credentials) + .rootInvocation(invocation) + .build() + Auth.authorizeEntry(entry.toXdrBase64(), signer, validUntilLedgerSeq, network) + "SUCCESS" } catch (e: Exception) { Log.e("MainActivity", "testSDK ERROR", e) diff --git a/android_test/app/src/main/res/drawable/ic_launcher_foreground.xml b/android_test/app/src/main/res/drawable-v24/ic_launcher_foreground.xml similarity index 100% rename from android_test/app/src/main/res/drawable/ic_launcher_foreground.xml rename to android_test/app/src/main/res/drawable-v24/ic_launcher_foreground.xml diff --git a/android_test/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/android_test/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml similarity index 100% rename from android_test/app/src/main/res/mipmap-anydpi/ic_launcher.xml rename to android_test/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml diff --git a/android_test/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/android_test/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml similarity index 100% rename from android_test/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml rename to android_test/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml diff --git a/android_test/settings.gradle.kts b/android_test/settings.gradle.kts index 756213d0f..83bd517df 100644 --- a/android_test/settings.gradle.kts +++ b/android_test/settings.gradle.kts @@ -10,6 +10,7 @@ dependencyResolutionManagement { repositories { google() mavenCentral() + maven { url = uri("https://jitpack.io") } } }