[WIP] reorganize and remove old stuff

This commit is contained in:
Steve Myers
2021-10-12 15:24:11 -07:00
parent a7f7ab0ef9
commit 290db0105f
55 changed files with 21 additions and 3040 deletions

View File

@@ -1,7 +0,0 @@
/target
.idea
.gradle
local.properties
build
*.so
*.dylib

View File

@@ -1,71 +0,0 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'maven-publish'
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'
}
}
}
afterEvaluate {
publishing {
publications {
// Creates a Maven publication called "release".
release(MavenPublication) {
// Applies the component for the release build variant.
from components.release
// You can then customize attributes of the publication as shown below.
groupId = 'org.bitcoindevkit'
artifactId = 'bdk'
version = '0.0.1-SNAPSHOT'
}
// Creates a Maven publication called “debug”.
debug(MavenPublication) {
// Applies the component for the debug build variant.
from components.debug
groupId = 'org.bitcoindevkit'
artifactId = 'bdk-debug'
version = '0.0.1-SNAPSHOT'
}
}
}
}
dependencies {
implementation(project(':jvm')) {
exclude group: 'net.java.dev.jna', module: 'jna'
}
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(project(':test-fixtures')) {
exclude group: 'net.java.dev.jna', module: 'jna'
}
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'
}

View File

@@ -1,26 +0,0 @@
# 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.* { *; }
-keepclassmembers class * extends com.sun.jna.* { public *; }

View File

@@ -1,14 +0,0 @@
<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

@@ -1,21 +0,0 @@
package org.bitcoindevkit.bdk
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
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class AndroidLibTest : LibTest() {
override fun getTestDataDir(): String {
val context = ApplicationProvider.getApplicationContext<Application>()
return context.getDir("bdk-test", MODE_PRIVATE).toString()
}
}

View File

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

View File

@@ -1,22 +0,0 @@
buildscript {
ext.kotlin_version = '1.5.10'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

View File

@@ -1,21 +0,0 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official

Binary file not shown.

View File

@@ -1,5 +0,0 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

185
bdk-kotlin/gradlew vendored
View File

@@ -1,185 +0,0 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

View File

@@ -1,89 +0,0 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@@ -1,37 +0,0 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
id 'java-library'
id 'maven-publish'
}
test {
testLogging {
events "PASSED", "SKIPPED", "FAILED", "STANDARD_OUT", "STANDARD_ERROR"
}
}
dependencies {
implementation platform('org.jetbrains.kotlin:kotlin-bom')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "net.java.dev.jna:jna:5.8.0"
api "org.slf4j:slf4j-api:1.7.30"
testImplementation "ch.qos.logback:logback-classic:1.2.3"
testImplementation "ch.qos.logback:logback-core:1.2.3"
testImplementation(project(':test-fixtures'))
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'org.bitcoindevkit'
artifactId = 'bdk'
version = '0.0.1-SNAPSHOT'
from components.java
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -1,45 +0,0 @@
package org.bitcoindevkit.bdk
enum class FfiError {
None,
InvalidU32Bytes,
Generic,
ScriptDoesntHaveAddressForm,
SingleRecipientMultipleOutputs,
SingleRecipientNoInputs,
NoRecipients,
NoUtxosSelected,
OutputBelowDustLimit,
InsufficientFunds,
BnBTotalTriesExceeded,
BnBNoExactMatch,
UnknownUtxo,
TransactionNotFound,
TransactionConfirmed,
IrreplaceableTransaction,
FeeRateTooLow,
FeeTooLow,
MissingKeyOrigin,
Key,
ChecksumMismatch,
SpendingPolicyRequired,
InvalidPolicyPathError,
Signer,
InvalidProgressValue,
ProgressUpdateError,
InvalidOutpoint,
Descriptor,
AddressValidator,
Encode,
Miniscript,
Bip32,
Secp256k1,
Json,
Hex,
Psbt,
Electrum,
// Esplora
// CompactFilters
Sled,
}

View File

@@ -1,14 +0,0 @@
package org.bitcoindevkit.bdk
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class FfiException(val err: FfiError) : Exception() {
private val log: Logger = LoggerFactory.getLogger(FfiException::class.java)
init {
log.error("JnaError: [{}] {}",err.ordinal, err.name)
}
internal constructor(err: Short) : this(FfiError.values()[err.toInt()])
}

View File

@@ -1,9 +0,0 @@
package org.bitcoindevkit.bdk
import com.sun.jna.Native
abstract class LibBase {
protected val libJna: LibJna
get() = Native.load("bdk_ffi", LibJna::class.java)
}

View File

@@ -1,407 +0,0 @@
package org.bitcoindevkit.bdk
import com.sun.jna.*
interface LibJna : Library {
// typedef struct {
//
// char * ok;
//
// FfiError_t err;
//
//} FfiResult_char_ptr_t;
open class FfiResult_char_ptr_t : Structure() {
class ByValue : FfiResult_char_ptr_t(), Structure.ByValue
class ByReference : FfiResult_char_ptr_t(), Structure.ByReference
@JvmField
var ok: String? = null
@JvmField
var err: Short? = null
override fun getFieldOrder() = listOf("ok", "err")
}
// void free_string_result (
// FfiResult_char_ptr_t string_result);
fun free_string_result(string_result: FfiResult_char_ptr_t.ByValue)
// typedef struct {
//
// FfiError_t err;
//
//} FfiResultVoid_t;
open class FfiResultVoid_t : Structure() {
class ByValue : FfiResultVoid_t(), Structure.ByValue
class ByReference : FfiResultVoid_t(), Structure.ByReference
@JvmField
var err: Short? = null
override fun getFieldOrder() = listOf("err")
}
// void free_void_result (
// FfiResultVoid_t void_result);
fun free_void_result(void_result: FfiResultVoid_t.ByValue)
// void free_string (
// char * string);
fun free_string(string: Pointer?)
// typedef struct BlockchainConfig BlockchainConfig_t;
class BlockchainConfig_t : PointerType {
constructor() : super()
constructor(pointer: Pointer) : super(pointer)
}
// BlockchainConfig_t * new_electrum_config (
// char const * url,
// char const * socks5,
// int16_t retry,
// int16_t timeout,
// size_t stop_gap);
fun new_electrum_config(
url: String,
socks5: String?,
retry: Short,
timeout: Short,
stop_gap: Long,
): BlockchainConfig_t
// void free_blockchain_config (
// BlockchainConfig_t * blockchain_config);
fun free_blockchain_config(blockchain_config: BlockchainConfig_t)
// typedef struct DatabaseConfig DatabaseConfig_t;
class DatabaseConfig_t : PointerType {
constructor() : super()
constructor(pointer: Pointer) : super(pointer)
}
// typedef struct OpaqueWallet OpaqueWallet_t;
class OpaqueWallet_t : PointerType {
constructor() : super()
constructor(pointer: Pointer) : super(pointer)
}
// typedef struct {
//
// OpaqueWallet_t * ok;
//
// FfiError_t err;
//
// } FfiResult_OpaqueWallet_ptr_t;
open class FfiResult_OpaqueWallet_ptr_t : Structure() {
class ByValue : FfiResult_OpaqueWallet_ptr_t(), Structure.ByValue
class ByReference : FfiResult_OpaqueWallet_ptr_t(), Structure.ByReference
@JvmField
var ok: OpaqueWallet_t? = null
@JvmField
var err: Short? = null
override fun getFieldOrder() = listOf("ok", "err")
}
// FfiResult_OpaqueWallet_ptr_t new_wallet_result (
// char const * descriptor,
// char const * change_descriptor,
// char const * network,
// BlockchainConfig_t const * blockchain_config,
// DatabaseConfig_t const * database_config);
fun new_wallet_result(
descriptor: String,
changeDescriptor: String?,
network: String,
blockchainConfig: BlockchainConfig_t,
databaseConfig: DatabaseConfig_t,
): FfiResult_OpaqueWallet_ptr_t.ByValue
// void free_wallet_result (
// FfiResult_OpaqueWallet_ptr_t wallet_result);
fun free_wallet_result(wallet_result: FfiResult_OpaqueWallet_ptr_t.ByValue)
// typedef struct {
//
// char * txid;
//
// uint32_t vout;
//
// } OutPoint_t;
open class OutPoint_t : Structure() {
class ByValue : OutPoint_t(), Structure.ByValue
@JvmField
var txid: String? = null
@JvmField
var vout: Int? = null
override fun getFieldOrder() = listOf("txid", "vout")
}
// typedef struct {
//
// uint64_t value;
//
// char * script_pubkey;
//
// } TxOut_t;
open class TxOut_t : Structure() {
class ByValue : TxOut_t(), Structure.ByValue
@JvmField
var value: Long? = null
@JvmField
var script_pubkey: String? = null
override fun getFieldOrder() = listOf("value", "script_pubkey")
}
// typedef struct {
//
// OutPoint_t outpoint;
//
// TxOut_t txout;
//
// uint16_t keychain;
//
// } LocalUtxo_t;
open class LocalUtxo_t : Structure() {
class ByValue : LocalUtxo_t(), Structure.ByValue
class ByReference : LocalUtxo_t(), Structure.ByReference
@JvmField
var outpoint: OutPoint_t? = null
@JvmField
var txout: TxOut_t? = null
@JvmField
var keychain: Short? = null
override fun getFieldOrder() = listOf("outpoint", "txout", "keychain")
}
// typedef struct {
//
// LocalUtxo_t * ptr;
//
// size_t len;
//
// size_t cap;
//
// } Vec_LocalUtxo_t;
open class Vec_LocalUtxo_t : Structure() {
class ByReference : Vec_LocalUtxo_t(), Structure.ByReference
class ByValue : Vec_LocalUtxo_t(), Structure.ByValue
@JvmField
var ptr: LocalUtxo_t.ByReference? = null
@JvmField
var len: NativeLong? = null
@JvmField
var cap: NativeLong? = null
override fun getFieldOrder() = listOf("ptr", "len", "cap")
}
// typedef struct {
//
// Vec_LocalUtxo_t ok;
//
// FfiError_t err;
//
// } FfiResult_Vec_LocalUtxo_t;
open class FfiResultVec_LocalUtxo_t : Structure() {
class ByValue : FfiResultVec_LocalUtxo_t(), Structure.ByValue
class ByReference : FfiResultVec_LocalUtxo_t(), Structure.ByReference
@JvmField
var ok: Vec_LocalUtxo_t? = null
@JvmField
var err: Short? = null
override fun getFieldOrder() = listOf("ok", "err")
}
// void free_veclocalutxo_result (
// FfiResult_Vec_LocalUtxo_t unspent_result);
fun free_veclocalutxo_result(unspent_result: FfiResultVec_LocalUtxo_t.ByValue)
// typedef struct {
//
// uint64_t ok;
//
// FfiError_t err;
//
// } FfiResult_uint64_t;
open class FfiResult_uint64_t : Structure() {
class ByValue : FfiResult_uint64_t(), Structure.ByValue
class ByReference : FfiResult_uint64_t(), Structure.ByReference
@JvmField
var ok: Long? = null
@JvmField
var err: Short? = null
override fun getFieldOrder() = listOf("ok", "err")
}
// void free_uint64_result (
// FfiResult_uint64_t void_result);
fun free_uint64_result(unspent_result: FfiResult_uint64_t.ByValue)
// FfiResultVoid_t sync_wallet (
// OpaqueWallet_t const * opaque_wallet);
fun sync_wallet(opaque_wallet: OpaqueWallet_t): FfiResultVoid_t.ByValue
// FfiResult_char_ptr_t new_address (
// OpaqueWallet_t const * opaque_wallet);
fun new_address(opaque_wallet: OpaqueWallet_t): FfiResult_char_ptr_t.ByValue
// FfiResult_Vec_LocalUtxo_t list_unspent (
// OpaqueWallet_t const * opaque_wallet);
fun list_unspent(opaque_wallet: OpaqueWallet_t): FfiResultVec_LocalUtxo_t.ByValue
// FfiResult_uint64_t balance (
// OpaqueWallet_t const * opaque_wallet);
fun balance(opaque_wallet: OpaqueWallet_t): FfiResult_uint64_t.ByValue
// DatabaseConfig_t * new_memory_config (void);
fun new_memory_config(): DatabaseConfig_t
// DatabaseConfig_t * new_sled_config (
// char const * path,
// char const * tree_name);
fun new_sled_config(path: String, tree_name: String): DatabaseConfig_t
// void free_database_config (
// DatabaseConfig_t * database_config);
fun free_database_config(database_config: DatabaseConfig_t)
// typedef struct {
// uint32_t height;
// uint64_t timestamp;
// } ConfirmationTime_t;
open class ConfirmationTime_t : Structure() {
class ByValue : ConfirmationTime_t(), Structure.ByValue
class ByReference : ConfirmationTime_t(), Structure.ByReference
@JvmField
var height: Int? = null
@JvmField
var timestamp: Long? = null
override fun getFieldOrder() = listOf("height", "timestamp")
}
// typedef struct {
// char * txid;
// uint64_t received;
// uint64_t sent;
// int64_t fee;
// bool is_confirmed;
// ConfirmationTime_t confirmation_time;
// bool verified;
// } TransactionDetails_t;
open class TransactionDetails_t : Structure() {
class ByValue : TransactionDetails_t(), Structure.ByValue
class ByReference : TransactionDetails_t(), Structure.ByReference
@JvmField
var txid: String? = null
@JvmField
var received: Long? = null
@JvmField
var sent: Long? = null
@JvmField
var fee: Long? = null
@JvmField
var is_confirmed: Boolean? = null
@JvmField
var confirmation_time: ConfirmationTime_t? = null
@JvmField
var verified: Boolean? = null
override fun getFieldOrder() = listOf("txid", "received", "sent", "fee", "is_confirmed", "confirmation_time", "verified")
}
// typedef struct {
//
// TransactionDetails_t * ptr;
//
// size_t len;
//
// size_t cap;
//
// } Vec_TransactionDetails_t;
open class Vec_TransactionDetails_t : Structure() {
class ByReference : Vec_TransactionDetails_t(), Structure.ByReference
class ByValue : Vec_TransactionDetails_t(), Structure.ByValue
@JvmField
var ptr: TransactionDetails_t.ByReference? = null
@JvmField
var len: NativeLong? = null
@JvmField
var cap: NativeLong? = null
override fun getFieldOrder() = listOf("ptr", "len", "cap")
}
// typedef struct {
//
// Vec_TransactionDetails_t ok;
//
// FfiError_t err;
//
// } FfiResult_Vec_TransactionDetails_t;
open class FfiResult_Vec_TransactionDetails_t : Structure() {
class ByValue : FfiResult_Vec_TransactionDetails_t(), Structure.ByValue
class ByReference : FfiResult_Vec_TransactionDetails_t(), Structure.ByReference
@JvmField
var ok: Vec_TransactionDetails_t? = null
@JvmField
var err: Short? = null
override fun getFieldOrder() = listOf("ok", "err")
}
// FfiResult_Vec_TransactionDetails_t list_transactions (
// OpaqueWallet_t const * opaque_wallet);
fun list_transactions(opaque_wallet: OpaqueWallet_t): FfiResult_Vec_TransactionDetails_t.ByValue
// void free_vectxdetails_result (
// FfiResult_Vec_TransactionDetails_t txdetails_result);
fun free_vectxdetails_result(txdetails_result: FfiResult_Vec_TransactionDetails_t.ByValue)
}

View File

@@ -1,31 +0,0 @@
package org.bitcoindevkit.bdk.types
import org.bitcoindevkit.bdk.FfiException
import org.bitcoindevkit.bdk.LibBase
import org.bitcoindevkit.bdk.LibJna
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class StringResult constructor(private val ffiResultCharPtrT: LibJna.FfiResult_char_ptr_t.ByValue) :
LibBase() {
private val log: Logger = LoggerFactory.getLogger(StringResult::class.java)
fun value(): String {
val err = ffiResultCharPtrT.err!!
val ok = ffiResultCharPtrT.ok!!
when {
err > 0 -> {
throw FfiException(err)
}
else -> {
return ok
}
}
}
protected fun finalize() {
libJna.free_string_result(ffiResultCharPtrT)
log.debug("$ffiResultCharPtrT freed")
}
}

View File

@@ -1,31 +0,0 @@
package org.bitcoindevkit.bdk.types
import org.bitcoindevkit.bdk.FfiException
import org.bitcoindevkit.bdk.LibBase
import org.bitcoindevkit.bdk.LibJna
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class UInt64Result constructor(private val ffiResultUint64T: LibJna.FfiResult_uint64_t.ByValue) :
LibBase() {
private val log: Logger = LoggerFactory.getLogger(UInt64Result::class.java)
fun value(): Long {
val err = ffiResultUint64T.err!!
val ok = ffiResultUint64T.ok!!
when {
err > 0 -> {
throw FfiException(err)
}
else -> {
return ok
}
}
}
protected fun finalize() {
libJna.free_uint64_result(ffiResultUint64T)
log.debug("$ffiResultUint64T freed")
}
}

View File

@@ -1,31 +0,0 @@
package org.bitcoindevkit.bdk.types
import org.bitcoindevkit.bdk.FfiException
import org.bitcoindevkit.bdk.LibBase
import org.bitcoindevkit.bdk.LibJna
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class VoidResult constructor(private val ffiResultVoidT: LibJna.FfiResultVoid_t.ByValue) :
LibBase() {
private val log: Logger = LoggerFactory.getLogger(VoidResult::class.java)
fun value(): Unit {
val err = ffiResultVoidT.err!!
when {
err > 0 -> {
throw FfiException(err)
}
else -> {
return
}
}
}
protected fun finalize() {
libJna.free_void_result(ffiResultVoidT)
log.debug("$ffiResultVoidT freed")
}
}

View File

@@ -1,26 +0,0 @@
package org.bitcoindevkit.bdk
import org.slf4j.Logger
import org.slf4j.LoggerFactory
abstract class BlockchainConfig : LibBase() {
private val log: Logger = LoggerFactory.getLogger(BlockchainConfig::class.java)
abstract val blockchainConfigT: LibJna.BlockchainConfig_t
protected fun finalize() {
libJna.free_blockchain_config(blockchainConfigT)
log.debug("$blockchainConfigT freed")
}
}
class ElectrumConfig(
url: String,
socks5: String?,
retry: Short,
timeout: Short,
stopGap: Long,
) : BlockchainConfig() {
private val log: Logger = LoggerFactory.getLogger(ElectrumConfig::class.java)
override val blockchainConfigT = libJna.new_electrum_config(url, socks5, retry, timeout, stopGap)
}

View File

@@ -1,26 +0,0 @@
package org.bitcoindevkit.bdk
import org.slf4j.Logger
import org.slf4j.LoggerFactory
abstract class DatabaseConfig : LibBase() {
private val log: Logger = LoggerFactory.getLogger(DatabaseConfig::class.java)
abstract val databaseConfigT: LibJna.DatabaseConfig_t
protected fun finalize() {
libJna.free_database_config(databaseConfigT)
log.debug("$databaseConfigT freed")
}
}
class MemoryConfig : DatabaseConfig() {
private val log: Logger = LoggerFactory.getLogger(MemoryConfig::class.java)
override val databaseConfigT = libJna.new_memory_config()
}
class SledConfig(path: String, treeName: String) : DatabaseConfig() {
private val log: Logger = LoggerFactory.getLogger(SledConfig::class.java)
override val databaseConfigT = libJna.new_sled_config(path, treeName)
}

View File

@@ -1,32 +0,0 @@
package org.bitcoindevkit.bdk.wallet
import org.bitcoindevkit.bdk.FfiException
import org.bitcoindevkit.bdk.LibBase
import org.bitcoindevkit.bdk.LibJna
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class VecLocalUtxoResult(private val ffiResultVecLocalUtxoT: LibJna.FfiResultVec_LocalUtxo_t.ByValue) :
LibBase() {
private val log: Logger = LoggerFactory.getLogger(VecLocalUtxoResult::class.java)
fun value(): Array<LibJna.LocalUtxo_t.ByReference> {
val err = ffiResultVecLocalUtxoT.err!!
val ok = ffiResultVecLocalUtxoT.ok!!
when {
err > 0 -> {
throw FfiException(err)
}
else -> {
val first = ok.ptr!!
return first.toArray(ok.len!!.toInt()) as Array<LibJna.LocalUtxo_t.ByReference>
}
}
}
protected fun finalize() {
libJna.free_veclocalutxo_result(ffiResultVecLocalUtxoT)
log.debug("$ffiResultVecLocalUtxoT freed")
}
}

View File

@@ -1,32 +0,0 @@
package org.bitcoindevkit.bdk.wallet
import org.bitcoindevkit.bdk.FfiException
import org.bitcoindevkit.bdk.LibBase
import org.bitcoindevkit.bdk.LibJna
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class VecTxDetailsResult(private val ffiResultVecTransactionDetailsT: LibJna.FfiResult_Vec_TransactionDetails_t.ByValue) :
LibBase() {
private val log: Logger = LoggerFactory.getLogger(VecTxDetailsResult::class.java)
fun value(): Array<LibJna.TransactionDetails_t.ByReference> {
val err = ffiResultVecTransactionDetailsT.err!!
val ok = ffiResultVecTransactionDetailsT.ok!!
when {
err > 0 -> {
throw FfiException(err)
}
else -> {
val first = ok.ptr!!
return first.toArray(ok.len!!.toInt()) as Array<LibJna.TransactionDetails_t.ByReference>
}
}
}
protected fun finalize() {
libJna.free_vectxdetails_result(ffiResultVecTransactionDetailsT)
log.debug("$ffiResultVecTransactionDetailsT freed")
}
}

View File

@@ -1,65 +0,0 @@
package org.bitcoindevkit.bdk.wallet
import org.bitcoindevkit.bdk.BlockchainConfig
import org.bitcoindevkit.bdk.DatabaseConfig
import org.bitcoindevkit.bdk.LibBase
import org.bitcoindevkit.bdk.LibJna
import org.bitcoindevkit.bdk.types.StringResult
import org.bitcoindevkit.bdk.types.UInt64Result
import org.bitcoindevkit.bdk.types.VoidResult
import org.slf4j.Logger
import org.slf4j.LoggerFactory
enum class Network {
Bitcoin,
Testnet,
Signet,
Regtest,
}
class Wallet constructor(
descriptor: String,
changeDescriptor: String?,
network: Network,
blockchainConfig: BlockchainConfig,
databaseConfig: DatabaseConfig,
) : LibBase() {
val log: Logger = LoggerFactory.getLogger(Wallet::class.java)
private val walletResult = WalletResult(
libJna.new_wallet_result(
descriptor,
changeDescriptor,
network.toString().lowercase(),
blockchainConfig.blockchainConfigT,
databaseConfig.databaseConfigT
)
)
private val wallet = walletResult.value()
fun sync() {
val voidResult = VoidResult(libJna.sync_wallet(wallet))
return voidResult.value()
}
fun getAddress(): String {
val stringResult = StringResult(libJna.new_address(wallet))
return stringResult.value()
}
fun listUnspent(): Array<LibJna.LocalUtxo_t.ByReference> {
val vecLocalUtxoResult = VecLocalUtxoResult(libJna.list_unspent(wallet))
return vecLocalUtxoResult.value()
}
fun balance(): Long {
val longResult = UInt64Result(libJna.balance(wallet))
return longResult.value()
}
fun listTransactionDetails(): Array<LibJna.TransactionDetails_t.ByReference> {
val vecTxDetailsResult = VecTxDetailsResult(libJna.list_transactions((wallet)))
return vecTxDetailsResult.value()
}
}

View File

@@ -1,31 +0,0 @@
package org.bitcoindevkit.bdk.wallet
import org.bitcoindevkit.bdk.FfiException
import org.bitcoindevkit.bdk.LibBase
import org.bitcoindevkit.bdk.LibJna
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class WalletResult constructor(private val ffiResultOpaqueWalletPtrT: LibJna.FfiResult_OpaqueWallet_ptr_t.ByValue) :
LibBase() {
private val log: Logger = LoggerFactory.getLogger(WalletResult::class.java)
fun value(): LibJna.OpaqueWallet_t {
val err = ffiResultOpaqueWalletPtrT.err!!
val ok = ffiResultOpaqueWalletPtrT.ok
when {
err > 0 -> {
throw FfiException(err)
}
else -> {
return ok!!
}
}
}
protected fun finalize() {
libJna.free_wallet_result(ffiResultOpaqueWalletPtrT)
log.debug("$ffiResultOpaqueWalletPtrT freed")
}
}

View File

@@ -1,16 +0,0 @@
package org.bitcoindevkit.bdk
import java.nio.file.Paths
/**
* Library test, which will execute on linux host.
*
*/
class JvmLibTest : LibTest() {
override fun getTestDataDir(): String {
//return Files.createTempDirectory("bdk-test").toString()
return Paths.get(System.getProperty("java.io.tmpdir"), "bdk-test").toString()
}
}

View File

@@ -1,3 +0,0 @@
rootProject.name = 'bdk-kotlin'
include ':jvm', ':android', ':test-fixtures'

View File

@@ -1,19 +0,0 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
id 'java-library'
}
dependencies {
implementation platform('org.jetbrains.kotlin:kotlin-bom')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "net.java.dev.jna:jna:5.8.0"
implementation(project(':jvm'))
implementation "junit:junit:4.13.2"
//implementation "org.mockito.kotlin:mockito-kotlin:3.2.0"
api "org.slf4j:slf4j-api:1.7.30"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

View File

@@ -1,135 +0,0 @@
package org.bitcoindevkit.bdk
import org.bitcoindevkit.bdk.wallet.Network
import org.bitcoindevkit.bdk.wallet.Wallet
import org.junit.Assert.*
import org.junit.Test
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.File
/**
* Library tests which will execute for jvm and android modules.
*/
abstract class LibTest : LibBase() {
private val log: Logger = LoggerFactory.getLogger(LibTest::class.java)
val name = "test_wallet"
val desc =
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"
val change =
"wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"
val network = Network.Testnet
val blockchainConfig = ElectrumConfig("ssl://electrum.blockstream.info:60002", null, 5, 30, 100)
val databaseConfig = MemoryConfig()
abstract fun getTestDataDir(): String
fun cleanupTestDataDir() {
File(getTestDataDir()).deleteRecursively()
}
@Test
fun walletResultError() {
val jnaException = assertThrows(FfiException::class.java) {
Wallet("bad", "bad", network, blockchainConfig, databaseConfig)
}
assertEquals(jnaException.err, FfiError.Descriptor)
}
// @Test
// fun walletResultFinalize() {
// run {
// val desc =
// "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)"
// val change =
// "wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)"
//
// val blockchainConfig = ElectrumConfig("ssl://electrum.blockstream.info:60002", null, 5, 30)
// val databaseConfig = MemoryConfig()
// val wallet = Wallet(desc, change, blockchainConfig, databaseConfig)
// wallet.sync()
// assertNotNull(wallet.getAddress())
// }
// System.gc()
// Thread.sleep(2000)
// // The only way to verify wallets freed is by checking the log
// }
@Test
fun walletSync() {
val blockchainConfig = ElectrumConfig("ssl://electrum.blockstream.info:60002", null, 5, 30, 100)
val testDataDir = getTestDataDir()
// log.debug("testDataDir = $testDataDir")
val databaseConfig = SledConfig(testDataDir, "steve-test")
val wallet = Wallet(desc, change, network, blockchainConfig, databaseConfig)
wallet.sync()
cleanupTestDataDir()
}
@Test
fun walletNewAddress() {
val wallet = Wallet(desc, change, network, blockchainConfig, databaseConfig)
val address = wallet.getAddress()
assertNotNull(address)
// log.debug("address created from kotlin: $address")
assertEquals(address, "tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e")
}
@Test
fun walletUnspent() {
val wallet = Wallet(desc, change, network, blockchainConfig, databaseConfig)
wallet.sync()
val unspent = wallet.listUnspent()
assertTrue(unspent.isNotEmpty())
unspent.iterator().forEach {
//log.debug("unspent.outpoint.txid: ${it.outpoint!!.txid}")
assertNotNull(it.outpoint?.txid)
//log.debug("unspent.outpoint.vout: ${it.outpoint?.vout}")
assertTrue(it.outpoint?.vout!! >= 0)
//log.debug("unspent.txout.value: ${it.txout?.value}")
assertTrue(it.txout?.value!! > 0)
//log.debug("unspent.txout.script_pubkey: ${it.txout?.script_pubkey}")
assertNotNull(it.txout?.script_pubkey)
//log.debug("unspent.keychain: ${it.keychain}")
assertTrue(it.keychain!! >= 0)
}
}
@Test
fun walletBalance() {
val wallet = Wallet(desc, change, network, blockchainConfig, databaseConfig)
wallet.sync()
val balance = wallet.balance()
//log.debug("balance from kotlin: $balance")
assertTrue(balance > 0)
}
@Test
fun walletTxDetails() {
val wallet = Wallet(desc, change, network, blockchainConfig, databaseConfig)
wallet.sync()
val txDetails = wallet.listTransactionDetails()
assertTrue(txDetails.isNotEmpty())
txDetails.iterator().forEach {
//log.debug("txDetails.txid: ${it.txid}")
assertNotNull(it.txid)
//log.debug("txDetails.received: ${it.received}")
//log.debug("txDetails.sent: ${it.sent}")
assertTrue(it.received!! > 0 || it.sent!! > 0)
//log.debug("txDetails.fee: ${it.fee}")
assertTrue(it.fee!! > 0)
//log.debug("txDetails.is_confirmed: ${it.is_confirmed}")
assertTrue(it.is_confirmed!!)
assertNotNull(it.confirmation_time!!)
//log.debug("txDetails.confirmation_time.timestamp: ${it.confirmation_time!!.timestamp}")
assertTrue(it.confirmation_time!!.timestamp!! > 0)
//log.debug("txDetails.confirmation_time.height: ${it.confirmation_time!!.height}")
assertTrue(it.confirmation_time!!.height!! > 0)
}
}
}