Remove non-kotlin related files, add bdk-ffi as submodule, update build.sh

This commit is contained in:
Steve Myers
2021-12-13 22:14:16 -08:00
parent 09ce971708
commit 0f42ba7590
29 changed files with 151 additions and 780 deletions

95
android/build.gradle Normal file
View File

@@ -0,0 +1,95 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'
apply plugin: 'signing'
android {
compileSdkVersion 30
defaultConfig {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'net.java.dev.jna:jna:5.8.0@aar'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.core:core-ktx:1.5.0'
api "org.slf4j:slf4j-api:1.7.30"
androidTestImplementation 'com.github.tony19:logback-android:2.0.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'
}
afterEvaluate {
publishing {
publications {
// Creates a Maven publication called "release".
release(MavenPublication) {
// You can then customize attributes of the publication as shown below.
groupId = 'org.bitcoindevkit'
artifactId = 'bdk-android'
version = '0.1.3-dev'
// Applies the component for the release build variant.
from components.release
pom {
name = 'bdk-android'
description = 'Bitcoin Dev Kit Kotlin language bindings.'
url = "https://bitcoindevkit.org"
licenses {
license {
name = "APACHE"
url = "https://github.com/bitcoindevkit/bdk/blob/master/LICENSE-APACHE"
}
license {
name = "MIT"
url = "https://github.com/bitcoindevkit/bdk/blob/master/LICENSE-MIT"
}
}
developers {
developer {
id = 'notmandatory'
name = 'Steve Myers'
email = 'notmandatory@noreply.github.org'
}
developer {
id = 'artfuldev'
name = 'Sudarsan Balaji'
email = 'sudarsan.balaji@artfuldev.com'
}
}
scm {
connection = 'scm:git:github.com/bitcoindevkit/bdk-ffi.git'
developerConnection = 'scm:git:ssh://github.com/bitcoindevkit/bdk-ffi.git'
url = 'https://github.com/bitcoindevkit/bdk-ffi/tree/master'
}
}
}
}
}
}
signing {
useGpgCmd()
sign publishing.publications
}

28
android/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,28 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
# for JNA
-dontwarn java.awt.*
-keep class com.sun.jna.* { *; }
-keep class org.bitcoindevkit.* { *; }
-keepclassmembers class * extends org.bitcoindevkit.* { public *; }
-keepclassmembers class * extends com.sun.jna.* { public *; }

View File

@@ -0,0 +1,14 @@
<configuration>
<appender name="logcat" class="ch.qos.logback.classic.android.LogcatAppender">
<tagEncoder>
<pattern>%logger{12}</pattern>
</tagEncoder>
<encoder>
<pattern>[%-20thread] %msg</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="logcat" />
</root>
</configuration>

View File

@@ -0,0 +1,106 @@
package org.bitcoindevkit
import org.junit.Assert.*
import org.junit.Test
import android.app.Application
import android.content.Context.MODE_PRIVATE
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.runner.RunWith
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.File
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class AndroidLibTest {
fun getTestDataDir(): String {
val context = ApplicationProvider.getApplicationContext<Application>()
return context.getDir("bdk-test", MODE_PRIVATE).toString()
}
fun cleanupTestDataDir(testDataDir: String) {
File(testDataDir).deleteRecursively()
}
val log: Logger = LoggerFactory.getLogger(AndroidLibTest::class.java)
val desc =
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"
@Test
fun memoryWalletNewAddress() {
val config = DatabaseConfig.Memory("")
val wallet = OfflineWallet(desc, Network.REGTEST, config)
val address = wallet.getNewAddress()
assertNotNull(address)
assertEquals(address, "bcrt1qzg4mckdh50nwdm9hkzq06528rsu73hjxytqkxs")
}
@Test(expected = BdkException.Descriptor::class)
fun invalidDescriptorExceptionIsThrown() {
val config = DatabaseConfig.Memory("")
OfflineWallet("invalid-descriptor", Network.REGTEST, config)
}
@Test
fun sledWalletNewAddress() {
val testDataDir = getTestDataDir()
val config = DatabaseConfig.Sled(SledDbConfiguration(testDataDir, "testdb"))
val wallet = OfflineWallet(desc, Network.REGTEST, config)
val address = wallet.getNewAddress()
assertNotNull(address)
assertEquals(address, "bcrt1qzg4mckdh50nwdm9hkzq06528rsu73hjxytqkxs")
cleanupTestDataDir(testDataDir)
}
@Test
fun onlineWalletInMemory() {
val db = DatabaseConfig.Memory("")
val client = BlockchainConfig.Electrum(
ElectrumConfig(
"ssl://electrum.blockstream.info:60002",
null,
5u,
null,
100u
)
)
val wallet = OnlineWallet(desc, null, Network.TESTNET, db, client)
assertNotNull(wallet)
val network = wallet.getNetwork()
assertEquals(network, Network.TESTNET)
}
class LogProgress : BdkProgress {
val log: Logger = LoggerFactory.getLogger(AndroidLibTest::class.java)
override fun update(progress: Float, message: String?) {
log.debug("Syncing...")
}
}
@Test
fun onlineWalletSyncGetBalance() {
val db = DatabaseConfig.Memory("")
val client = BlockchainConfig.Electrum(
ElectrumConfig(
"ssl://electrum.blockstream.info:60002",
null,
5u,
null,
100u
)
)
val wallet = OnlineWallet(desc, null, Network.TESTNET, db, client)
wallet.sync(LogProgress(), null)
val balance = wallet.getBalance()
assertTrue(balance > 0u)
}
}

View File

@@ -0,0 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.bitcoindevkit">
<uses-permission android:name="android.permission.INTERNET" />
</manifest>