Skip to content

Commit

Permalink
Actualize CIS-2 management (#16)
Browse files Browse the repository at this point in the history
- Import the latest CIS-2 management from Concordium
- Fix keeping ever found tokens between contracts
- Show balance/ownership of found tokens
  • Loading branch information
Radiokot authored Mar 26, 2024
1 parent 60131a5 commit f50d00d
Show file tree
Hide file tree
Showing 13 changed files with 625 additions and 377 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
- Support of WalletConnect CCD transfer requests
- Ability to see full details of the WalletConnect transaction to sign
- Support for WalletConnect verifiable presentation requests (for identity proofs)
- Validation of metadata checksum when adding CIS-2 tokens
- Display of balance/ownership when adding CIS-2 tokens

### Fixed

Expand All @@ -21,12 +23,15 @@
- An issue where exporting transaction logs for an account without any transactions would be stuck at 0%
- "Invalid WalletConnect request" message repeatedly shown if received a request with unsupported transaction type
- Exported private key for file-based initial account being incompatible with concordium-client
- Inability to search for CIS-2 token by ID on contracts with lots of tokens
- When managing CIS-2 tokens, removing all of them when only unselecting the visible ones

### Changed
- Suggest running a recovery when facing account or identity creation errors
- Baker/baking renamed to Validator/validating
- WalletConnect session proposals are now rejected if the namespace or methods are not supported, or if the wallet contains no accounts.
- WalletConnect transaction signing request now shows the receiver
(either smart contract or an account) and amount of CCD to send (not including CIS-2 tokens)
- CIS-2 tokens with corrupted or missing metadata can no longer be added

[Unreleased]: https://github.com/Concordium/cryptox-android/compare/0.6.1-qa.5...HEAD
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
package com.concordium.wallet.data.backend

import com.concordium.wallet.data.cryptolib.CreateTransferOutput
import com.concordium.wallet.data.model.*
import com.concordium.wallet.data.model.AccountBalance
import com.concordium.wallet.data.model.AccountKeyData
import com.concordium.wallet.data.model.AccountNonce
import com.concordium.wallet.data.model.AccountSubmissionStatus
import com.concordium.wallet.data.model.AccountTransactions
import com.concordium.wallet.data.model.BakerPoolStatus
import com.concordium.wallet.data.model.CIS2Tokens
import com.concordium.wallet.data.model.CIS2TokensBalances
import com.concordium.wallet.data.model.CIS2TokensMetadata
import com.concordium.wallet.data.model.ChainParameters
import com.concordium.wallet.data.model.CredentialWrapper
import com.concordium.wallet.data.model.GlobalParamsWrapper
import com.concordium.wallet.data.model.IdentityContainer
import com.concordium.wallet.data.model.IdentityProvider
import com.concordium.wallet.data.model.PassiveDelegation
import com.concordium.wallet.data.model.SubmissionData
import com.concordium.wallet.data.model.TransferCost
import com.concordium.wallet.data.model.TransferSubmissionStatus
import retrofit2.Call
import retrofit2.Response
import retrofit2.http.*
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Query

interface ProxyBackend {

Expand Down Expand Up @@ -100,25 +121,25 @@ interface ProxyBackend {
fun getAccountEncryptedKey(@Path("accountAddress") accountAddress: String): Call<AccountKeyData>

@GET("v0/CIS2Tokens/{index}/{subIndex}")
fun cis2Tokens(
suspend fun cis2Tokens(
@Path("index") index: String,
@Path("subIndex") subIndex: String,
@Query("from") from: String? = null,
@Query("limit") limit: Int? = null
): Call<CIS2Tokens>
): CIS2Tokens

@GET("v0/CIS2TokenMetadata/{index}/{subIndex}")
fun cis2TokenMetadata(
@GET("v1/CIS2TokenMetadata/{index}/{subIndex}")
suspend fun cis2TokenMetadataV1(
@Path("index") index: String,
@Path("subIndex") subIndex: String,
@Query("tokenId") tokenId: String
): Call<CIS2TokensMetadata>
): CIS2TokensMetadata

@GET("v0/CIS2TokenBalance/{index}/{subIndex}/{accountAddress}")
fun cis2TokenBalance(
@GET("v1/CIS2TokenBalance/{index}/{subIndex}/{accountAddress}")
suspend fun cis2TokenBalanceV1(
@Path("index") index: String,
@Path("subIndex") subIndex: String,
@Path("accountAddress") accountAddress: String,
@Query("tokenId") tokenId: String
): Call<CIS2TokensBalances>
): CIS2TokensBalances
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class ProxyRepository {
const val REMOVE_BAKER = "removeBaker"
const val CONFIGURE_BAKER = "configureBaker"
const val UPDATE = "update"

const val CIS_2_TOKEN_BALANCE_MAX_TOKEN_IDS = 20
const val CIS_2_TOKEN_METADATA_MAX_TOKEN_IDS = 20
}

fun submitCredential(
Expand All @@ -67,7 +70,8 @@ class ProxyRepository {
)
}

suspend fun getAccountSubmissionStatusSuspended(submissionId: String) = backend.accountSubmissionStatusSuspended(submissionId)
suspend fun getAccountSubmissionStatusSuspended(submissionId: String) =
backend.accountSubmissionStatusSuspended(submissionId)

fun getAccountSubmissionStatus(
submissionId: String,
Expand Down Expand Up @@ -143,7 +147,8 @@ class ProxyRepository {
)
}

suspend fun getTransferSubmissionStatusSuspended(submissionId: String) = backend.transferSubmissionStatusSuspended(submissionId)
suspend fun getTransferSubmissionStatusSuspended(submissionId: String) =
backend.transferSubmissionStatusSuspended(submissionId)

fun getTransferSubmissionStatus(
submissionId: String,
Expand All @@ -169,29 +174,47 @@ class ProxyRepository {
)
}

fun getTransferCost(type: String,
memoSize: Int? = null,
amount: BigInteger? = null,
restake: Boolean? = null,
lPool: Boolean? = null,
targetChange: Boolean? = null,
metadataSize: Int? = null,
openStatus: String? = null,
sender: String? = null,
contractIndex: Int? = null,
contractSubindex: Int? = null,
receiveName: String? = null,
parameter: String? = null,
executionNRGBuffer: Int? = null,
success: (TransferCost) -> Unit,
failure: ((Throwable) -> Unit)?): BackendRequest<TransferCost> {
fun getTransferCost(
type: String,
memoSize: Int? = null,
amount: BigInteger? = null,
restake: Boolean? = null,
lPool: Boolean? = null,
targetChange: Boolean? = null,
metadataSize: Int? = null,
openStatus: String? = null,
sender: String? = null,
contractIndex: Int? = null,
contractSubindex: Int? = null,
receiveName: String? = null,
parameter: String? = null,
executionNRGBuffer: Int? = null,
success: (TransferCost) -> Unit,
failure: ((Throwable) -> Unit)?
): BackendRequest<TransferCost> {
val lPoolArg = if (lPool == true) "lPool" else null
val targetArg = if (targetChange == true) "target" else null
val call = backend.transferCost(type, memoSize, amount?.toString(), restake, lPoolArg, targetArg, metadataSize, openStatus, sender, contractIndex, contractSubindex, receiveName, parameter, executionNRGBuffer)
val call = backend.transferCost(
type,
memoSize,
amount?.toString(),
restake,
lPoolArg,
targetArg,
metadataSize,
openStatus,
sender,
contractIndex,
contractSubindex,
receiveName,
parameter,
executionNRGBuffer
)
call.enqueue(object : BackendCallback<TransferCost>() {
override fun onResponseData(response: TransferCost) {
success(response)
}

override fun onFailure(t: Throwable) {
failure?.invoke(t)
}
Expand Down Expand Up @@ -252,7 +275,8 @@ class ProxyRepository {

suspend fun getBakerPoolSuspended(poolId: String) = backend.bakerPoolSuspended(poolId)

suspend fun getAccountBalanceSuspended(accountAddress: String) = backend.accountBalanceSuspended(accountAddress)
suspend fun getAccountBalanceSuspended(accountAddress: String) =
backend.accountBalanceSuspended(accountAddress)

fun getAccountBalance(
accountAddress: String,
Expand Down Expand Up @@ -377,74 +401,33 @@ class ProxyRepository {
)
}

fun getCIS2Tokens(
suspend fun getCIS2Tokens(
index: String,
subIndex: String,
from: String? = null,
limit: Int? = null,
success: (CIS2Tokens) -> Unit,
failure: ((Throwable) -> Unit)?
): BackendRequest<CIS2Tokens> {
val call = backend.cis2Tokens(index, subIndex, from, limit)
call.enqueue(object : BackendCallback<CIS2Tokens>() {
override fun onResponseData(response: CIS2Tokens) {
success(response)
}
override fun onFailure(t: Throwable) {
failure?.invoke(t)
}
})
return BackendRequest(
call = call,
success = success,
failure = failure
)
}

fun getCIS2TokenMetadata(
): CIS2Tokens = backend.cis2Tokens(index, subIndex, from, limit)

/**
* @param tokenIds comma-separated token IDs, but no more than [CIS_2_TOKEN_METADATA_MAX_TOKEN_IDS]
*
* @return metadata items for tokens having it
*/
suspend fun getCIS2TokenMetadataV1(
index: String,
subIndex: String,
tokenIds: String,
success: (CIS2TokensMetadata) -> Unit,
failure: ((Throwable) -> Unit)?
): BackendRequest<CIS2TokensMetadata> {
val call = backend.cis2TokenMetadata(index, subIndex, tokenIds)
call.enqueue(object : BackendCallback<CIS2TokensMetadata>() {
override fun onResponseData(response: CIS2TokensMetadata) {
success(response)
}
override fun onFailure(t: Throwable) {
failure?.invoke(t)
}
})
return BackendRequest(
call = call,
success = success,
failure = failure
)
}
): CIS2TokensMetadata = backend.cis2TokenMetadataV1(index, subIndex, tokenIds)

/**
* @param tokenIds comma-separated token IDs, but no more than [CIS_2_TOKEN_BALANCE_MAX_TOKEN_IDS]
fun getCIS2TokenBalance(
* @return balance items for tokens having it
*/
suspend fun getCIS2TokenBalanceV1(
index: String,
subIndex: String,
accountAddress: String,
tokenIds: String,
success: (CIS2TokensBalances) -> Unit,
failure: ((Throwable) -> Unit)?
): BackendRequest<CIS2TokensBalances> {
val call = backend.cis2TokenBalance(index, subIndex, accountAddress, tokenIds)
call.enqueue(object : BackendCallback<CIS2TokensBalances>() {
override fun onResponseData(response: CIS2TokensBalances) {
success(response)
}
override fun onFailure(t: Throwable) {
failure?.invoke(t)
}
})
return BackendRequest(
call = call,
success = success,
failure = failure
)
}
): CIS2TokensBalances = backend.cis2TokenBalanceV1(index, subIndex, accountAddress, tokenIds)
}
Loading

0 comments on commit f50d00d

Please sign in to comment.