Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 24 additions & 35 deletions backend-lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions backend-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ rust-version = "1.92"

[dependencies]
# Zcash dependencies
orchard = "0.11"
orchard = "0.12"
pczt = { version = "0.5", features = ["prover", "orchard", "sapling"] }
sapling = { package = "sapling-crypto", version = "0.5", default-features = false }
sapling = { package = "sapling-crypto", version = "0.6", default-features = false }
transparent = { package = "zcash_transparent", version = "0.6", default-features = false }
zcash_address = "0.10"
zcash_client_backend = { version = "0.21", features = [
Expand Down Expand Up @@ -96,6 +96,16 @@ xz2 = { version = "0.1", features = ["static"] }
#zcash_proofs = { git = "https://github.com/zcash/librustzcash", branch = "main" }
#zcash_protocol = { git = "https://github.com/zcash/librustzcash", branch = "main" }

[patch.crates-io]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is marked as draft; it must not be merged until this patch is removed after the next zcash_client_sqlite release.

pczt = { git = "https://github.com/zcash/librustzcash.git", rev = "5bff17ef8a7283bd6e9e87c77689541ef15e0784" }
transparent = { package = "zcash_transparent", git = "https://github.com/zcash/librustzcash", rev = "5bff17ef8a7283bd6e9e87c77689541ef15e0784" }
zcash_address = { git = "https://github.com/zcash/librustzcash", rev = "5bff17ef8a7283bd6e9e87c77689541ef15e0784" }
zcash_client_backend = { git = "https://github.com/zcash/librustzcash", rev = "5bff17ef8a7283bd6e9e87c77689541ef15e0784" }
zcash_client_sqlite = { git = "https://github.com/zcash/librustzcash", rev = "5bff17ef8a7283bd6e9e87c77689541ef15e0784" }
zcash_primitives = { git = "https://github.com/zcash/librustzcash", rev = "5bff17ef8a7283bd6e9e87c77689541ef15e0784" }
zcash_proofs = { git = "https://github.com/zcash/librustzcash", rev = "5bff17ef8a7283bd6e9e87c77689541ef15e0784" }
zcash_protocol = { git = "https://github.com/zcash/librustzcash", rev = "5bff17ef8a7283bd6e9e87c77689541ef15e0784" }

[lib]
name = "zcashwalletsdk"
path = "src/main/rust/lib.rs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cash.z.ecc.android.sdk.internal
import cash.z.ecc.android.sdk.internal.model.JniAccount
import cash.z.ecc.android.sdk.internal.model.JniAccountUsk
import cash.z.ecc.android.sdk.internal.model.JniBlockMeta
import cash.z.ecc.android.sdk.internal.model.JniReceivedTransactionOutput
import cash.z.ecc.android.sdk.internal.model.JniRewindResult
import cash.z.ecc.android.sdk.internal.model.JniScanRange
import cash.z.ecc.android.sdk.internal.model.JniScanSummary
Expand Down Expand Up @@ -217,6 +218,14 @@ interface Backend {

fun getBranchIdForHeight(height: Long): Long

/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun getReceivedTransactionOutputs(
txId: ByteArray,
): List<JniReceivedTransactionOutput>

/**
* @throws RuntimeException as a common indicator of the operation failure
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import cash.z.ecc.android.sdk.internal.Backend
import cash.z.ecc.android.sdk.internal.model.JniAccount
import cash.z.ecc.android.sdk.internal.model.JniAccountUsk
import cash.z.ecc.android.sdk.internal.model.JniBlockMeta
import cash.z.ecc.android.sdk.internal.model.JniReceivedTransactionOutput
import cash.z.ecc.android.sdk.internal.model.JniRewindResult
import cash.z.ecc.android.sdk.internal.model.JniScanRange
import cash.z.ecc.android.sdk.internal.model.JniSingleUseTransparentAddress
Expand Down Expand Up @@ -236,6 +237,12 @@ class FakeRustBackend(
error("Intentionally not implemented yet.")
}

override suspend fun getReceivedTransactionOutputs(
txId: ByteArray,
): List<JniReceivedTransactionOutput> {
error("Intentionally not implemented yet.")
}

override suspend fun getMemoAsUtf8(
txId: ByteArray,
protocol: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import cash.z.ecc.android.sdk.internal.ext.deleteSuspend
import cash.z.ecc.android.sdk.internal.model.JniAccount
import cash.z.ecc.android.sdk.internal.model.JniAccountUsk
import cash.z.ecc.android.sdk.internal.model.JniBlockMeta
import cash.z.ecc.android.sdk.internal.model.JniReceivedTransactionOutput
import cash.z.ecc.android.sdk.internal.model.JniRewindResult
import cash.z.ecc.android.sdk.internal.model.JniScanRange
import cash.z.ecc.android.sdk.internal.model.JniScanSummary
Expand Down Expand Up @@ -194,6 +195,17 @@ class RustBackend private constructor(
).asList()
}

override suspend fun getReceivedTransactionOutputs(
txId: ByteArray,
): List<JniReceivedTransactionOutput> =
withContext(SdkDispatchers.DATABASE_IO) {
getReceivedTransactionOutputs(
dataDbFile.absolutePath,
networkId = networkId,
txId,
).asList()
}

override suspend fun getMemoAsUtf8(
txId: ByteArray,
protocol: Int,
Expand Down Expand Up @@ -704,6 +716,13 @@ class RustBackend private constructor(
networkId: Int
): Long

@JvmStatic
private external fun getReceivedTransactionOutputs(
dbDataPath: String,
networkId: Int,
txId: ByteArray,
): Array<JniReceivedTransactionOutput>

@JvmStatic
private external fun getMemoAsUtf8(
dbDataPath: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package cash.z.ecc.android.sdk.internal.model

import androidx.annotation.Keep
import cash.z.ecc.android.sdk.internal.ext.isInUIntRange

/**
* High-level information about the output of a transaction received by the
* wallet.
*
* This type is capable of representing both shielded and transparent outputs.
* It does not internally store the transaction ID, so it must be interpreted in
* the context of a caller having requested output information for a specific
* transaction.
*
* Serves as cross layer (Kotlin, Rust) communication class.
*
* @param poolType The pool in which the output was received.
* @param outputIndex The index of the output among the transaction's outputs to
* the associated pool.
* @param value The value of the output.
* @param confirmationsUntilSpendable The number of confirmations required for
* the output to be treated as spendable,.
* @throws IllegalArgumentException if the values are inconsistent.
*/
@Keep
@Suppress("LongParameterList")
class JniReceivedTransactionOutput(
val poolType: Int,
val outputIndex: Int,
val value: Long,
val confirmationsUntilSpendable: Long,
) {
init {
require(poolType >= 0) {
"Pool type $poolType must be non-negative"
}
require(outputIndex >= 0) {
"Output index $outputIndex must be non-negative"
}
require(value >= 0L) {
"Value $value must be non-negative"
}
require(confirmationsUntilSpendable.isInUIntRange()) {
"Confirmations until spendable $confirmationsUntilSpendable must be a UInt"
}
}
}
Loading