Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Variant-Kyoto/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ dependencies {
implementation("androidx.appcompat:appcompat:1.7.0")

// Bitcoin Development Kit
implementation("org.bitcoindevkit:bdk-android:1.2.0")
implementation("org.bitcoindevkit:bdk-android:2.1.0-SNAPSHOT")

// QR codes
implementation("com.google.zxing:core:3.5.3")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import kotlinx.coroutines.runBlocking
import org.bitcoindevkit.Address
import org.bitcoindevkit.AddressInfo
import org.bitcoindevkit.Amount
import org.bitcoindevkit.BlockId
import org.bitcoindevkit.CanonicalTx
import org.bitcoindevkit.ChainPosition
import org.bitcoindevkit.Connection
import org.bitcoindevkit.Descriptor
import org.bitcoindevkit.DescriptorSecretKey
import org.bitcoindevkit.FeeRate
Expand All @@ -39,6 +39,7 @@ import org.bitcoindevkit.devkitwallet.domain.utils.intoDomain
import org.bitcoindevkit.devkitwallet.domain.utils.intoProto
import org.bitcoindevkit.devkitwallet.presentation.viewmodels.mvi.Recipient
import org.bitcoindevkit.CbfClient
import org.bitcoindevkit.Persister
import java.util.UUID
import org.bitcoindevkit.Wallet as BdkWallet

Expand All @@ -47,7 +48,7 @@ private const val TAG = "Wallet"
class Wallet private constructor(
private val wallet: BdkWallet,
private val walletSecrets: WalletSecrets,
private val connection: Connection,
private val connection: Persister,
private var fullScanCompleted: Boolean,
private val walletId: String,
private val userPreferencesRepository: UserPreferencesRepository,
Expand Down Expand Up @@ -117,7 +118,7 @@ class Wallet private constructor(
fun broadcast(signedPsbt: Psbt): String {
currentBlockchainClient?.broadcast(signedPsbt.extractTx())
?: throw IllegalStateException("Blockchain client not initialized")
return signedPsbt.extractTx().computeTxid()
return signedPsbt.extractTx().computeTxid().toString()
}

private fun getAllTransactions(): List<CanonicalTx> = wallet.transactions()
Expand Down Expand Up @@ -153,7 +154,7 @@ class Wallet private constructor(
}
TxDetails(
tx.transaction,
txid,
txid.toString(),
sent.toSat(),
received.toSat(),
fee?.toSat() ?: 0uL,
Expand All @@ -179,6 +180,8 @@ class Wallet private constructor(

fun getNewAddress(): AddressInfo = wallet.revealNextAddress(KeychainKind.EXTERNAL)

fun getLastCheckpoint(): BlockId = wallet.latestCheckpoint();

fun startKyotoNode() {
Log.i(TAG, "Starting Kyoto node")
// val ip: IpAddress = IpAddress.fromIpv4(68u, 47u, 229u, 218u) // Signet
Expand All @@ -192,7 +195,7 @@ class Wallet private constructor(
.dataDir(this.internalAppFilesPath)
.peers(peers)
.connections(1u)
.scanType(ScanType.New)
.scanType(ScanType.Sync)
.build(this.wallet)

node.run()
Expand Down Expand Up @@ -232,7 +235,7 @@ class Wallet private constructor(
KeychainKind.INTERNAL,
)
val walletId = UUID.randomUUID().toString()
val connection = Connection("$internalAppFilesPath/wallet-${walletId.take(8)}.sqlite3")
val connection = Persister.newSqlite("$internalAppFilesPath/wallet-${walletId.take(8)}.sqlite3")

// Create SingleWallet object for saving to datastore
val newWalletForDatastore: SingleWallet =
Expand All @@ -256,7 +259,7 @@ class Wallet private constructor(
descriptor = descriptor,
changeDescriptor = changeDescriptor,
network = newWalletConfig.network,
connection = connection,
persister = connection,
)

val walletSecrets = WalletSecrets(descriptor, changeDescriptor, mnemonic.toString())
Expand All @@ -280,12 +283,12 @@ class Wallet private constructor(
): Wallet {
val descriptor = Descriptor(activeWallet.descriptor, activeWallet.network.intoDomain())
val changeDescriptor = Descriptor(activeWallet.changeDescriptor, activeWallet.network.intoDomain())
val connection = Connection("$internalAppFilesPath/wallet-${activeWallet.id.take(8)}.sqlite3")
val connection = Persister.newSqlite("$internalAppFilesPath/wallet-${activeWallet.id.take(8)}.sqlite3")
val bdkWallet =
BdkWallet.load(
descriptor = descriptor,
changeDescriptor = changeDescriptor,
connection = connection,
persister = connection,
)

val walletSecrets = WalletSecrets(descriptor, changeDescriptor, activeWallet.recoveryPhrase)
Expand Down Expand Up @@ -337,7 +340,7 @@ class Wallet private constructor(
changeDescriptor = recoverWalletConfig.changeDescriptor
}
val walletId = UUID.randomUUID().toString()
val connection = Connection("$internalAppFilesPath/wallet-${walletId.take(8)}.sqlite3")
val connection = Persister.newSqlite("$internalAppFilesPath/wallet-${walletId.take(8)}.sqlite3")

// Create SingleWallet object for saving to datastore
val newWalletForDatastore: SingleWallet =
Expand All @@ -360,7 +363,7 @@ class Wallet private constructor(
BdkWallet(
descriptor = descriptor,
changeDescriptor = changeDescriptor,
connection = connection,
persister = connection,
network = recoverWalletConfig.network,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,9 @@ internal class WalletViewModel(

kyotoCoroutineScope.launch {
while (wallet.kyotoClient != null) {
val nextLog: org.bitcoindevkit.Log = wallet.kyotoClient!!.nextLog()
Log.i("Kyoto", "LOG: $nextLog")
val logString = nextLog.toString()
if (logString.contains("Compact Filter Headers")) {
val regex = Regex("""\d+/\d+""")

val lastNumber = regex.findAll(logString)
.lastOrNull()
?.value
?.split("/")
?.getOrNull(1)
?.toIntOrNull()
val nextInfo = wallet.kyotoClient!!.nextInfo()
Log.i("Kyoto", "LOG: $nextInfo")
val lastNumber = wallet.getLastCheckpoint().height.toInt()

if (lastNumber != null) {
if (lastNumber > latestBlock) {
Expand All @@ -124,7 +115,6 @@ internal class WalletViewModel(
showSnackbar("New block mined! $latestBlock \uD83C\uDF89\uD83C\uDF89")
}
}
}
}
}

Expand Down
Loading