Skip to content

Commit 576c574

Browse files
build: apply first ktlint format
1 parent 8c7401c commit 576c574

40 files changed

+979
-639
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Root .editorconfig file
2+
root = true
3+
4+
[*.{kt,kts}]
5+
indent_style = space
6+
max_line_length = 120
7+
8+
ktlint_standard_trailing-comma-on-call-site = disabled
9+
ktlint_standard_multiline-expression-wrapping = disabled
10+
ktlint_standard_string-template-indent = disabled
11+
ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than = 5
12+
ktlint_function_naming_ignore_when_annotated_with=Composable

app/src/main/java/org/bitcoindevkit/devkitwallet/domain/BlockchainClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ package org.bitcoindevkit.devkitwallet.domain
88
import org.bitcoindevkit.FullScanRequest
99
import org.bitcoindevkit.SyncRequest
1010
import org.bitcoindevkit.Transaction
11-
import org.bitcoindevkit.EsploraClient as BdkEsploraClient
1211
import org.bitcoindevkit.Update
12+
import org.bitcoindevkit.EsploraClient as BdkEsploraClient
1313

1414
interface BlockchainClient {
1515
fun clientId(): String

app/src/main/java/org/bitcoindevkit/devkitwallet/domain/BlockchainClientsConfig.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ class BlockchainClientsConfig {
1717

1818
fun addClient(client: BlockchainClient, setDefault: Boolean) {
1919
allClients.forEach {
20-
if (it.clientId() == client.clientId()) throw IllegalArgumentException("Client with url ${client.clientId()} already exists")
20+
if (it.clientId() == client.clientId()) {
21+
throw IllegalArgumentException(
22+
"Client with url ${client.clientId()} already exists"
23+
)
24+
}
2125
}
2226
if (allClients.size >= 8) throw IllegalArgumentException("Maximum number of clients (8) reached")
2327
allClients.add(client)

app/src/main/java/org/bitcoindevkit/devkitwallet/domain/CurrencyUnit.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ package org.bitcoindevkit.devkitwallet.domain
77

88
enum class CurrencyUnit {
99
Bitcoin,
10-
Satoshi
10+
Satoshi,
1111
}

app/src/main/java/org/bitcoindevkit/devkitwallet/domain/DwLogger.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright 2021-2025 thunderbiscuit and contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the ./LICENSE file.
4+
*/
5+
16
package org.bitcoindevkit.devkitwallet.domain
27

38
object DwLogger {
File renamed without changes.

app/src/main/java/org/bitcoindevkit/devkitwallet/domain/Wallet.kt

Lines changed: 117 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,14 @@ import android.util.Log
99
import kotlinx.coroutines.runBlocking
1010
import org.bitcoindevkit.Address
1111
import org.bitcoindevkit.AddressInfo
12-
import org.rustbitcoin.bitcoin.Amount
1312
import org.bitcoindevkit.CanonicalTx
1413
import org.bitcoindevkit.ChainPosition
1514
import org.bitcoindevkit.Connection
1615
import org.bitcoindevkit.Descriptor
1716
import org.bitcoindevkit.DescriptorSecretKey
18-
import org.rustbitcoin.bitcoin.FeeRate
1917
import org.bitcoindevkit.KeychainKind
2018
import org.bitcoindevkit.Mnemonic
21-
import org.rustbitcoin.bitcoin.Network
2219
import org.bitcoindevkit.Psbt
23-
import org.rustbitcoin.bitcoin.Script
2420
import org.bitcoindevkit.TxBuilder
2521
import org.bitcoindevkit.Update
2622
import org.bitcoindevkit.WordCount
@@ -34,8 +30,12 @@ import org.bitcoindevkit.devkitwallet.data.TxDetails
3430
import org.bitcoindevkit.devkitwallet.domain.utils.intoDomain
3531
import org.bitcoindevkit.devkitwallet.domain.utils.intoProto
3632
import org.bitcoindevkit.devkitwallet.presentation.viewmodels.mvi.Recipient
37-
import org.bitcoindevkit.Wallet as BdkWallet
33+
import org.rustbitcoin.bitcoin.Amount
34+
import org.rustbitcoin.bitcoin.FeeRate
35+
import org.rustbitcoin.bitcoin.Network
36+
import org.rustbitcoin.bitcoin.Script
3837
import java.util.UUID
38+
import org.bitcoindevkit.Wallet as BdkWallet
3939

4040
private const val TAG = "Wallet"
4141

@@ -46,19 +46,15 @@ class Wallet private constructor(
4646
private var fullScanCompleted: Boolean,
4747
private val walletId: String,
4848
private val userPreferencesRepository: UserPreferencesRepository,
49-
blockchainClientsConfig: BlockchainClientsConfig
49+
blockchainClientsConfig: BlockchainClientsConfig,
5050
) {
5151
private var currentBlockchainClient: BlockchainClient? = blockchainClientsConfig.getClient()
5252

5353
fun getRecoveryPhrase(): List<String> {
5454
return recoveryPhrase.split(" ")
5555
}
5656

57-
fun createTransaction(
58-
recipientList: List<Recipient>,
59-
feeRate: FeeRate,
60-
opReturnMsg: String?
61-
): Psbt {
57+
fun createTransaction(recipientList: List<Recipient>, feeRate: FeeRate, opReturnMsg: String?): Psbt {
6258
// technique 1 for adding a list of recipients to the TxBuilder
6359
// var txBuilder = TxBuilder()
6460
// for (recipient in recipientList) {
@@ -67,11 +63,12 @@ class Wallet private constructor(
6763
// txBuilder = txBuilder.feeRate(satPerVbyte = fee_rate)
6864

6965
// technique 2 for adding a list of recipients to the TxBuilder
70-
var txBuilder = recipientList.fold(TxBuilder()) { builder, recipient ->
71-
// val address = Address(recipient.address)
72-
val scriptPubKey: Script = Address(recipient.address, Network.TESTNET).scriptPubkey()
73-
builder.addRecipient(scriptPubKey, Amount.fromSat(recipient.amount))
74-
}
66+
var txBuilder =
67+
recipientList.fold(TxBuilder()) { builder, recipient ->
68+
// val address = Address(recipient.address)
69+
val scriptPubKey: Script = Address(recipient.address, Network.TESTNET).scriptPubkey()
70+
builder.addRecipient(scriptPubKey, Amount.fromSat(recipient.amount))
71+
}
7572
// if (!opReturnMsg.isNullOrEmpty()) {
7673
// txBuilder = txBuilder.addData(opReturnMsg.toByteArray(charset = Charsets.UTF_8).asUByteArray().toList())
7774
// }
@@ -111,11 +108,13 @@ class Wallet private constructor(
111108
}
112109

113110
fun broadcast(signedPsbt: Psbt): String {
114-
currentBlockchainClient?.broadcast(signedPsbt.extractTx()) ?: throw IllegalStateException("Blockchain client not initialized")
111+
currentBlockchainClient?.broadcast(signedPsbt.extractTx()) ?: throw IllegalStateException(
112+
"Blockchain client not initialized"
113+
)
115114
return signedPsbt.extractTx().computeTxid()
116115
}
117116

118-
private fun getAllTransactions(): List<CanonicalTx> = wallet.transactions()
117+
private fun getAllTransactions(): List<CanonicalTx> = wallet.transactions()
119118

120119
fun getAllTxDetails(): List<TxDetails> {
121120
val transactions = getAllTransactions()
@@ -136,11 +135,27 @@ class Wallet private constructor(
136135
Log.e(TAG, "Error calculating fee for tx $txid: $e")
137136
}
138137

139-
val (confirmationBlock, confirmationTimestamp, pending) = when (val position = tx.chainPosition) {
140-
is ChainPosition.Unconfirmed -> Triple(null, null, true)
141-
is ChainPosition.Confirmed -> Triple(ConfirmationBlock(position.confirmationBlockTime.blockId.height), Timestamp(position.confirmationBlockTime.confirmationTime), false)
142-
}
143-
TxDetails(tx.transaction, txid, sent.toSat(), received.toSat(), fee?.toSat() ?: 0uL, feeRate, pending, confirmationBlock, confirmationTimestamp)
138+
val (confirmationBlock, confirmationTimestamp, pending) =
139+
when (val position = tx.chainPosition) {
140+
is ChainPosition.Unconfirmed -> Triple(null, null, true)
141+
is ChainPosition.Confirmed ->
142+
Triple(
143+
ConfirmationBlock(position.confirmationBlockTime.blockId.height),
144+
Timestamp(position.confirmationBlockTime.confirmationTime),
145+
false
146+
)
147+
}
148+
TxDetails(
149+
tx.transaction,
150+
txid,
151+
sent.toSat(),
152+
received.toSat(),
153+
fee?.toSat() ?: 0uL,
154+
feeRate,
155+
pending,
156+
confirmationBlock,
157+
confirmationTimestamp
158+
)
144159
}
145160
}
146161

@@ -156,10 +171,11 @@ class Wallet private constructor(
156171

157172
private fun fullScan() {
158173
val fullScanRequest = wallet.startFullScan().build()
159-
val update: Update = currentBlockchainClient?.fullScan(
160-
fullScanRequest = fullScanRequest,
161-
stopGap = 20u,
162-
) ?: throw IllegalStateException("Blockchain client not initialized")
174+
val update: Update =
175+
currentBlockchainClient?.fullScan(
176+
fullScanRequest = fullScanRequest,
177+
stopGap = 20u,
178+
) ?: throw IllegalStateException("Blockchain client not initialized")
163179
wallet.applyUpdate(update)
164180
wallet.persist(connection)
165181
}
@@ -175,9 +191,10 @@ class Wallet private constructor(
175191
} else {
176192
Log.i(TAG, "Just a normal sync!")
177193
val syncRequest = wallet.startSyncWithRevealedSpks().build()
178-
val update = currentBlockchainClient?.sync(
179-
syncRequest = syncRequest,
180-
) ?: throw IllegalStateException("Blockchain client not initialized")
194+
val update =
195+
currentBlockchainClient?.sync(
196+
syncRequest = syncRequest,
197+
) ?: throw IllegalStateException("Blockchain client not initialized")
181198
wallet.applyUpdate(update)
182199
wallet.persist(connection)
183200
}
@@ -188,7 +205,7 @@ class Wallet private constructor(
188205
fun getNewAddress(): AddressInfo = wallet.revealNextAddress(KeychainKind.EXTERNAL)
189206

190207
fun getClientEndpoint(): String = currentBlockchainClient?.endpoint() ?: "No active client"
191-
208+
192209
// fun setElectrumSettings(electrumSettings: ElectrumSettings) {
193210
// when (electrumSettings) {
194211
// ElectrumSettings.DEFAULT -> electrumServer.useDefaultElectrum()
@@ -204,42 +221,46 @@ class Wallet private constructor(
204221
): Wallet {
205222
val mnemonic = Mnemonic(WordCount.WORDS12)
206223
val bip32ExtendedRootKey = DescriptorSecretKey(newWalletConfig.network, mnemonic, null)
207-
val descriptor: Descriptor = createScriptAppropriateDescriptor(
208-
newWalletConfig.scriptType,
209-
bip32ExtendedRootKey,
210-
newWalletConfig.network,
211-
KeychainKind.EXTERNAL
212-
)
213-
val changeDescriptor: Descriptor = createScriptAppropriateDescriptor(
214-
newWalletConfig.scriptType,
215-
bip32ExtendedRootKey,
216-
newWalletConfig.network,
217-
KeychainKind.INTERNAL
218-
)
224+
val descriptor: Descriptor =
225+
createScriptAppropriateDescriptor(
226+
newWalletConfig.scriptType,
227+
bip32ExtendedRootKey,
228+
newWalletConfig.network,
229+
KeychainKind.EXTERNAL
230+
)
231+
val changeDescriptor: Descriptor =
232+
createScriptAppropriateDescriptor(
233+
newWalletConfig.scriptType,
234+
bip32ExtendedRootKey,
235+
newWalletConfig.network,
236+
KeychainKind.INTERNAL
237+
)
219238
val walletId = UUID.randomUUID().toString()
220239
val connection = Connection("$internalAppFilesPath/wallet-${walletId.take(8)}.sqlite3",)
221240

222241
// Create SingleWallet object for saving to datastore
223-
val newWalletForDatastore: SingleWallet = SingleWallet.newBuilder()
224-
.setId(walletId)
225-
.setName(newWalletConfig.name)
226-
.setNetwork(newWalletConfig.network.intoProto())
227-
.setScriptType(newWalletConfig.scriptType)
228-
.setDescriptor(descriptor.toStringWithSecret())
229-
.setChangeDescriptor(changeDescriptor.toStringWithSecret())
230-
.setRecoveryPhrase(mnemonic.toString())
231-
.build()
242+
val newWalletForDatastore: SingleWallet =
243+
SingleWallet.newBuilder()
244+
.setId(walletId)
245+
.setName(newWalletConfig.name)
246+
.setNetwork(newWalletConfig.network.intoProto())
247+
.setScriptType(newWalletConfig.scriptType)
248+
.setDescriptor(descriptor.toStringWithSecret())
249+
.setChangeDescriptor(changeDescriptor.toStringWithSecret())
250+
.setRecoveryPhrase(mnemonic.toString())
251+
.build()
232252

233253
// TODO: launch this correctly, not on the main thread
234254
// Save the new wallet to the datastore
235255
runBlocking { userPreferencesRepository.updateActiveWallets(newWalletForDatastore) }
236256

237-
val bdkWallet = BdkWallet(
238-
descriptor = descriptor,
239-
changeDescriptor = changeDescriptor,
240-
network = newWalletConfig.network,
241-
connection = connection,
242-
)
257+
val bdkWallet =
258+
BdkWallet(
259+
descriptor = descriptor,
260+
changeDescriptor = changeDescriptor,
261+
network = newWalletConfig.network,
262+
connection = connection,
263+
)
243264

244265
return Wallet(
245266
wallet = bdkWallet,
@@ -260,11 +281,12 @@ class Wallet private constructor(
260281
val descriptor = Descriptor(activeWallet.descriptor, activeWallet.network.intoDomain())
261282
val changeDescriptor = Descriptor(activeWallet.changeDescriptor, activeWallet.network.intoDomain())
262283
val connection = Connection("$internalAppFilesPath/wallet-${activeWallet.id.take(8)}.sqlite3")
263-
val bdkWallet = BdkWallet.load(
264-
descriptor = descriptor,
265-
changeDescriptor = changeDescriptor,
266-
connection = connection,
267-
)
284+
val bdkWallet =
285+
BdkWallet.load(
286+
descriptor = descriptor,
287+
changeDescriptor = changeDescriptor,
288+
connection = connection,
289+
)
268290

269291
return Wallet(
270292
wallet = bdkWallet,
@@ -284,42 +306,46 @@ class Wallet private constructor(
284306
): Wallet {
285307
val mnemonic = Mnemonic.fromString(recoverWalletConfig.recoveryPhrase)
286308
val bip32ExtendedRootKey = DescriptorSecretKey(recoverWalletConfig.network, mnemonic, null)
287-
val descriptor: Descriptor = createScriptAppropriateDescriptor(
288-
recoverWalletConfig.scriptType,
289-
bip32ExtendedRootKey,
290-
recoverWalletConfig.network,
291-
KeychainKind.EXTERNAL
292-
)
293-
val changeDescriptor: Descriptor = createScriptAppropriateDescriptor(
294-
recoverWalletConfig.scriptType,
295-
bip32ExtendedRootKey,
296-
recoverWalletConfig.network,
297-
KeychainKind.INTERNAL
298-
)
309+
val descriptor: Descriptor =
310+
createScriptAppropriateDescriptor(
311+
recoverWalletConfig.scriptType,
312+
bip32ExtendedRootKey,
313+
recoverWalletConfig.network,
314+
KeychainKind.EXTERNAL
315+
)
316+
val changeDescriptor: Descriptor =
317+
createScriptAppropriateDescriptor(
318+
recoverWalletConfig.scriptType,
319+
bip32ExtendedRootKey,
320+
recoverWalletConfig.network,
321+
KeychainKind.INTERNAL
322+
)
299323
val walletId = UUID.randomUUID().toString()
300324
val connection = Connection("$internalAppFilesPath/wallet-${walletId.take(8)}.sqlite3",)
301325

302326
// Create SingleWallet object for saving to datastore
303-
val newWalletForDatastore: SingleWallet = SingleWallet.newBuilder()
304-
.setId(walletId)
305-
.setName(recoverWalletConfig.name)
306-
.setNetwork(recoverWalletConfig.network.intoProto())
307-
.setScriptType(recoverWalletConfig.scriptType)
308-
.setDescriptor(descriptor.toStringWithSecret())
309-
.setChangeDescriptor(changeDescriptor.toStringWithSecret())
310-
.setRecoveryPhrase(mnemonic.toString())
311-
.build()
327+
val newWalletForDatastore: SingleWallet =
328+
SingleWallet.newBuilder()
329+
.setId(walletId)
330+
.setName(recoverWalletConfig.name)
331+
.setNetwork(recoverWalletConfig.network.intoProto())
332+
.setScriptType(recoverWalletConfig.scriptType)
333+
.setDescriptor(descriptor.toStringWithSecret())
334+
.setChangeDescriptor(changeDescriptor.toStringWithSecret())
335+
.setRecoveryPhrase(mnemonic.toString())
336+
.build()
312337

313338
// TODO: launch this correctly, not on the main thread
314339
// Save the new wallet to the datastore
315340
runBlocking { userPreferencesRepository.updateActiveWallets(newWalletForDatastore) }
316341

317-
val bdkWallet = BdkWallet(
318-
descriptor = descriptor,
319-
changeDescriptor = changeDescriptor,
320-
connection = connection,
321-
network = recoverWalletConfig.network,
322-
)
342+
val bdkWallet =
343+
BdkWallet(
344+
descriptor = descriptor,
345+
changeDescriptor = changeDescriptor,
346+
connection = connection,
347+
network = recoverWalletConfig.network,
348+
)
323349

324350
return Wallet(
325351
wallet = bdkWallet,
@@ -338,7 +364,7 @@ fun createScriptAppropriateDescriptor(
338364
scriptType: ActiveWalletScriptType,
339365
bip32ExtendedRootKey: DescriptorSecretKey,
340366
network: Network,
341-
keychain: KeychainKind
367+
keychain: KeychainKind,
342368
): Descriptor {
343369
return if (keychain == KeychainKind.EXTERNAL) {
344370
when (scriptType) {

0 commit comments

Comments
 (0)