Skip to content

Commit

Permalink
feat: upgrade bdk to 1.0.0-alpha.2
Browse files Browse the repository at this point in the history
This is a big change that updates some of our build infrastructure
as well as upgrading the bdk dependency. It adds the simple
new_no_persist constructor on the wallet as well as the blocking
esplora client.
  • Loading branch information
thunderbiscuit committed Oct 23, 2023
1 parent 743862f commit 790aee9
Show file tree
Hide file tree
Showing 27 changed files with 2,021 additions and 2,761 deletions.
14 changes: 10 additions & 4 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ jobs:
security_audit:
name: Security audit
runs-on: ubuntu-20.04
defaults:
run:
working-directory: bdk-ffi
steps:
- uses: actions/checkout@v3
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Check out PR branch"
uses: actions/checkout@v3

- name: "Run audit"
run: |
cargo install cargo-audit
cargo-audit audit
51 changes: 29 additions & 22 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,26 @@ on:

jobs:
build-test:
name: Build and test
name: "Build and test"
runs-on: ubuntu-20.04
defaults:
run:
working-directory: bdk-ffi
strategy:
matrix:
rust:
- version: 1.71.0 # STABLE
- version: 1.67.0
clippy: true
- version: 1.61.0 # MSRV
# TODO 1: Should we keep this? We'll need to pin dependencies
# - version: 1.61.0 # MSRV
steps:
- name: Checkout
- name: "Checkout"
uses: actions/checkout@v3

- name: Generate cache key
- name: "Generate cache key"
run: echo "${{ matrix.rust.version }} ${{ matrix.features }}" | tee .cache_key

- name: Cache
- name: "Cache"
uses: actions/cache@v3
with:
path: |
Expand All @@ -33,53 +37,56 @@ jobs:
target
key: ${{ runner.os }}-cargo-${{ hashFiles('.cache_key') }}-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}

- name: Set default toolchain
- name: "Set default toolchain"
run: rustup default ${{ matrix.rust.version }}

- name: Set profile
- name: "Set profile"
run: rustup set profile minimal

- name: Add clippy
- name: "Add clippy"
if: ${{ matrix.rust.clippy }}
run: rustup component add clippy

- name: Update toolchain
- name: "Update toolchain"
run: rustup update

- name: Pin dependencies for MSRV
- name: "Pin dependencies for MSRV"
if: matrix.rust.version == '1.61.0'
run: |
cargo update -p hashlink --precise "0.8.1"
cargo update -p tokio --precise "1.29.1"
cargo update -p flate2 --precise "1.0.26"
- name: Build
- name: "Build"
run: cargo build

- name: Clippy
- name: "Clippy"
if: ${{ matrix.rust.clippy }}
run: cargo clippy --all-targets --features "uniffi/bindgen-tests" -- -D warnings

- name: Test
- name: "Test"
run: CLASSPATH=./tests/jna/jna-5.8.0.jar cargo test --features uniffi/bindgen-tests

fmt:
name: Rust fmt
runs-on: ubuntu-latest
name: "Rust fmt"
runs-on: ubuntu-20.04
defaults:
run:
working-directory: bdk-ffi
steps:
- name: Checkout
- name: "Checkout"
uses: actions/checkout@v3

- name: Set default toolchain
- name: "Set default toolchain"
run: rustup default nightly

- name: Set profile
- name: "Set profile"
run: rustup set profile minimal

- name: Add rustfmt
- name: "Add rustfmt"
run: rustup component add rustfmt

- name: Update toolchain
- name: "Update toolchain"
run: rustup update

- name: Check fmt
- name: "Check fmt"
run: cargo fmt --all -- --config format_code_in_doc_comments=true --check
1 change: 1 addition & 0 deletions .github/workflows/publish-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
uses: actions/checkout@v3
with:
submodules: true
# TODO 2: Other CI workflows use explicit Rust compiler versions, I think we should do the same here
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand Down
39 changes: 5 additions & 34 deletions .github/workflows/test-swift.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,15 @@ on:

jobs:
build:
name: "Build and test"
runs-on: macos-12
steps:
- name: Checkout
- name: "Checkout"
uses: actions/checkout@v3

- name: "Set default Rust version to 1.67.0"
run: rustup default 1.67.0
- name: "Build Swift package"
run: bash ./bdk-swift/build-local-swift.sh

- name: Install Rust targets
run: |
rustup install nightly-x86_64-apple-darwin
rustup component add rust-src --toolchain nightly-x86_64-apple-darwin
rustup target add aarch64-apple-darwin x86_64-apple-darwin
- name: Run bdk-ffi-bindgen
working-directory: bdk-ffi
run: cargo run --bin uniffi-bindgen generate src/bdk.udl --language swift --out-dir ../bdk-swift/Sources/BitcoinDevKit --no-format

- name: Build bdk-ffi for x86_64-apple-darwin
run: cargo build --package bdk-ffi --profile release-smaller --target x86_64-apple-darwin

- name: Build bdk-ffi for aarch64-apple-darwin
run: cargo build --package bdk-ffi --profile release-smaller --target aarch64-apple-darwin

- name: Create lipo-macos
run: |
mkdir -p target/lipo-macos/release-smaller
lipo target/aarch64-apple-darwin/release-smaller/libbdkffi.a target/x86_64-apple-darwin/release-smaller/libbdkffi.a -create -output target/lipo-macos/release-smaller/libbdkffi.a
- name: Create bdkFFI.xcframework
working-directory: bdk-swift
run: |
mv Sources/BitcoinDevKit/bdk.swift Sources/BitcoinDevKit/BitcoinDevKit.swift
cp Sources/BitcoinDevKit/bdkFFI.h bdkFFI.xcframework/macos-arm64_x86_64/bdkFFI.framework/Headers
cp ../target/lipo-macos/release-smaller/libbdkffi.a bdkFFI.xcframework/macos-arm64_x86_64/bdkFFI.framework/bdkFFI
rm Sources/BitcoinDevKit/bdkFFI.h
rm Sources/BitcoinDevkit/bdkFFI.modulemap
- name: Run Swift tests
- name: "Run Swift tests"
working-directory: bdk-swift
run: swift test
12 changes: 0 additions & 12 deletions Cargo.toml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,42 @@ import java.io.File
*/
@RunWith(AndroidJUnit4::class)
class AndroidLibTest {

private fun getTestDataDir(): String {
val context = ApplicationProvider.getApplicationContext<Application>()
return context.getDir("bdk-test", MODE_PRIVATE).toString()
}

private fun cleanupTestDataDir(testDataDir: String) {
File(testDataDir).deleteRecursively()
}

class LogProgress : Progress {
private val log: Logger = LoggerFactory.getLogger(AndroidLibTest::class.java)

override fun update(progress: Float, message: String?) {
log.debug("Syncing...")
}
@Test
fun testNetwork() {
val signetNetwork = Network.SIGNET
}

private val descriptor = Descriptor("wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)", Network.TESTNET)

private val databaseConfig = DatabaseConfig.Memory

private val blockchainConfig = BlockchainConfig.Electrum(
ElectrumConfig(
"ssl://electrum.blockstream.info:60002",
null,
5u,
null,
100u,
true,
)
)

@Test
fun memoryWalletNewAddress() {
val wallet = Wallet(descriptor, null, Network.TESTNET, databaseConfig)
val address = wallet.getAddress(AddressIndex.New).address.asString()
assertEquals("tb1qzg4mckdh50nwdm9hkzq06528rsu73hjxxzem3e", address)
fun testDescriptorBip86() {
val mnemonic = Mnemonic(WordCount.WORDS12)
val descriptorSecretKey = DescriptorSecretKey(Network.TESTNET, mnemonic, null)
val descriptor = Descriptor.newBip86(descriptorSecretKey, KeychainKind.EXTERNAL, Network.TESTNET)
}

@Test
fun memoryWalletSyncGetBalance() {
val wallet = Wallet(descriptor, null, Network.TESTNET, databaseConfig)
val blockchain = Blockchain(blockchainConfig)
wallet.sync(blockchain, LogProgress())
val balance: Balance = wallet.getBalance()
assertTrue(balance.total > 0u)
fun testUsedWallet() {
val descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET)
val wallet = Wallet.newNoPersist(descriptor, null, Network.TESTNET)
val (index, address, keychain) = wallet.getAddress(AddressIndex.LastUnused)
println("Address ${address.asString()} at index $index")
}

@Test
fun sqliteWalletSyncGetBalance() {
val testDataDir = getTestDataDir() + "/bdk-wallet.sqlite"
val databaseConfig = DatabaseConfig.Sqlite(SqliteDbConfiguration(testDataDir))
val wallet = Wallet(descriptor, null, Network.TESTNET, databaseConfig)
val blockchain = Blockchain(blockchainConfig)
wallet.sync(blockchain, LogProgress())
val balance: Balance = wallet.getBalance()
assertTrue(balance.total > 0u)
cleanupTestDataDir(testDataDir)
fun testBalance() {
val descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET)
val wallet = Wallet.newNoPersist(descriptor, null, Network.TESTNET)

assert(wallet.getBalance().total() == 0uL)
}

// @Test
// fun testSyncedBalance() {
// val descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.TESTNET)
// val wallet = Wallet.newNoPersist(descriptor, null, Network.TESTNET)
// val esploraClient = EsploraClient("https://mempool.space/testnet/api")
// // val esploraClient = EsploraClient("https://blockstream.info/testnet/api")
// val update = esploraClient.scan(wallet, 10uL, 1uL)
// wallet.applyUpdate(update)
// println("Balance: ${wallet.getBalance().total()}")
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ internal class UniFfiAndroidPlugin : Plugin<Project> {
into("${project.projectDir}/../lib/src/main/jniLibs/")

into("arm64-v8a") {
from("${project.projectDir}/../../target/aarch64-linux-android/release-smaller/libbdkffi.so")
from("${project.projectDir}/../../bdk-ffi/target/aarch64-linux-android/release-smaller/libbdkffi.so")
}

into("x86_64") {
from("${project.projectDir}/../../target/x86_64-linux-android/release-smaller/libbdkffi.so")
from("${project.projectDir}/../../bdk-ffi/target/x86_64-linux-android/release-smaller/libbdkffi.so")
}

into("armeabi-v7a") {
from("${project.projectDir}/../../target/armv7-linux-androideabi/release-smaller/libbdkffi.so")
from("${project.projectDir}/../../bdk-ffi/target/armv7-linux-androideabi/release-smaller/libbdkffi.so")
}

doLast {
Expand All @@ -137,6 +137,12 @@ internal class UniFfiAndroidPlugin : Plugin<Project> {
val generateAndroidBindings by tasks.register<Exec>("generateAndroidBindings") {
dependsOn(moveNativeAndroidLibs)

// val libraryPath = "${project.projectDir}/../../bdk-ffi/target/aarch64-linux-android/release-smaller/libbdkffi.so"
// workingDir("${project.projectDir}/../../bdk-ffi")
// val cargoArgs: List<String> = listOf("run", "--bin", "uniffi-bindgen", "generate", "--library", libraryPath, "--language", "kotlin", "--out-dir", "../bdk-android/lib/src/main/kotlin", "--no-format")

// The code above worked for uniffi 0.24.3 using the --library flag
// The code below works for uniffi 0.23.0
workingDir("${project.projectDir}/../../bdk-ffi")
val cargoArgs: List<String> = listOf("run", "--bin", "uniffi-bindgen", "generate", "src/bdk.udl", "--language", "kotlin", "--out-dir", "../bdk-android/lib/src/main/kotlin", "--no-format")

Expand Down
Loading

0 comments on commit 790aee9

Please sign in to comment.