-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(dashpay): coinjoin entire wallet balance #1222
Changes from 9 commits
8d9bca3
0fd636e
bde8fab
cd74d68
6d2e40a
af903e0
4ec8988
7da5e2d
b7291d1
57e83ad
9204cb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,17 @@ package de.schildbach.wallet.payments | |
|
||
import androidx.annotation.VisibleForTesting | ||
import de.schildbach.wallet.WalletApplication | ||
import de.schildbach.wallet.data.CoinJoinConfig | ||
import de.schildbach.wallet.data.PaymentIntent | ||
import de.schildbach.wallet.payments.parsers.PaymentIntentParser | ||
import de.schildbach.wallet.security.SecurityFunctions | ||
import de.schildbach.wallet.security.SecurityGuard | ||
import de.schildbach.wallet.service.CoinJoinMode | ||
import de.schildbach.wallet.service.PackageInfoProvider | ||
import kotlinx.coroutines.* | ||
import kotlinx.coroutines.flow.filterNotNull | ||
import kotlinx.coroutines.flow.launchIn | ||
import kotlinx.coroutines.flow.onEach | ||
import okhttp3.CacheControl | ||
import okhttp3.MediaType | ||
import okhttp3.MediaType.Companion.toMediaTypeOrNull | ||
|
@@ -34,7 +39,6 @@ import okio.IOException | |
import org.bitcoin.protocols.payments.Protos | ||
import org.bitcoin.protocols.payments.Protos.Payment | ||
import org.bitcoinj.coinjoin.CoinJoinCoinSelector | ||
import org.bitcoinj.coinjoin.UnmixedZeroConfCoinSelector | ||
import org.bitcoinj.core.* | ||
import org.bitcoinj.crypto.IKey | ||
import org.bitcoinj.crypto.KeyCrypterException | ||
|
@@ -57,12 +61,25 @@ class SendCoinsTaskRunner @Inject constructor( | |
private val walletData: WalletDataProvider, | ||
private val walletApplication: WalletApplication, | ||
private val securityFunctions: SecurityFunctions, | ||
private val packageInfoProvider: PackageInfoProvider | ||
private val packageInfoProvider: PackageInfoProvider, | ||
coinJoinConfig: CoinJoinConfig | ||
) : SendPaymentService { | ||
companion object { | ||
private const val WALLET_EXCEPTION_MESSAGE = "this method can't be used before creating the wallet" | ||
private val log = LoggerFactory.getLogger(SendCoinsTaskRunner::class.java) | ||
} | ||
private var coinJoinSend = false | ||
private val coroutineScope = CoroutineScope(Dispatchers.IO) | ||
|
||
init { | ||
coinJoinConfig | ||
.observeMode() | ||
.filterNotNull() | ||
.onEach { mode -> | ||
coinJoinSend = mode != CoinJoinMode.NONE | ||
} | ||
.launchIn(coroutineScope) | ||
} | ||
Comment on lines
+71
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My first thought was to pass a "send with coinjoin" boolean value in many of these functions. But this would require that many ViewModels in many modules have access to the My final idea was to load the CoinJoin mode here and no other modules or view models need to know anything about CoinJoin. |
||
|
||
@Throws(LeftoverBalanceException::class) | ||
override suspend fun sendCoins( | ||
|
@@ -233,12 +250,11 @@ class SendCoinsTaskRunner @Inject constructor( | |
mayEditAmount: Boolean, | ||
paymentIntent: PaymentIntent, | ||
signInputs: Boolean, | ||
forceEnsureMinRequiredFee: Boolean, | ||
coinJoin: Boolean = false | ||
forceEnsureMinRequiredFee: Boolean | ||
): SendRequest { | ||
val wallet = walletData.wallet ?: throw RuntimeException(WALLET_EXCEPTION_MESSAGE) | ||
val sendRequest = paymentIntent.toSendRequest() | ||
sendRequest.coinSelector = getCoinSelector(coinJoin) | ||
sendRequest.coinSelector = getCoinSelector() | ||
sendRequest.useInstantSend = false | ||
sendRequest.feePerKb = Constants.ECONOMIC_FEE | ||
sendRequest.ensureMinRequiredFee = forceEnsureMinRequiredFee | ||
|
@@ -256,15 +272,14 @@ class SendCoinsTaskRunner @Inject constructor( | |
amount: Coin, | ||
coinSelector: CoinSelector? = null, | ||
emptyWallet: Boolean = false, | ||
forceMinFee: Boolean = true, | ||
coinJoin: Boolean = false | ||
forceMinFee: Boolean = true | ||
): SendRequest { | ||
return SendRequest.to(address, amount).apply { | ||
this.feePerKb = Constants.ECONOMIC_FEE | ||
this.ensureMinRequiredFee = forceMinFee | ||
this.emptyWallet = emptyWallet | ||
|
||
val selector = coinSelector ?: getCoinSelector(coinJoin) | ||
val selector = coinSelector ?: getCoinSelector() | ||
this.coinSelector = selector | ||
|
||
if (selector is ByAddressCoinSelector) { | ||
|
@@ -273,10 +288,12 @@ class SendCoinsTaskRunner @Inject constructor( | |
} | ||
} | ||
|
||
private fun getCoinSelector(coinJoin: Boolean) = if (coinJoin) { | ||
private fun getCoinSelector() = if (coinJoinSend) { | ||
// mixed only | ||
CoinJoinCoinSelector(walletData.wallet) | ||
} else { | ||
UnmixedZeroConfCoinSelector(walletData.wallet) | ||
// collect all coins, mixed and unmixed | ||
ZeroConfCoinSelector.get() | ||
} | ||
|
||
@Throws(LeftoverBalanceException::class) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixing is no longer part of the Username Creation Process, but the UI hasn't been updated to reflect that.