[#753] Add API for querying recipients
This commit is contained in:
parent
9af6986e43
commit
61f1c1a9cb
|
@ -10,6 +10,7 @@ Change Log
|
|||
- `Synchronizer.getLegacyTransparentAddress`
|
||||
- `Synchronizer.isValidUnifiedAddr`
|
||||
- `Synchronizer.getMemos(TransactionOverview)`
|
||||
- `Synchronizer.getReceipients(TransactionOverview)`
|
||||
- `cash.z.ecc.android.sdk.model`:
|
||||
- `Account`
|
||||
- `FirstClassByteArray`
|
||||
|
|
|
@ -16,6 +16,8 @@ For SDK clients that store the key separately from the mnemonic, the migration m
|
|||
provided that they can be rederived from the mnemonic.
|
||||
* Re-generate the key from the mnemonic using `DerivationTool.deriveUnifiedFullViewingKeys`
|
||||
|
||||
Due to internal changes in the SDK, the way transactions are queried and represented works differently. The previous ConfirmedTransaction object has been replaced with `TransactionOverview` which contains less information. Missing fields, such as memos and recipients, can be queried with `Synchronizer.getMemos(TransactionOverview)` and `Synchronizer.getReceipients(TransactionOverview)`.
|
||||
|
||||
Migration to Version 1.9
|
||||
--------------------------------------
|
||||
`ZcashNetwork` is no longer an enum. The prior enum values are now declared as object properties `ZcashNetwork.Mainnet` and `ZcashNetwork.Testnet`. For the most part, this change should have minimal impact. ZcashNetwork was also moved from the package `cash.z.ecc.android.sdk.type` to `cash.z.ecc.android.sdk.model`, which will require a change to your import statements. The server fields have been removed from `ZcashNetwork`, allowing server and network configuration to be done independently.
|
||||
|
|
|
@ -339,6 +339,12 @@ class SdkSynchronizer internal constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun getRecipients(transactionOverview: TransactionOverview): Flow<TransactionRecipient> {
|
||||
require(transactionOverview.isSentTransaction) { "Recipients can only be queried for sent transactions" }
|
||||
|
||||
return storage.getRecipients(transactionOverview.id)
|
||||
}
|
||||
|
||||
//
|
||||
// Storage APIs
|
||||
//
|
||||
|
|
|
@ -11,6 +11,7 @@ import cash.z.ecc.android.sdk.model.LightWalletEndpoint
|
|||
import cash.z.ecc.android.sdk.model.PendingTransaction
|
||||
import cash.z.ecc.android.sdk.model.Transaction
|
||||
import cash.z.ecc.android.sdk.model.TransactionOverview
|
||||
import cash.z.ecc.android.sdk.model.TransactionRecipient
|
||||
import cash.z.ecc.android.sdk.model.UnifiedSpendingKey
|
||||
import cash.z.ecc.android.sdk.model.WalletBalance
|
||||
import cash.z.ecc.android.sdk.model.Zatoshi
|
||||
|
@ -364,6 +365,11 @@ interface Synchronizer {
|
|||
*/
|
||||
fun getMemos(transactionOverview: TransactionOverview): Flow<String>
|
||||
|
||||
/**
|
||||
* Returns a list of recipients for a transaction.
|
||||
*/
|
||||
fun getRecipients(transactionOverview: TransactionOverview): Flow<TransactionRecipient>
|
||||
|
||||
//
|
||||
// Error Handling
|
||||
//
|
||||
|
|
|
@ -5,6 +5,7 @@ import cash.z.ecc.android.sdk.internal.repository.DerivedDataRepository
|
|||
import cash.z.ecc.android.sdk.model.BlockHeight
|
||||
import cash.z.ecc.android.sdk.model.Transaction
|
||||
import cash.z.ecc.android.sdk.model.TransactionOverview
|
||||
import cash.z.ecc.android.sdk.model.TransactionRecipient
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
@ -64,6 +65,9 @@ internal class DbDerivedDataRepository(
|
|||
get() = invalidatingFlow.map { derivedDataDb.allTransactionView.getAllTransactions().toList() }
|
||||
|
||||
override fun getSentNoteIds(transactionId: Long) = derivedDataDb.sentNotesTable.getSentNoteIds(transactionId)
|
||||
override fun getRecipients(transactionId: Long): Flow<TransactionRecipient> {
|
||||
return derivedDataDb.sentNotesTable.getRecipients(transactionId)
|
||||
}
|
||||
|
||||
override fun getReceivedNoteIds(transactionId: Long) =
|
||||
derivedDataDb.receivedNotesTable.getReceivedNoteIds(transactionId)
|
||||
|
|
|
@ -2,6 +2,8 @@ package cash.z.ecc.android.sdk.internal.db.derived
|
|||
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import cash.z.ecc.android.sdk.internal.db.queryAndMap
|
||||
import cash.z.ecc.android.sdk.model.Account
|
||||
import cash.z.ecc.android.sdk.model.TransactionRecipient
|
||||
import cash.z.ecc.android.sdk.model.ZcashNetwork
|
||||
import java.util.Locale
|
||||
|
||||
|
@ -20,6 +22,11 @@ internal class SentNoteTable(
|
|||
|
||||
private val PROJECTION_ID = arrayOf(SentNoteTableDefinition.COLUMN_INTEGER_ID)
|
||||
|
||||
private val PROJECTION_RECIPIENT = arrayOf(
|
||||
SentNoteTableDefinition.COLUMN_STRING_TO_ADDRESS,
|
||||
SentNoteTableDefinition.COLUMN_INTEGER_TO_ACCOUNT
|
||||
)
|
||||
|
||||
private val SELECT_BY_TRANSACTION_ID = String.format(
|
||||
Locale.ROOT,
|
||||
"%s = ?", // $NON-NLS
|
||||
|
@ -40,6 +47,25 @@ internal class SentNoteTable(
|
|||
it.getLong(idColumnIndex)
|
||||
}
|
||||
)
|
||||
|
||||
fun getRecipients(transactionId: Long) =
|
||||
sqliteDatabase.queryAndMap(
|
||||
table = SentNoteTableDefinition.TABLE_NAME,
|
||||
columns = PROJECTION_RECIPIENT,
|
||||
selection = SELECT_BY_TRANSACTION_ID,
|
||||
selectionArgs = arrayOf(transactionId),
|
||||
orderBy = ORDER_BY,
|
||||
cursorParser = {
|
||||
val toAccountIndex = it.getColumnIndex(SentNoteTableDefinition.COLUMN_INTEGER_TO_ACCOUNT)
|
||||
val toAddressIndex = it.getColumnIndex(SentNoteTableDefinition.COLUMN_STRING_TO_ADDRESS)
|
||||
|
||||
if (!it.isNull(toAccountIndex)) {
|
||||
TransactionRecipient.Account(Account(it.getInt(toAccountIndex)))
|
||||
} else {
|
||||
TransactionRecipient.Address(it.getString(toAddressIndex))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
// https://github.com/zcash/librustzcash/blob/277d07c79c7a08907b05a6b29730b74cdb238b97/zcash_client_sqlite/src/wallet/init.rs#L393
|
||||
|
|
|
@ -4,6 +4,7 @@ import cash.z.ecc.android.sdk.internal.model.EncodedTransaction
|
|||
import cash.z.ecc.android.sdk.model.BlockHeight
|
||||
import cash.z.ecc.android.sdk.model.Transaction
|
||||
import cash.z.ecc.android.sdk.model.TransactionOverview
|
||||
import cash.z.ecc.android.sdk.model.TransactionRecipient
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
/**
|
||||
|
@ -106,6 +107,8 @@ internal interface DerivedDataRepository {
|
|||
|
||||
fun getSentNoteIds(transactionId: Long): Flow<Long>
|
||||
|
||||
fun getRecipients(transactionId: Long): Flow<TransactionRecipient>
|
||||
|
||||
fun getReceivedNoteIds(transactionId: Long): Flow<Long>
|
||||
|
||||
suspend fun close()
|
||||
|
|
Loading…
Reference in New Issue