Skip to content

Commit

Permalink
Dashpay feature submit request backend (#1301)
Browse files Browse the repository at this point in the history
* fix: align with Send Request functionality

* feat: add broadcastIdentityVerify method to PlatformBroadcastService

* feat: add identityVerify queries to Platform Services

* feat: add identityVerify queries to CreateIdentityService

* feat: add worker for broadcast identity verification

* feat: update to support improved username requests

* chore: remove commented code

* fix: fix verify links saving to document

* chore: fix or add license headers
  • Loading branch information
HashEngineering authored Aug 29, 2024
1 parent 66c4816 commit 71d1092
Show file tree
Hide file tree
Showing 23 changed files with 620 additions and 523 deletions.
126 changes: 30 additions & 96 deletions wallet/res/layout/fragment_voting_request_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,75 +48,6 @@
android:layout_marginTop="5dp"
android:text="@string/after_the_voting" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:orientation="horizontal">

<ImageView
android:id="@+id/create_a_username_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toStartOf="@id/create_a_username_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/create_a_username_title"
app:srcCompat="@drawable/ic_calendar" />

<TextView
style="@style/Caption.SemiBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:includeFontPadding="false"
android:text="@string/voting"
android:textAlignment="gravity" />

<TextView
android:id="@+id/voting_range"
style="@style/Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:maxLines="1"
android:textAlignment="gravity"
tools:text=" 1 Mar – 15 Mar" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<ImageView
android:id="@+id/votes_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toStartOf="@id/create_a_username_title"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/create_a_username_title"
app:srcCompat="@drawable/ic_thumb_up_fill" />

<TextView
android:id="@+id/votes_number"
style="@style/Caption.SemiBold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="7dp"
android:includeFontPadding="false"
android:text="@string/votes"
android:textAlignment="gravity" />

<ImageView
android:id="@+id/votes_arrow"
android:layout_width="wrap_content"
android:layout_height="11dp"
android:layout_gravity="center"
android:src="@drawable/ic_menu_row_arrow"
app:srcCompat="@drawable/ic_menu_row_arrow" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -150,7 +81,7 @@
android:layout_weight="1"
android:gravity="end"
android:textAlignment="textEnd"
tools:text="John Doe" />
tools:text="JohnDoe" />
</LinearLayout>

<LinearLayout
Expand Down Expand Up @@ -187,7 +118,7 @@
android:textAlignment="textEnd" />

<TextView
android:id="@+id/verfiy_now"
android:id="@+id/verify"
style="@style/Overline.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -264,34 +195,37 @@
android:layout_weight="1"
android:gravity="end"
android:textAlignment="textEnd"
tools:text="John Doe" />
tools:text="GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec" />

</LinearLayout>
</LinearLayout>
</LinearLayout>

<Button
android:id="@+id/cancel_request_button"
style="@style/Button.Primary.Large.LightRed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="15dp"
android:layout_marginBottom="15dp"
android:text="@string/cancel_request"
app:layout_constraintBottom_toBottomOf="parent" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingVertical="15dp">

<TextView
android:id="@+id/balance_requirement_disclaimer"
style="@style/Overline.Secondary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:gravity="center_horizontal"
android:text="@string/if_you_tap_cancel"
android:textAlignment="gravity"
app:layout_constraintBottom_toTopOf="@id/cancel_request_button"
app:layout_constraintEnd_toEndOf="@id/cancel_request_button"
app:layout_constraintStart_toStartOf="@id/cancel_request_button"
tools:visibility="visible" />
<TextView
style="@style/Caption.Medium.Tertiary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
android:text="@string/results" />

<TextView
android:id="@+id/voting_range"
style="@style/Caption"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginTop="2dp"
android:layout_weight="1"
android:gravity="end"
android:textAlignment="textEnd"
tools:text="March 31, 2024" />

</LinearLayout>
</LinearLayout>
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions wallet/res/values/strings-dashpay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
<string name="request_details_subtitle">Review the posting bellow to verify the ownership of this username</string>
<string name="vote_to_approve">Vote to Approve</string>
<string name="identity">Identity</string>
<string name="results">Results</string>
<string name="link">Link</string>
<string name="link_not_provided">Not provided</string>
<string name="cancel_approval">Cancel Approval</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import org.dashj.platform.dpp.identity.Identity
import org.dash.wallet.common.data.entity.BlockchainState
import org.bitcoinj.core.Coin
import org.bitcoinj.core.Sha256Hash
import org.dashj.platform.dashpay.IdentityStatus
import org.dashj.platform.dashpay.UsernameStatus
import org.dashj.platform.sdk.KeyType
import java.util.*
import kotlin.collections.ArrayList
Expand Down Expand Up @@ -78,22 +80,22 @@ class BlockchainStateRoomConverters {
}

@TypeConverter
fun toUsernameStatus(value: Int): BlockchainIdentity.UsernameStatus {
return BlockchainIdentity.UsernameStatus.values()[value]
fun toUsernameStatus(value: Int): UsernameStatus {
return UsernameStatus.values()[value]
}

@TypeConverter
fun fromUsernameStatus(usernameStatus: BlockchainIdentity.UsernameStatus?): Int {
return usernameStatus?.value ?: BlockchainIdentity.UsernameStatus.NOT_PRESENT.value
fun fromUsernameStatus(usernameStatus: UsernameStatus?): Int {
return usernameStatus?.value ?: UsernameStatus.NOT_PRESENT.value
}

@TypeConverter
fun toRegistrationStatus(value: Int): BlockchainIdentity.RegistrationStatus? {
return if (value > -1) BlockchainIdentity.RegistrationStatus.values()[value] else null
fun toRegistrationStatus(value: Int): IdentityStatus? {
return if (value > -1) IdentityStatus.values()[value] else null
}

@TypeConverter
fun fromRegistrationStatus(registrationStatus: BlockchainIdentity.RegistrationStatus?): Int {
fun fromRegistrationStatus(registrationStatus: IdentityStatus?): Int {
return registrationStatus?.ordinal ?: -1
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package de.schildbach.wallet.database.entity

import de.schildbach.wallet.data.InvitationLinkData
import org.bitcoinj.core.Sha256Hash
import org.dashj.platform.dashpay.UsernameRequestStatus

data class BlockchainIdentityBaseData(
val id: Int,
Expand All @@ -33,14 +34,14 @@ data class BlockchainIdentityBaseData(
var requestedUsername: String? = null,
var verificationLink: String? = null,
val cancelledVerificationLink: Boolean? = null,
val usernameRequested: Boolean? = null,
val usernameRequested: UsernameRequestStatus? = null,
val votingPeriodStart: Long? = null
) {

val creationInProgress: Boolean
get() = creationState > BlockchainIdentityData.CreationState.NONE &&
creationState < BlockchainIdentityData.CreationState.VOTING &&
creationStateErrorMessage == null
creationStateErrorMessage == null && !restoring

val votingInProgress: Boolean
get() = creationState == BlockchainIdentityData.CreationState.VOTING
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import org.bitcoinj.wallet.Wallet
import org.bitcoinj.wallet.authentication.AuthenticationGroupExtension
import org.dash.wallet.common.WalletDataProvider
import org.dash.wallet.common.data.BaseConfig
import org.dashj.platform.dashpay.BlockchainIdentity
import org.dashj.platform.dashpay.IdentityStatus
import org.dashj.platform.dashpay.UsernameRequestStatus
import org.dashj.platform.dashpay.UsernameStatus
import org.dashj.platform.dpp.identity.Identity
import org.dashj.platform.dpp.toHex
import org.dashj.platform.dpp.util.Converters
Expand All @@ -55,20 +57,19 @@ data class BlockchainIdentityData(
var usingInvite: Boolean = false,
var invite: InvitationLinkData? = null,
var preorderSalt: ByteArray? = null,
var registrationStatus: BlockchainIdentity.RegistrationStatus? = null,
var usernameStatus: BlockchainIdentity.UsernameStatus? = null,
var registrationStatus: IdentityStatus? = null,
var usernameStatus: UsernameStatus? = null,
var privacyMode: CoinJoinMode? = null,
var creditBalance: Coin? = null,
var activeKeyCount: Int? = null,
var totalKeyCount: Int? = null,
var keysCreated: Long? = null,
var currentMainKeyIndex: Int? = null,
var currentMainKeyType: KeyType? = null,
var requestedUsername: String? = null,
var verificationLink: String? = null,
val cancelledVerificationLink: Boolean? = null,
val usernameRequested: Boolean? = null,
val votingPeriodStart: Long? = null
var usernameRequested: UsernameRequestStatus? = null,
var votingPeriodStart: Long? = null
) {

var id = 1
Expand Down Expand Up @@ -161,10 +162,10 @@ open class BlockchainIdentityConfig @Inject constructor(
val PRIVACY_MODE = stringPreferencesKey("privacy_mode")
val BALANCE = longPreferencesKey("identity_balance")

val REQUESTED_USERNAME = stringPreferencesKey("requested_username")
// val REQUESTED_USERNAME = stringPreferencesKey("requested_username")
val REQUESTED_USERNAME_LINK = stringPreferencesKey("requested_username_link")
val CANCELED_REQUESTED_USERNAME_LINK = booleanPreferencesKey("cancelled_requested_username_link")
val USERNAME_REQUESTED = booleanPreferencesKey("username_requested")
val USERNAME_REQUESTED = stringPreferencesKey("username_requested")
val VOTING_PERIOD_START = longPreferencesKey("voting_period_start")

}
Expand All @@ -182,14 +183,13 @@ open class BlockchainIdentityConfig @Inject constructor(
usingInvite = prefs[USING_INVITE] ?: false,
invite = prefs[INVITE_LINK]?.let { InvitationLinkData(Uri.parse(it), false) },
preorderSalt = prefs[PREORDER_SALT]?.let { Converters.fromHex(it) },
registrationStatus = prefs[IDENTITY_REGISTRATION_STATUS]?.let { BlockchainIdentity.RegistrationStatus.valueOf(it) },
usernameStatus = prefs[USERNAME_REGISTRATION_STATUS]?.let { BlockchainIdentity.UsernameStatus.valueOf(it) },
registrationStatus = prefs[IDENTITY_REGISTRATION_STATUS]?.let { IdentityStatus.valueOf(it) },
usernameStatus = prefs[USERNAME_REGISTRATION_STATUS]?.let { UsernameStatus.valueOf(it) },
privacyMode = prefs[PRIVACY_MODE]?.let { CoinJoinMode.valueOf(it) },
creditBalance = prefs[BALANCE]?.let { Coin.valueOf(it) },
requestedUsername = prefs[REQUESTED_USERNAME],
verificationLink = prefs[REQUESTED_USERNAME_LINK],
cancelledVerificationLink = prefs[CANCELED_REQUESTED_USERNAME_LINK],
usernameRequested = prefs[USERNAME_REQUESTED],
usernameRequested = prefs[USERNAME_REQUESTED]?.let { UsernameRequestStatus.valueOf(it) },
votingPeriodStart = prefs[VOTING_PERIOD_START]
)
}
Expand All @@ -206,10 +206,9 @@ open class BlockchainIdentityConfig @Inject constructor(
creditFundingTxId = prefs[ASSET_LOCK_TXID]?.let { Sha256Hash.wrap(it) },
usingInvite = prefs[USING_INVITE] ?: false,
invite = prefs[INVITE_LINK]?.let { InvitationLinkData(Uri.parse(it), false) },
requestedUsername = prefs[REQUESTED_USERNAME],
verificationLink = prefs[REQUESTED_USERNAME_LINK],
cancelledVerificationLink = prefs[CANCELED_REQUESTED_USERNAME_LINK],
usernameRequested = prefs[USERNAME_REQUESTED],
usernameRequested = prefs[USERNAME_REQUESTED]?.let { UsernameRequestStatus.valueOf(it) },
votingPeriodStart = prefs[VOTING_PERIOD_START]
)
}
Expand Down
12 changes: 10 additions & 2 deletions wallet/src/de/schildbach/wallet/database/entity/UsernameRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ data class UsernameRequest(
@PrimaryKey
val requestId: String,
val username: String,
val normalizedLabel: String,
val createdAt: Long,
val identity: String,
val link: String?,
var link: String?,
val votes: Int,
val lockVotes: Int,
val isApproved: Boolean
)
) {
companion object {
fun getRequestId(identity: String, username: String): String {
return String.format("%s %s", identity, username)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +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.callback.WalletSignerCallback
import org.dashj.platform.wallet.IdentityVerifyDocument
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import javax.inject.Inject
Expand All @@ -36,6 +38,7 @@ interface PlatformBroadcastService {
suspend fun broadcastUpdatedProfile(dashPayProfile: DashPayProfile, encryptionKey: KeyParameter): DashPayProfile
suspend fun sendContactRequest(toUserId: String): DashPayContactRequest
suspend fun sendContactRequest(toUserId: String, encryptionKey: KeyParameter): DashPayContactRequest
suspend fun broadcastIdentityVerify(username: String, url: String, encryptionKey: KeyParameter?): IdentityVerifyDocument
}

class PlatformDocumentBroadcastService @Inject constructor(
Expand Down Expand Up @@ -93,6 +96,25 @@ class PlatformDocumentBroadcastService @Inject constructor(
return dashPayContactRequest
}

override suspend fun broadcastIdentityVerify(username: String, url: String, encryptionKey: KeyParameter?): IdentityVerifyDocument {
val blockchainIdentity = platformRepo.blockchainIdentity

// Create Identity Verify
val timer = AnalyticsTimer(analytics, log, AnalyticsConstants.Process.PROCESS_CONTACT_REQUEST_SEND)
val identityVerifyDocument = platform.identityVerify.createForDashDomain(
username,
url,
blockchainIdentity.identity!!,
WalletSignerCallback(walletDataProvider.wallet!!, encryptionKey)
)
timer.logTiming()
log.info("identity verify sent")

log.info("contact request: $identityVerifyDocument")

return identityVerifyDocument
}

@Throws(Exception::class)
override suspend fun broadcastUpdatedProfile(dashPayProfile: DashPayProfile, encryptionKey: KeyParameter): DashPayProfile {
log.info("broadcast profile")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import org.dashj.platform.sdk.platform.Identities
import org.dashj.platform.sdk.platform.Names
import org.dashj.platform.sdk.platform.Platform
import org.dashj.platform.sdk.platform.PlatformStateRepository
import org.dashj.platform.wallet.IdentityVerify
import org.slf4j.LoggerFactory
import javax.inject.Inject

Expand All @@ -52,6 +53,7 @@ interface PlatformService {
val names: Names
val profiles: Profiles
val contactRequests: ContactRequests
val identityVerify: IdentityVerify
val client: DapiClient
val params: NetworkParameters

Expand All @@ -66,6 +68,7 @@ class PlatformServiceImplementation @Inject constructor(
override val platform = Platform(Constants.NETWORK_PARAMETERS)
override val profiles = Profiles(platform)
override val contactRequests = ContactRequests(platform)
override val identityVerify = IdentityVerify(platform)
override val dpp: DashPlatformProtocol = platform.dpp
override val stateRepository: PlatformStateRepository = platform.stateRepository
override val identities: Identities = platform.identities
Expand Down
Loading

0 comments on commit 71d1092

Please sign in to comment.