-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #1368.
- Loading branch information
Showing
9 changed files
with
120 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
backend-lib/src/main/java/cash/z/ecc/android/sdk/internal/model/JniScanSummary.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cash.z.ecc.android.sdk.internal.model | ||
|
||
import androidx.annotation.Keep | ||
import cash.z.ecc.android.sdk.internal.ext.isInUIntRange | ||
|
||
/** | ||
* Serves as cross layer (Kotlin, Rust) communication class. | ||
* | ||
* @param startHeight the minimum height in the scanned range (inclusive). | ||
* Although it's type Long, it needs to be a UInt. | ||
* @param endHeight the maximum height in the scanned range (exclusive). | ||
* Although it's type Long, it needs to be a UInt. | ||
* @param spentSaplingNoteCount the number of Sapling notes detected as spent in | ||
* the scanned range. | ||
* @param receivedSaplingNoteCount the number of Sapling notes detected as | ||
* received in the scanned range. | ||
* @throws IllegalArgumentException unless (startHeight and endHeight are UInts, | ||
* and startHeight is not less than endHeight). | ||
*/ | ||
@Keep | ||
class JniScanSummary( | ||
val startHeight: Long, | ||
val endHeight: Long, | ||
val spentSaplingNoteCount: Long, | ||
val receivedSaplingNoteCount: Long | ||
) { | ||
init { | ||
// We require some of the parameters below to be in the range of | ||
// unsigned integer, because they are block heights. | ||
require(startHeight.isInUIntRange()) { | ||
"Height $startHeight is outside of allowed UInt range" | ||
} | ||
require(endHeight.isInUIntRange()) { | ||
"Height $endHeight is outside of allowed UInt range" | ||
} | ||
require(endHeight >= startHeight) { | ||
"End height $endHeight must be greater than start height $startHeight." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/model/ScanSummary.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cash.z.ecc.android.sdk.internal.model | ||
|
||
import cash.z.ecc.android.sdk.model.BlockHeight | ||
import cash.z.ecc.android.sdk.model.ZcashNetwork | ||
|
||
internal data class ScanSummary( | ||
val scannedRange: ClosedRange<BlockHeight>, | ||
val spentSaplingNoteCount: Long, | ||
val receivedSaplingNoteCount: Long | ||
) { | ||
companion object { | ||
/** | ||
* Note that this function subtracts 1 from [JniScanSummary.endHeight] | ||
* as the rest of the logic works with [ClosedRange] and the endHeight | ||
* is exclusive. | ||
*/ | ||
fun new( | ||
jni: JniScanSummary, | ||
zcashNetwork: ZcashNetwork | ||
): ScanSummary { | ||
return ScanSummary( | ||
scannedRange = BlockHeight.new(zcashNetwork, jni.startHeight)..(BlockHeight.new(zcashNetwork, jni.endHeight) - 1), | ||
spentSaplingNoteCount = jni.spentSaplingNoteCount, | ||
receivedSaplingNoteCount = jni.receivedSaplingNoteCount | ||
) | ||
} | ||
} | ||
} |