-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide the pool type when retrieving a memo. (#1436)
* WIP: Provide the pool type when retrieving a memo. * Gitignore new idea file * Let TypesafeBackend work with typesafe class * Query and use protocol for memo obtaining --------- Co-authored-by: Honza <rychnovsky.honza@gmail.com>
- Loading branch information
Showing
13 changed files
with
132 additions
and
20 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
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
41 changes: 41 additions & 0 deletions
41
backend-lib/src/main/java/cash/z/ecc/android/sdk/internal/model/ZcashProtocol.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,41 @@ | ||
package cash.z.ecc.android.sdk.internal.model | ||
|
||
/** | ||
* An enumeration of supported Zcash protocols. | ||
*/ | ||
@Suppress("MagicNumber") | ||
enum class ZcashProtocol { | ||
TRANSPARENT { | ||
override val poolCode = 0 | ||
}, | ||
SAPLING { | ||
override val poolCode = 2 | ||
}, | ||
ORCHARD { | ||
override val poolCode = 3 | ||
}; | ||
|
||
abstract val poolCode: Int | ||
|
||
fun isShielded() = this == SAPLING || this == ORCHARD | ||
|
||
companion object { | ||
fun validate(poolTypeCode: Int): Boolean { | ||
return when (poolTypeCode) { | ||
TRANSPARENT.poolCode, | ||
SAPLING.poolCode, | ||
ORCHARD.poolCode -> true | ||
else -> false | ||
} | ||
} | ||
|
||
fun fromPoolType(poolCode: Int): ZcashProtocol { | ||
return when (poolCode) { | ||
TRANSPARENT.poolCode -> TRANSPARENT | ||
SAPLING.poolCode -> SAPLING | ||
ORCHARD.poolCode -> ORCHARD | ||
else -> error("Unsupported pool type: $poolCode") | ||
} | ||
} | ||
} | ||
} |
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
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
25 changes: 25 additions & 0 deletions
25
sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/model/OutputProperties.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,25 @@ | ||
package cash.z.ecc.android.sdk.internal.model | ||
|
||
/** | ||
* Typesafe model class representing different properties from [TxOutputsView] | ||
*/ | ||
internal class OutputProperties( | ||
val index: Int, | ||
val protocol: ZcashProtocol | ||
) { | ||
companion object { | ||
fun new( | ||
index: Int, | ||
poolType: Int | ||
): OutputProperties { | ||
require(index >= 0) { "Output index: $index must be greater or equal to zero" } | ||
|
||
require(ZcashProtocol.validate(poolType)) { "Output poolType: $poolType unknown" } | ||
|
||
return OutputProperties( | ||
index = index, | ||
protocol = ZcashProtocol.fromPoolType(poolType) | ||
) | ||
} | ||
} | ||
} |
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