Skip to content

Commit

Permalink
feat(dashpay): integrate dash-sdk and restore basic functions (#1291)
Browse files Browse the repository at this point in the history
* feat: support for making DAPI calls via dash sdk

* fix: keep sdk classes

* fix: update KeyType fields and functions

* fix: remove test queries for getIdentity

* fix: add ContextProvider to PlatformService

* fix: call DAPI functions after masternode list sync

* fix: updates for DAPI call changes

* fix: account for failures in registration

* fix: create username fixes

* fix: fix passing of arguments via view model if others are missing

* fix: updates based on rust sdk contact request items

* fix: remove private settings step on invites

* fix: simplify the end of sending contact request

* fix: simplify send invite operation

* fix: isPlatformAvailable

* style: improve InviteFriendFragment

* style: improve MainViewModel

* style: remove unused imports

* refactor: improve CreateIdentityService

* refactor: improve PlatformRepo

* fix: update dependencies for dash-sdk

* fix: minor changes

* refactor: simplify callbacks for contact view holders

* refactor: make some fields private

* refactor: remove ?

* refactor: remove StatusRuntimeException uses

* fix: fix UI on Contacts Screen

* refactor: use DomainDocument instead of ["*"]

* fix: use label instead of normalizedLabel for the display of usernames

* fix: ignore alias usernames

* chore: bump version code and name
  • Loading branch information
HashEngineering authored Jul 1, 2024
1 parent a84fd67 commit 9c5ef18
Show file tree
Hide file tree
Showing 29 changed files with 395 additions and 395 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.dash.wallet.common.services

import kotlinx.coroutines.flow.Flow
import org.bitcoinj.core.AbstractBlockChain
import org.bitcoinj.core.PeerGroup
import org.dash.wallet.common.data.entity.BlockchainState
import org.dash.wallet.common.data.NetworkStatus

Expand All @@ -43,4 +44,6 @@ interface BlockchainStateProvider {

fun getBlockChain(): AbstractBlockChain?
fun observeBlockChain(): Flow<AbstractBlockChain?>

fun observeSyncStage(): Flow<PeerGroup.SyncStage?>
}
15 changes: 6 additions & 9 deletions wallet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ dependencies {

implementation 'org.bouncycastle:bcprov-jdk15to18:1.74'
implementation "org.dashj:dashj-core:$dashjVersion"
implementation 'org.dashj.platform:dashpay:0.24-MOCK-SNAPSHOT'
implementation 'org.dashj.platform:platform-core:0.24-MOCK-SNAPSHOT'
implementation 'org.dashj.platform:dpp:0.24-SNAPSHOT'
implementation 'org.dashj.platform:dapi-client:0.24-SNAPSHOT'
implementation 'org.dashj:dashj-merk:0.22-SNAPSHOT'
implementation 'org.dashj.android:dashj-merk:0.22-SNAPSHOT'
implementation 'io.grpc:grpc-stub:1.28.0' // CURRENT_GRPC_VERSION
implementation 'org.dashj.platform:dash-sdk-java:1.0-SNAPSHOT'
implementation 'org.dashj.platform:dash-sdk-kotlin:1.0-SNAPSHOT'
implementation 'org.dashj.platform:dash-sdk-android:1.0-SNAPSHOT'
implementation 'io.grpc:grpc-stub:1.54.0' // CURRENT_GRPC_VERSION
implementation "org.dashj.android:dashj-bls-android:1.0.0"
implementation "org.dashj.android:dashj-x11-android:0.17.5"
implementation "org.dashj.android:dashj-scrypt-android:0.17.5"
Expand Down Expand Up @@ -208,8 +205,8 @@ android {
compileSdk 33
minSdkVersion 24
targetSdkVersion 33
versionCode project.hasProperty('versionCode') ? project.property('versionCode') as int : 90002
versionName project.hasProperty('versionName') ? project.property('versionName') : "5.4-dashpay"
versionCode project.hasProperty('versionCode') ? project.property('versionCode') as int : 90008
versionName project.hasProperty('versionName') ? project.property('versionName') : "5.5-dashpay"
multiDexEnabled true
generatedDensities = ['hdpi', 'xhdpi']
vectorDrawables.useSupportLibrary = true
Expand Down
3 changes: 3 additions & 0 deletions wallet/proguard.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
-dontnote com.squareup.okhttp.internal.Platform
-dontwarn org.bitcoinj.store.LevelDBFullPrunedBlockStore**

# dash-sdk
-keep class org.dashj.platform.sdk.** { *; }

# zxing
-dontwarn com.google.zxing.common.BitMatrix

Expand Down
2 changes: 1 addition & 1 deletion wallet/src/de/schildbach/wallet/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public final class Constants {

/** Bitcoinj global context. */
public static final Context CONTEXT = new Context(NETWORK_PARAMETERS);
public static final boolean DASHPAY_DISABLED = true;
public static final boolean DASHPAY_DISABLED = false;

public final static class Files {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import android.net.Uri
import androidx.room.TypeConverter
import de.schildbach.wallet.database.entity.BlockchainIdentityData
import de.schildbach.wallet.data.InvitationLinkData
import de.schildbach.wallet.ui.dashpay.PlatformRepo
import org.dashj.platform.dashpay.BlockchainIdentity
import org.dashj.platform.dpp.identity.Identity
import org.dashj.platform.dpp.identity.IdentityPublicKey
import org.dash.wallet.common.data.entity.BlockchainState
import org.bitcoinj.core.Coin
import org.bitcoinj.core.Sha256Hash
import org.dashj.platform.sdk.KeyType
import java.util.*
import kotlin.collections.ArrayList

Expand Down Expand Up @@ -99,12 +98,12 @@ class BlockchainStateRoomConverters {
}

@TypeConverter
fun toCurrentMainKeyType(value: Int): IdentityPublicKey.Type? {
return if (value > -1) IdentityPublicKey.Type.values()[value] else null
fun toCurrentMainKeyType(value: Int): KeyType? {
return if (value > -1) KeyType.entries[value] else null
}

@TypeConverter
fun fromCurrentMainKeyType(currentMainKeyType: IdentityPublicKey.Type?): Int {
fun fromCurrentMainKeyType(currentMainKeyType: KeyType?): Int {
return currentMainKeyType?.ordinal ?: -1
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import org.dash.wallet.common.WalletDataProvider
import org.dash.wallet.common.data.BaseConfig
import org.dashj.platform.dashpay.BlockchainIdentity
import org.dashj.platform.dpp.identity.Identity
import org.dashj.platform.dpp.identity.IdentityPublicKey
import org.dashj.platform.dpp.toHex
import org.dashj.platform.dpp.util.Converters
import org.dashj.platform.sdk.KeyType
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -62,7 +62,7 @@ data class BlockchainIdentityData(var creationState: CreationState = CreationSta
var totalKeyCount: Int? = null,
var keysCreated: Long? = null,
var currentMainKeyIndex: Int? = null,
var currentMainKeyType: IdentityPublicKey.Type? = null) {
var currentMainKeyType: KeyType? = null) {

var id = 1
set(@Suppress("UNUSED_PARAMETER") value) {
Expand All @@ -73,7 +73,11 @@ data class BlockchainIdentityData(var creationState: CreationState = CreationSta

fun findAssetLockTransaction(wallet: Wallet?): AssetLockTransaction? {
if (creditFundingTxId == null) {
return null
val authExtension =
wallet!!.getKeyChainExtension(AuthenticationGroupExtension.EXTENSION_ID) as AuthenticationGroupExtension
val list = authExtension.assetLockTransactions
list.sortBy { it.updateTime }
return if (list.isEmpty()) null else list.first()
}
if (wallet != null) {
creditFundingTransactionCache = wallet.getTransaction(creditFundingTxId)?.run {
Expand Down Expand Up @@ -141,7 +145,7 @@ open class BlockchainIdentityConfig @Inject constructor(
val BALANCE = longPreferencesKey("identity_balance")
}

val identityData: Flow<BlockchainIdentityData> = data
private val identityData: Flow<BlockchainIdentityData> = data
.map { prefs ->
BlockchainIdentityData(
creationState = BlockchainIdentityData.CreationState.valueOf(prefs[CREATION_STATE] ?: "NONE"),
Expand All @@ -161,7 +165,7 @@ open class BlockchainIdentityConfig @Inject constructor(
)
}

val identityBaseData: Flow<BlockchainIdentityBaseData> = data
private val identityBaseData: Flow<BlockchainIdentityBaseData> = data
.map { prefs ->
BlockchainIdentityBaseData(
1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ data class DashPayContactRequest(val userId: String,
companion object {
fun fromDocument(document: Document): DashPayContactRequest {
val timestamp: Long = if (document.createdAt != null) document.createdAt!! else 0L
val toUserId = Base58.encode(document.data["toUserId"] as ByteArray)
val toUserId = Base58.encode((document.data["toUserId"] as Identifier).toBuffer())

val encryptedAccountLabel: ByteArray? = if (document.data.containsKey("encryptedAccountLabel"))
document.data["encryptedAccountLabel"] as ByteArray
else null

val accountReference: Int = if (document.data.containsKey("accountReference"))
document.data["accountReference"] as Int
(document.data["accountReference"] as Long).toInt()
else 0

val autoAcceptProof: ByteArray? = if (document.data.containsKey("autoAcceptProof"))
Expand All @@ -60,8 +60,8 @@ data class DashPayContactRequest(val userId: String,
return DashPayContactRequest(document.ownerId.toString(), toUserId,
accountReference,
document.data["encryptedPublicKey"] as ByteArray,
document.data["senderKeyIndex"] as Int,
document.data["recipientKeyIndex"] as Int,
(document.data["senderKeyIndex"] as Long).toInt(),
(document.data["recipientKeyIndex"] as Long).toInt(),
timestamp,
encryptedAccountLabel,
autoAcceptProof)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.bitcoinj.core.CheckpointManager;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.FilteredBlock;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Peer;
import org.bitcoinj.core.PeerGroup;
import org.bitcoinj.core.Sha256Hash;
Expand Down Expand Up @@ -192,7 +191,7 @@ public class BlockchainServiceImpl extends LifecycleService implements Blockchai
private BlockchainState blockchainState = new BlockchainState(null, 0, false, impediments, 0, 0, 0);
private int notificationCount = 0;
private Coin notificationAccumulatedAmount = Coin.ZERO;
private final List<Address> notificationAddresses = new LinkedList<Address>();
private final List<Address> notificationAddresses = new LinkedList<>();
private AtomicInteger transactionsReceived = new AtomicInteger();
private AtomicInteger mnListDiffsReceived = new AtomicInteger();
private long serviceCreatedAt;
Expand Down Expand Up @@ -1302,7 +1301,10 @@ private void updateBlockchainStateImpediments() {
}

private void updateBlockchainState() {
blockchainStateDataProvider.updateBlockchainState(blockChain, impediments, percentageSync());
blockchainStateDataProvider.updateBlockchainState(
blockChain, impediments, percentageSync(),
peerGroup != null ? peerGroup.getSyncStage() : null
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.bitcoinj.core.BlockChain
import org.bitcoinj.core.CheckpointManager
import org.bitcoinj.core.Coin
import org.bitcoinj.core.NetworkParameters
import org.bitcoinj.core.PeerGroup
import org.bitcoinj.core.StoredBlock
import org.bitcoinj.store.BlockStoreException
import org.dash.wallet.common.Configuration
Expand All @@ -42,7 +43,6 @@ import org.dash.wallet.common.data.entity.BlockchainState
import org.dash.wallet.common.data.NetworkStatus
import org.dash.wallet.common.data.entity.BlockchainState.Impediment
import org.dash.wallet.common.services.BlockchainStateProvider
import org.slf4j.LoggerFactory
import java.io.IOException
import java.io.InputStream
import java.math.BigInteger
Expand Down Expand Up @@ -86,6 +86,7 @@ class BlockchainStateDataProvider @Inject constructor(

private val networkStatusFlow = MutableStateFlow(NetworkStatus.UNKNOWN)
private val blockchainFlow = MutableStateFlow<AbstractBlockChain?>(null)
private val syncStageFlow = MutableStateFlow<PeerGroup.SyncStage?>(null)

override suspend fun getState(): BlockchainState? {
return blockchainStateDao.getState()
Expand All @@ -106,7 +107,7 @@ class BlockchainStateDataProvider @Inject constructor(
}
}

fun updateBlockchainState(blockChain: BlockChain, impediments: Set<Impediment>, percentageSync: Int) {
fun updateBlockchainState(blockChain: BlockChain, impediments: Set<Impediment>, percentageSync: Int, syncStage: PeerGroup.SyncStage?) {
coroutineScope.launch {
var blockchainState = blockchainStateDao.getState()
if (blockchainState == null) {
Expand All @@ -123,6 +124,7 @@ class BlockchainStateDataProvider @Inject constructor(
blockchainState.mnlistHeight = mnListHeight
blockchainState.percentageSync = percentageSync
blockchainStateDao.saveState(blockchainState)
syncStageFlow.value = syncStage
}
}

Expand Down Expand Up @@ -182,7 +184,11 @@ class BlockchainStateDataProvider @Inject constructor(
}

override fun observeBlockChain(): Flow<AbstractBlockChain?> {
return blockchainFlow;
return blockchainFlow
}

override fun observeSyncStage(): Flow<PeerGroup.SyncStage?> {
return syncStageFlow
}

override fun getMasternodeAPY(): Double {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ import org.dash.wallet.common.WalletDataProvider
import org.dash.wallet.common.services.analytics.AnalyticsConstants
import org.dash.wallet.common.services.analytics.AnalyticsService
import org.dash.wallet.common.services.analytics.AnalyticsTimer
import org.dashj.platform.dashpay.RetryDelayType
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.concurrent.TimeoutException
import javax.inject.Inject

interface PlatformBroadcastService {
Expand Down Expand Up @@ -127,20 +125,11 @@ class PlatformDocumentBroadcastService @Inject constructor(
timer.logTiming()
log.info("profile broadcast")

//Verify that the Contact Request was seen on the network
val updatedProfile = blockchainIdentity.watchProfile(100, 5000, RetryDelayType.LINEAR)
// TODO: Verify that the Contact Request was seen on the network?

if (createdProfile != updatedProfile) {
log.warn("Created profile doesn't match profile from network $createdProfile != $updatedProfile")
}

log.info("updated profile: $updatedProfile")
if (updatedProfile != null) {
val updatedDashPayProfile = DashPayProfile.fromDocument(updatedProfile, dashPayProfile.username)
platformRepo.updateDashPayProfile(updatedDashPayProfile!!) //update the database since the cr was accepted
return updatedDashPayProfile
} else {
throw TimeoutException("timeout when updating profile")
}
log.info("updated profile: $createdProfile")
val updatedDashPayProfile = DashPayProfile.fromDocument(createdProfile, dashPayProfile.username)
platformRepo.updateDashPayProfile(updatedDashPayProfile!!) //update the database since the cr was accepted
return updatedDashPayProfile
}
}
Loading

0 comments on commit 9c5ef18

Please sign in to comment.