diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/AbstractKit.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/AbstractKit.kt index 82ba4574..e585e046 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/AbstractKit.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/AbstractKit.kt @@ -89,6 +89,10 @@ abstract class AbstractKit { return bitcoinCore.receiveAddress() } + fun usedAddresses(): List { + return bitcoinCore.usedAddresses() + } + fun receivePublicKey(): PublicKey { return bitcoinCore.receivePublicKey() } diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/BitcoinCore.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/BitcoinCore.kt index 8953cd24..bc2f3b0e 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/BitcoinCore.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/BitcoinCore.kt @@ -24,6 +24,7 @@ import io.horizontalsystems.bitcoincore.models.PublicKey import io.horizontalsystems.bitcoincore.models.TransactionDataSortType import io.horizontalsystems.bitcoincore.models.TransactionFilterType import io.horizontalsystems.bitcoincore.models.TransactionInfo +import io.horizontalsystems.bitcoincore.models.UsedAddress import io.horizontalsystems.bitcoincore.network.messages.IMessageParser import io.horizontalsystems.bitcoincore.network.messages.IMessageSerializer import io.horizontalsystems.bitcoincore.network.messages.NetworkMessageParser @@ -203,6 +204,15 @@ class BitcoinCore( return addressConverter.convert(publicKeyManager.receivePublicKey(), purpose.scriptType).stringValue } + fun usedAddresses(): List { + return publicKeyManager.usedPublicKeys().map { + UsedAddress( + index = it.index, + address = addressConverter.convert(it, purpose.scriptType).stringValue + ) + }.sortedBy { it.index } + } + fun receivePublicKey(): PublicKey { return publicKeyManager.receivePublicKey() } diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/WatchAddressPublicKeyManager.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/WatchAddressPublicKeyManager.kt index 9ffe26c5..15dbd286 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/WatchAddressPublicKeyManager.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/WatchAddressPublicKeyManager.kt @@ -20,6 +20,8 @@ class WatchAddressPublicKeyManager( override fun receivePublicKey() = publicKey + override fun usedPublicKeys(): List = listOf(publicKey) + override fun fillGap() { bloomFilterManager?.regenerateBloomFilter() } diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/core/Interfaces.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/core/Interfaces.kt index 8f83be33..59a0842a 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/core/Interfaces.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/core/Interfaces.kt @@ -252,6 +252,7 @@ interface IAccountWallet { interface IPublicKeyManager { fun changePublicKey(): PublicKey fun receivePublicKey(): PublicKey + fun usedPublicKeys(): List fun fillGap() fun addKeys(keys: List) fun gapShifts(): Boolean diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/managers/AccountPublicKeyManager.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/managers/AccountPublicKeyManager.kt index f0269af2..9b68712e 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/managers/AccountPublicKeyManager.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/managers/AccountPublicKeyManager.kt @@ -29,6 +29,10 @@ class AccountPublicKeyManager( return getPublicKey(external = true) } + override fun usedPublicKeys(): List { + return storage.getPublicKeysWithUsedState().filter { it.publicKey.external && it.used }.map { it.publicKey } + } + @Throws override fun changePublicKey(): PublicKey { return getPublicKey(external = false) diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/managers/PublicKeyManager.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/managers/PublicKeyManager.kt index dbd2acf7..dbd0204c 100644 --- a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/managers/PublicKeyManager.kt +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/managers/PublicKeyManager.kt @@ -36,6 +36,10 @@ class PublicKeyManager( return getPublicKey(external = false) } + override fun usedPublicKeys(): List { + return storage.getPublicKeysWithUsedState().filter { it.publicKey.external && it.used }.map { it.publicKey } + } + override fun getPublicKeyByPath(path: String): PublicKey { val parts = path.split("/").map { it.toInt() } diff --git a/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/models/UsedAddress.kt b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/models/UsedAddress.kt new file mode 100644 index 00000000..b694f781 --- /dev/null +++ b/bitcoincore/src/main/kotlin/io/horizontalsystems/bitcoincore/models/UsedAddress.kt @@ -0,0 +1,6 @@ +package io.horizontalsystems.bitcoincore.models + +data class UsedAddress( + val index: Int, + val address: String +)