-
Notifications
You must be signed in to change notification settings - Fork 172
fix: fix username creation bugs and remove some ANR's #1350
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
Changes from all commits
6971acb
0a593bb
4fb3b50
a037f1e
ad6dbc5
ef127ea
db582b1
a6ce6ab
15c7a14
e16f16c
1f5135a
0637006
19910b3
4b3d0a8
20cd511
f246f1f
e7f2b9e
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 |
---|---|---|
|
@@ -99,7 +99,7 @@ class DashDirectViewModel @Inject constructor( | |
.launchIn(viewModelScope) | ||
|
||
walletDataProvider | ||
.observeBalance() | ||
.observeTotalBalance() | ||
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. observeBalance -> observeTotalBalance, make it explicity getting the total balance, not necessarily what is spendable. This balance should be based on the CoinJoin Mode, but that will be handled later. |
||
.distinctUntilChanged() | ||
.onEach(_balance::postValue) | ||
.launchIn(viewModelScope) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,8 @@ public final class Constants { | |
public static boolean SUPPORTS_PLATFORM; | ||
// TODO: remove all references to this when invites are enabled and functional | ||
public static boolean SUPPORTS_INVITES; | ||
// TODO: remove all references to this when transaction metadata is saved on platform | ||
public static final boolean SUPPORTS_TXMETADATA; | ||
|
||
public static final EnumSet<MasternodeSync.SYNC_FLAGS> SYNC_FLAGS = MasternodeSync.SYNC_DEFAULT_SPV; | ||
public static final EnumSet<MasternodeSync.VERIFY_FLAGS> VERIFY_FLAGS = MasternodeSync.VERIFY_DEFAULT_SPV; | ||
|
@@ -92,6 +94,7 @@ public final class Constants { | |
org.dash.wallet.common.util.Constants.INSTANCE.setEXPLORE_GC_FILE_PATH("explore/explore.db"); | ||
SUPPORTS_PLATFORM = !is32Bit; | ||
SUPPORTS_INVITES = false; | ||
SUPPORTS_TXMETADATA = false; | ||
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. This will disable publishing tx-metadata to platform, which is an unfinished feature. |
||
SYNC_FLAGS.add(MasternodeSync.SYNC_FLAGS.SYNC_HEADERS_MN_LIST_FIRST); | ||
if (SUPPORTS_PLATFORM) { | ||
SYNC_FLAGS.add(MasternodeSync.SYNC_FLAGS.SYNC_BLOCKS_AFTER_PREPROCESSING); | ||
|
@@ -110,6 +113,7 @@ public final class Constants { | |
WALLET_NAME_CURRENCY_CODE = "tdash"; | ||
SUPPORTS_PLATFORM = !is32Bit; | ||
SUPPORTS_INVITES = false; | ||
SUPPORTS_TXMETADATA = false; | ||
SYNC_FLAGS.add(MasternodeSync.SYNC_FLAGS.SYNC_HEADERS_MN_LIST_FIRST); | ||
if (SUPPORTS_PLATFORM) { | ||
SYNC_FLAGS.add(MasternodeSync.SYNC_FLAGS.SYNC_BLOCKS_AFTER_PREPROCESSING); | ||
|
@@ -130,7 +134,9 @@ public final class Constants { | |
FEE_NETWORK_SUFFIX = "-testnet"; // use the same fee file as testnet | ||
WALLET_NAME_CURRENCY_CODE = "tdash"; | ||
org.dash.wallet.common.util.Constants.EXPLORE_GC_FILE_PATH = "explore/explore-devnet.db"; | ||
SUPPORTS_PLATFORM = true; | ||
SUPPORTS_PLATFORM = !is32Bit; | ||
SUPPORTS_INVITES = false; | ||
SUPPORTS_TXMETADATA = false; | ||
Comment on lines
+137
to
+139
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. We haven't made devnet builds in a long time, but let's update the feature flags. |
||
SYNC_FLAGS.add(MasternodeSync.SYNC_FLAGS.SYNC_HEADERS_MN_LIST_FIRST); | ||
SYNC_FLAGS.add(MasternodeSync.SYNC_FLAGS.SYNC_BLOCKS_AFTER_PREPROCESSING); | ||
org.dash.wallet.common.util.Constants.FAUCET_URL = String.format("http://faucet.%s.networks.dash.org/", devNetName); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,24 +61,21 @@ | |
import org.bitcoinj.core.TransactionBag; | ||
import org.bitcoinj.core.VerificationException; | ||
import org.bitcoinj.crypto.LinuxSecureRandom; | ||
import org.bitcoinj.manager.DashSystem; | ||
import org.bitcoinj.utils.Threading; | ||
import org.bitcoinj.core.VersionMessage; | ||
import org.bitcoinj.crypto.IKey; | ||
import org.bitcoinj.wallet.AuthenticationKeyChain; | ||
import org.bitcoinj.wallet.CoinSelector; | ||
import org.bitcoinj.wallet.Protos; | ||
import org.bitcoinj.wallet.UnreadableWalletException; | ||
import org.bitcoinj.wallet.Wallet; | ||
import org.bitcoinj.wallet.WalletEx; | ||
import org.bitcoinj.wallet.WalletExtension; | ||
import org.bitcoinj.wallet.WalletProtobufSerializer; | ||
import org.bitcoinj.wallet.authentication.AuthenticationGroupExtension; | ||
import org.bitcoinj.wallet.authentication.AuthenticationKeyUsage; | ||
import org.dash.wallet.common.AutoLogoutTimerHandler; | ||
import org.dash.wallet.common.Configuration; | ||
import org.dash.wallet.common.InteractionAwareActivity; | ||
import org.dash.wallet.common.WalletDataProvider; | ||
import org.dash.wallet.common.data.WalletUIConfig; | ||
import org.dash.wallet.common.services.LeftoverBalanceException; | ||
import org.dash.wallet.common.services.TransactionMetadataProvider; | ||
import org.dash.wallet.common.services.analytics.AnalyticsService; | ||
|
@@ -91,17 +88,18 @@ | |
|
||
import ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy; | ||
import ch.qos.logback.core.util.FileSize; | ||
import de.schildbach.wallet.data.CoinJoinConfig; | ||
import de.schildbach.wallet.service.BlockchainStateDataProvider; | ||
import de.schildbach.wallet.service.DashSystemService; | ||
import de.schildbach.wallet.service.PackageInfoProvider; | ||
import de.schildbach.wallet.service.WalletFactory; | ||
import de.schildbach.wallet.transactions.MasternodeObserver; | ||
import de.schildbach.wallet.transactions.WalletBalanceObserver; | ||
import de.schildbach.wallet.ui.buy_sell.LiquidClient; | ||
import org.dash.wallet.integrations.uphold.api.UpholdClient; | ||
import org.dash.wallet.integrations.uphold.data.UpholdConstants; | ||
import org.dash.wallet.integrations.crowdnode.utils.CrowdNodeConfig; | ||
import org.dash.wallet.integrations.crowdnode.utils.CrowdNodeBalanceCondition; | ||
import org.dash.wallet.integrations.crowdnode.utils.CrowdNodeConfig; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
@@ -118,7 +116,6 @@ | |
import java.util.EnumSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.inject.Inject; | ||
|
@@ -130,8 +127,6 @@ | |
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.rolling.RollingFileAppender; | ||
import dagger.hilt.android.HiltAndroidApp; | ||
import org.dash.wallet.common.data.entity.BlockchainState; | ||
import de.schildbach.wallet.database.dao.BlockchainStateDao; | ||
import de.schildbach.wallet.security.SecurityGuard; | ||
import de.schildbach.wallet.service.BlockchainService; | ||
import de.schildbach.wallet.service.BlockchainServiceImpl; | ||
|
@@ -216,6 +211,9 @@ public class WalletApplication extends MultiDexApplication | |
WalletFactory walletFactory; | ||
@Inject | ||
DashSystemService dashSystemService; | ||
@Inject | ||
WalletUIConfig walletUIConfig; | ||
private WalletBalanceObserver walletBalanceObserver; | ||
|
||
@Override | ||
protected void attachBaseContext(Context base) { | ||
|
@@ -580,6 +578,9 @@ private void afterLoadWallet() { | |
// make sure there is at least one recent backup | ||
if (!getFileStreamPath(Constants.Files.WALLET_KEY_BACKUP_PROTOBUF).exists()) | ||
backupWallet(); | ||
|
||
// setup WalletBalanceObserver | ||
walletBalanceObserver = new WalletBalanceObserver(wallet, walletUIConfig); | ||
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. this is the "global" wallet observer. |
||
} | ||
|
||
private void deleteBlockchainFiles() { | ||
|
@@ -1041,6 +1042,8 @@ public void finalizeWipe() { | |
// wallet must be null for the OnboardingActivity flow | ||
log.info("removing wallet from memory during wipe"); | ||
wallet = null; | ||
walletBalanceObserver.close(); | ||
walletBalanceObserver = null; | ||
Comment on lines
+1045
to
+1046
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. when the wallet is replaced or reset, we should also close out the balance observer. |
||
if (afterWipeFunction != null) | ||
afterWipeFunction.invoke(); | ||
afterWipeFunction = null; | ||
|
@@ -1103,7 +1106,28 @@ public Coin getWalletBalance() { | |
return Coin.ZERO; | ||
} | ||
|
||
return wallet.getBalance(Wallet.BalanceType.ESTIMATED); | ||
//return wallet.getBalance(Wallet.BalanceType.ESTIMATED); | ||
return walletBalanceObserver.getTotalBalance().getValue(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Flow<Coin> observeTotalBalance() { | ||
if (wallet == null) { | ||
return FlowKt.emptyFlow(); | ||
} | ||
|
||
return walletBalanceObserver.getTotalBalance(); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Flow<Coin> observeMixedBalance() { | ||
if (wallet == null) { | ||
return FlowKt.emptyFlow(); | ||
} | ||
|
||
return walletBalanceObserver.getMixedBalance(); | ||
} | ||
|
||
@NonNull | ||
|
@@ -1116,7 +1140,7 @@ public Flow<Coin> observeBalance( | |
return FlowKt.emptyFlow(); | ||
} | ||
|
||
return new WalletBalanceObserver(wallet, balanceType, coinSelector).observe(); | ||
return walletBalanceObserver.observe(balanceType, coinSelector); | ||
} | ||
|
||
@NonNull | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ import kotlinx.coroutines.CoroutineScope | |
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.SupervisorJob | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.sync.Mutex | ||
import kotlinx.coroutines.withContext | ||
import org.bitcoinj.core.Address | ||
import org.bitcoinj.core.Block | ||
|
@@ -169,6 +170,7 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService { | |
private val serviceJob = SupervisorJob() | ||
private val serviceScope = CoroutineScope(Dispatchers.IO + serviceJob) | ||
private val onCreateCompleted = CompletableDeferred<Unit>() | ||
private var checkMutex = Mutex(false) | ||
|
||
@Inject lateinit var application: WalletApplication | ||
|
||
|
@@ -215,7 +217,6 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService { | |
private var peerGroup: PeerGroup? = null | ||
private val handler = Handler() | ||
private val delayHandler = Handler() | ||
private val metadataHandler = Handler() | ||
private var wakeLock: PowerManager.WakeLock? = null | ||
private var peerConnectivityListener: PeerConnectivityListener? = null | ||
private var nm: NotificationManager? = null | ||
|
@@ -241,6 +242,8 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService { | |
private var syncPercentage = 0 // 0 to 100% | ||
private var mixingStatus = MixingStatus.NOT_STARTED | ||
private var mixingProgress = 0.0 | ||
private var balance = Coin.ZERO | ||
private var mixedBalance = Coin.ZERO | ||
private var foregroundService = ForegroundService.NONE | ||
|
||
// Risk Analyser for Transactions that is PeerGroup Aware | ||
|
@@ -254,10 +257,8 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService { | |
CrowdNodeDepositReceivedResponse(Constants.NETWORK_PARAMETERS) | ||
private var apiConfirmationHandler: CrowdNodeAPIConfirmationHandler? = null | ||
private fun handleMetadata(tx: Transaction) { | ||
metadataHandler.post { | ||
transactionMetadataProvider.syncTransactionBlocking( | ||
tx | ||
) | ||
serviceScope.launch { | ||
transactionMetadataProvider.syncTransaction(tx) | ||
Comment on lines
-257
to
+261
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. use coroutine instead of a Handler() |
||
} | ||
} | ||
|
||
|
@@ -683,7 +684,12 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService { | |
serviceScope.launch { | ||
// make sure that onCreate is finished | ||
onCreateCompleted.await() | ||
checkService() | ||
checkMutex.lock() | ||
try { | ||
checkService() | ||
} finally { | ||
checkMutex.unlock() | ||
} | ||
} | ||
} | ||
|
||
|
@@ -708,7 +714,7 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService { | |
packageInfoProvider.packageInfo | ||
) | ||
} | ||
org.bitcoinj.core.Context.propagate(wallet.context) | ||
propagateContext() | ||
dashSystemService.system.initDashSync(getDir("masternode", MODE_PRIVATE).absolutePath) | ||
log.info("starting peergroup") | ||
peerGroup = PeerGroup(Constants.NETWORK_PARAMETERS, blockChain, headerChain) | ||
|
@@ -1012,6 +1018,9 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService { | |
} | ||
|
||
private fun propagateContext() { | ||
if (application.wallet?.context != Constants.CONTEXT) { | ||
log.warn("wallet context does not equal Constants.CONTEXT") | ||
} | ||
org.bitcoinj.core.Context.propagate(Constants.CONTEXT) | ||
} | ||
|
||
|
@@ -1125,21 +1134,31 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService { | |
coinJoinService.observeMixingProgress().observe(this@BlockchainServiceImpl) { mixingProgress -> | ||
handleBlockchainStateNotification(blockchainState, mixingStatus, mixingProgress) | ||
} | ||
|
||
application.observeTotalBalance().observe(this@BlockchainServiceImpl) { | ||
balance = it | ||
handleBlockchainStateNotification(blockchainState, mixingStatus, mixingProgress) | ||
} | ||
|
||
application.observeMixedBalance().observe(this@BlockchainServiceImpl) { | ||
mixedBalance = it | ||
handleBlockchainStateNotification(blockchainState, mixingStatus, mixingProgress) | ||
} | ||
Comment on lines
+1137
to
+1146
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. balance updates will trigger notification updates |
||
|
||
onCreateCompleted.complete(Unit) // Signal completion of onCreate | ||
log.info(".onCreate() finished") | ||
} | ||
} | ||
|
||
private fun createCoinJoinNotification(): Notification { | ||
val mixedBalance = (application.wallet as WalletEx?)!!.coinJoinBalance | ||
val totalBalance = application.wallet!!.balance | ||
val notificationIntent = createIntent(this) | ||
val pendingIntent = PendingIntent.getActivity( | ||
this, 0, | ||
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE | ||
) | ||
val decimalFormat = DecimalFormat("0.000") | ||
val statusStringId = when (mixingStatus) { | ||
MixingStatus.NOT_STARTED -> R.string.coinjoin_not_started | ||
MixingStatus.MIXING -> R.string.coinjoin_mixing | ||
MixingStatus.PAUSED -> R.string.coinjoin_paused | ||
MixingStatus.FINISHED -> R.string.coinjoin_progress_finished | ||
|
@@ -1150,7 +1169,7 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService { | |
getString(statusStringId), | ||
mixingProgress, | ||
decimalFormat.format(mixedBalance.toBigDecimal()), | ||
decimalFormat.format(totalBalance.toBigDecimal()) | ||
decimalFormat.format(balance.toBigDecimal()) | ||
) | ||
return NotificationCompat.Builder( | ||
this, | ||
|
@@ -1300,6 +1319,7 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService { | |
serviceScope.launch { | ||
try { | ||
onCreateCompleted.await() // wait until onCreate is finished | ||
checkMutex.lock() | ||
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. There was a crash from |
||
WalletApplication.scheduleStartBlockchainService(this@BlockchainServiceImpl) //disconnect feature | ||
application.wallet!!.removeChangeEventListener(walletEventListener) | ||
application.wallet!!.removeCoinsSentEventListener(walletEventListener) | ||
|
@@ -1330,6 +1350,7 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService { | |
throw RuntimeException(x) | ||
} | ||
if (!deleteWalletFileOnShutdown) { | ||
propagateContext() | ||
application.saveWallet() | ||
} | ||
if (wakeLock!!.isHeld) { | ||
|
@@ -1353,6 +1374,7 @@ class BlockchainServiceImpl : LifecycleService(), BlockchainService { | |
} finally { | ||
log.info("serviceJob cancelled after " + (System.currentTimeMillis() - serviceCreatedAt) / 1000 / 60 + " minutes") | ||
serviceJob.cancel() | ||
checkMutex.unlock() | ||
cleanupDeferred?.complete(Unit) | ||
} | ||
} | ||
|
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.
Save the last calculated values so that they can be emitted first when the app starts