Skip to content

Commit 4609fe1

Browse files
thunderbiscuitrustaceanrob
authored andcommitted
feat: add compact block filter client
temp 2 temp 3 temp 4 pass wallet to builder remove async builder make ip a type, bump bdk-kyoto, add connections add more configurations fix datadir builder bump kyoto add trait bound for logger update logger update bdk-ffi
1 parent 8cf23df commit 4609fe1

File tree

9 files changed

+171
-50
lines changed

9 files changed

+171
-50
lines changed

bdk-android/lib/src/androidTest/kotlin/org/bitcoindevkit/KyotoTest.kt

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.bitcoindevkit
2+
import org.rustbitcoin.bitcoin.Network
3+
4+
import kotlin.test.AfterTest
5+
import kotlin.test.assertNotNull
6+
7+
import java.nio.file.Files
8+
import java.nio.file.Paths
9+
import kotlin.io.path.ExperimentalPathApi
10+
import kotlin.io.path.deleteRecursively
11+
12+
import org.junit.Test
13+
import androidx.test.ext.junit.runners.AndroidJUnit4
14+
import kotlinx.coroutines.runBlocking
15+
import org.junit.runner.RunWith
16+
17+
@RunWith(AndroidJUnit4::class)
18+
class LiveKyotoTest {
19+
private val descriptor: Descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.SIGNET)
20+
private val changeDescriptor: Descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", Network.SIGNET)
21+
private val ip: IpAddress = IpAddress.fromIpv4(68u, 47u, 229u, 218u)
22+
private val peer: Peer = Peer(ip, null, false)
23+
private val currentPath = Paths.get(".").toAbsolutePath().normalize()
24+
private val persistenceFilePath = Files.createTempDirectory(currentPath, "tempDirPrefix_")
25+
26+
@OptIn(ExperimentalPathApi::class)
27+
@AfterTest
28+
fun cleanup() {
29+
persistenceFilePath.deleteRecursively()
30+
}
31+
32+
@Test
33+
fun testKyoto() {
34+
val conn: Connection = Connection.newInMemory()
35+
val wallet: Wallet = Wallet(descriptor, changeDescriptor, Network.SIGNET, conn)
36+
val peers = listOf(peer)
37+
runBlocking {
38+
val nodePair = buildLightClient(wallet, peers, 1u, null, persistenceFilePath.toString())
39+
val client = nodePair.client
40+
val node = nodePair.node
41+
println("Node running")
42+
runNode(node)
43+
val updateOpt: Update? = client.update(null)
44+
val update = assertNotNull(updateOpt)
45+
wallet.applyUpdate(update)
46+
assert(wallet.balance().total.toSat() > 0uL) {
47+
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address} and try again."
48+
}
49+
client.shutdown()
50+
println("Test completed successfully")
51+
}
52+
}
53+
}

bdk-ffi/src/bdk.udl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ interface LightClient {
667667
Update? update(NodeEventHandler? logger);
668668

669669
[Async, Throws=LightClientError]
670-
void broadcast(Transaction transaction);
670+
void broadcast([ByRef] Transaction transaction);
671671

672672
[Async, Throws=LightClientError]
673673
void watch_address(Address address);

bdk-ffi/src/bitcoin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl From<BdkAddress> for Address {
7777
}
7878

7979
#[derive(Debug, Clone, PartialEq, Eq)]
80-
pub struct Transaction(pub(crate) BdkTransaction);
80+
pub struct Transaction(BdkTransaction);
8181

8282
impl Transaction {
8383
pub fn new(transaction_bytes: Vec<u8>) -> Result<Self, TransactionError> {

bdk-ffi/src/kyoto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ impl LightClient {
109109
update.map(|update| Arc::new(Update(update.into())))
110110
}
111111

112-
pub async fn broadcast(&self, transaction: Arc<Transaction>) -> Result<(), LightClientError> {
112+
pub async fn broadcast(&self, transaction: &Transaction) -> Result<(), LightClientError> {
113113
let client = self.client.lock().await;
114-
let tx = transaction.0.clone();
114+
let tx = transaction.into();
115115
client
116116
.broadcast(tx, bdk_kyoto::TxBroadcastPolicy::RandomPeer)
117117
.await

bdk-jvm/lib/src/test/kotlin/org/bitcoindevkit/KyotoTest.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package org.bitcoindevkit
2+
import org.rustbitcoin.bitcoin.Network
3+
4+
import kotlinx.coroutines.runBlocking
5+
import kotlin.test.Test
6+
import kotlin.test.AfterTest
7+
import kotlin.test.assertNotNull
8+
9+
import java.nio.file.Files
10+
import java.nio.file.Paths
11+
import kotlin.io.path.ExperimentalPathApi
12+
import kotlin.io.path.deleteRecursively
13+
14+
class LiveKyotoTest {
15+
private val descriptor: Descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)", Network.SIGNET)
16+
private val changeDescriptor: Descriptor = Descriptor("wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)", Network.SIGNET)
17+
private val ip: IpAddress = IpAddress.fromIpv4(68u, 47u, 229u, 218u)
18+
private val peer: Peer = Peer(ip, null, false)
19+
private val currentPath = Paths.get(".").toAbsolutePath().normalize()
20+
private val persistenceFilePath = Files.createTempDirectory(currentPath, "tempDirPrefix_")
21+
22+
@OptIn(ExperimentalPathApi::class)
23+
@AfterTest
24+
fun cleanup() {
25+
persistenceFilePath.deleteRecursively()
26+
}
27+
28+
@Test
29+
fun testKyoto() {
30+
val conn: Connection = Connection.newInMemory()
31+
val wallet: Wallet = Wallet(descriptor, changeDescriptor, Network.SIGNET, conn)
32+
val peers = listOf(peer)
33+
runBlocking {
34+
val nodePair = buildLightClient(wallet, peers, 1u, null, persistenceFilePath.toString())
35+
val client = nodePair.client
36+
val node = nodePair.node
37+
println("Node running")
38+
runNode(node)
39+
val updateOpt: Update? = client.update(null)
40+
val update = assertNotNull(updateOpt)
41+
wallet.applyUpdate(update)
42+
assert(wallet.balance().total.toSat() > 0uL) {
43+
"Wallet balance must be greater than 0! Please send funds to ${wallet.revealNextAddress(KeychainKind.EXTERNAL).address} and try again."
44+
}
45+
client.shutdown()
46+
println("Test completed successfully")
47+
}
48+
}
49+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from bdkpython import *
2+
from bdkpython.bitcoin import *
3+
import unittest
4+
import os
5+
6+
network: Network = Network.SIGNET
7+
8+
ip: IpAddress = IpAddress.from_ipv4(68, 47, 229, 218)
9+
peer: Peer = Peer(address=ip, port=None, v2_transport=False)
10+
11+
descriptor: Descriptor = Descriptor(
12+
"wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/0/*)",
13+
network=network
14+
)
15+
change_descriptor: Descriptor = Descriptor(
16+
"wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)",
17+
network=network
18+
)
19+
20+
class LiveKyotoTest(unittest.IsolatedAsyncioTestCase):
21+
22+
def tearDown(self) -> None:
23+
if os.path.exists("./bdk_persistence.sqlite"):
24+
os.remove("./bdk_persistence.sqlite")
25+
if os.path.exists("./data/signet/headers.db"):
26+
os.remove("./data/signet/headers.db")
27+
if os.path.exists("./data/signet/peers.db"):
28+
os.remove("./data/signet/peers.db")
29+
30+
async def testKyoto(self) -> None:
31+
connection: Connection = Connection.new_in_memory()
32+
wallet: Wallet = Wallet(
33+
descriptor,
34+
change_descriptor,
35+
network,
36+
connection
37+
)
38+
peers = [peer]
39+
node_pair: NodePair = build_light_client(wallet, peers, 1, None, ".")
40+
client: LightClient = node_pair.client
41+
node: LightNode = node_pair.node
42+
run_node(node)
43+
update: Update = await client.update(None)
44+
self.assertIsNotNone(update, "Update is None. This should not be possible.")
45+
wallet.apply_update(update)
46+
self.assertGreater(
47+
wallet.balance().total.to_sat(),
48+
0,
49+
f"Wallet balance must be greater than 0! Please send funds to {wallet.reveal_next_address(KeychainKind.EXTERNAL).address} and try again."
50+
)
51+
await client.shutdown()
52+
53+
if __name__ == "__main__":
54+
unittest.main()

bdk-swift/Tests/BitcoinDevKitTests/LiveKyotoTests.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import XCTest
99
@testable import BitcoinDevKit
1010

11-
private let PEER = IpAddress.fromIpv4(q1: 68, q2: 47, q3: 229, q4: 218)
1211

1312
final class LiveKyotoTests: XCTestCase {
1413
private let descriptor = try! Descriptor(
@@ -19,6 +18,15 @@ final class LiveKyotoTests: XCTestCase {
1918
descriptor: "wpkh(tprv8ZgxMBicQKsPf2qfrEygW6fdYseJDDrVnDv26PH5BHdvSuG6ecCbHqLVof9yZcMoM31z9ur3tTYbSnr1WBqbGX97CbXcmp5H6qeMpyvx35B/84h/1h/0h/1/*)",
2019
network: Network.signet
2120
)
21+
private let peer = IpAddress.fromIpv4(q1: 68, q2: 47, q3: 229, q4: 218)
22+
private let cwd = FileManager.default.currentDirectoryPath.appending("/temp")
23+
24+
override func tearDownWithError() throws {
25+
let fileManager = FileManager.default
26+
if fileManager.fileExists(atPath: cwd) {
27+
try fileManager.removeItem(atPath: cwd)
28+
}
29+
}
2230

2331
func testSuccessfullySyncs() async throws {
2432
let connection = try Connection.newInMemory()
@@ -28,8 +36,8 @@ final class LiveKyotoTests: XCTestCase {
2836
network: Network.signet,
2937
connection: connection
3038
)
31-
let trusted_peer = Peer(address: PEER, port: nil, v2Transport: false)
32-
let nodePair = try! buildLightClient(wallet: wallet, peers: [trusted_peer], connections: 1, recoveryHeight: nil, dataDir: ".")
39+
let trusted_peer = Peer(address: peer, port: nil, v2Transport: false)
40+
let nodePair = try buildLightClient(wallet: wallet, peers: [trusted_peer], connections: 1, recoveryHeight: nil, dataDir: cwd)
3341
let client = nodePair.client
3442
let node = nodePair.node
3543
runNode(node: node)

0 commit comments

Comments
 (0)