Skip to content

Commit

Permalink
Merge pull request #1639 from Electric-Coin-Company/1638-fix-account-bug
Browse files Browse the repository at this point in the history
Fix bug in new `getAccounts` method
  • Loading branch information
str4d authored Nov 22, 2024
2 parents 711bb1c + 15f46f8 commit e9a822f
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface Backend {
suspend fun initBlockMetaDb(): Int

suspend fun proposeTransfer(
account: Int,
accountIndex: Int,
to: String,
value: Long,
memo: ByteArray? = null
Expand All @@ -35,12 +35,12 @@ interface Backend {
*/
@Throws(RuntimeException::class)
suspend fun proposeTransferFromUri(
account: Int,
accountIndex: Int,
uri: String
): ProposalUnsafe

suspend fun proposeShielding(
account: Int,
accountIndex: Int,
shieldingThreshold: Long,
memo: ByteArray? = null,
transparentReceiver: String? = null
Expand Down Expand Up @@ -109,13 +109,13 @@ interface Backend {
fun isValidTexAddr(addr: String): Boolean

@Throws(RuntimeException::class)
suspend fun getCurrentAddress(account: Int): String
suspend fun getCurrentAddress(accountIndex: Int): String

fun getTransparentReceiver(ua: String): String?

fun getSaplingReceiver(ua: String): String?

suspend fun listTransparentReceivers(account: Int): List<String>
suspend fun listTransparentReceivers(accountIndex: Int): List<String>

fun getBranchIdForHeight(height: Long): Long

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ class RustBackend private constructor(
)
}

override suspend fun getCurrentAddress(account: Int) =
override suspend fun getCurrentAddress(accountIndex: Int) =
withContext(SdkDispatchers.DATABASE_IO) {
getCurrentAddress(
dataDbFile.absolutePath,
account,
accountIndex,
networkId = networkId
)
}
Expand All @@ -127,11 +127,11 @@ class RustBackend private constructor(

override fun getSaplingReceiver(ua: String) = getSaplingReceiverForUnifiedAddress(ua)

override suspend fun listTransparentReceivers(account: Int): List<String> {
override suspend fun listTransparentReceivers(accountIndex: Int): List<String> {
return withContext(SdkDispatchers.DATABASE_IO) {
listTransparentReceivers(
dbDataPath = dataDbFile.absolutePath,
account = account,
accountIndex = accountIndex,
networkId = networkId
).asList()
}
Expand Down Expand Up @@ -318,22 +318,22 @@ class RustBackend private constructor(
}

override suspend fun proposeTransferFromUri(
account: Int,
accountIndex: Int,
uri: String
): ProposalUnsafe =
withContext(SdkDispatchers.DATABASE_IO) {
ProposalUnsafe.parse(
proposeTransferFromUri(
dataDbFile.absolutePath,
account,
accountIndex,
uri,
networkId = networkId,
)
)
}

override suspend fun proposeTransfer(
account: Int,
accountIndex: Int,
to: String,
value: Long,
memo: ByteArray?
Expand All @@ -342,7 +342,7 @@ class RustBackend private constructor(
ProposalUnsafe.parse(
proposeTransfer(
dataDbFile.absolutePath,
account,
accountIndex,
to,
value,
memo,
Expand All @@ -352,15 +352,15 @@ class RustBackend private constructor(
}

override suspend fun proposeShielding(
account: Int,
accountIndex: Int,
shieldingThreshold: Long,
memo: ByteArray?,
transparentReceiver: String?
): ProposalUnsafe? {
return withContext(SdkDispatchers.DATABASE_IO) {
proposeShielding(
dataDbFile.absolutePath,
account,
accountIndex,
shieldingThreshold,
memo,
transparentReceiver,
Expand Down Expand Up @@ -510,7 +510,7 @@ class RustBackend private constructor(
@JvmStatic
private external fun getCurrentAddress(
dbDataPath: String,
account: Int,
accountIndex: Int,
networkId: Int
): String

Expand All @@ -523,7 +523,7 @@ class RustBackend private constructor(
@JvmStatic
private external fun listTransparentReceivers(
dbDataPath: String,
account: Int,
accountIndex: Int,
networkId: Int
): Array<String>

Expand Down Expand Up @@ -671,7 +671,7 @@ class RustBackend private constructor(
@JvmStatic
private external fun proposeTransferFromUri(
dbDataPath: String,
account: Int,
accountIndex: Int,
uri: String,
networkId: Int,
): ByteArray
Expand All @@ -680,7 +680,7 @@ class RustBackend private constructor(
@Suppress("LongParameterList")
private external fun proposeTransfer(
dbDataPath: String,
account: Int,
accountIndex: Int,
to: String,
value: Long,
memo: ByteArray?,
Expand All @@ -691,7 +691,7 @@ class RustBackend private constructor(
@Suppress("LongParameterList")
private external fun proposeShielding(
dbDataPath: String,
account: Int,
accountIndex: Int,
shieldingThreshold: Long,
memo: ByteArray?,
transparentReceiver: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class RustDerivationTool private constructor() : Derivation {
@JvmStatic
private external fun deriveSpendingKey(
seed: ByteArray,
account: Int,
accountIndex: Int,
networkId: Int
): JniUnifiedSpendingKey

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import androidx.annotation.Keep
/**
* Serves as cross layer (Kotlin, Rust) communication class.
*
* @param account the account ID
* @param accountIndex the ZIP 32 account index.
* @param ufvk The account's Unified Full Viewing Key, if any.
* @throws IllegalArgumentException if the values are inconsistent.
*/
@Keep
@Suppress("LongParameterList")
class JniAccount(
val accountId: Long,
val accountIndex: Int,
val ufvk: String?,
) {
init {
require(accountId >= 0) {
"Account ID must be non-negative"
require(accountIndex >= 0) {
"Account index must be non-negative"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import androidx.annotation.Keep
*/
@Keep
class JniUnifiedSpendingKey(
/**
* The [ZIP 32](https://zips.z.cash/zip-0032) account index used to derive this key.
*/
val account: Int,
/**
* The binary encoding of the [ZIP 316](https://zips.z.cash/zip-0316) Unified Spending
Expand Down
Loading

0 comments on commit e9a822f

Please sign in to comment.