-
Notifications
You must be signed in to change notification settings - Fork 27
Replace Backend.{createToAddress, shieldToAddress} with proposal-based methods
#1344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package cash.z.ecc.android.sdk.internal.model | ||
|
|
||
| import cash.z.wallet.sdk.internal.ffi.ProposalOuterClass.FeeRule | ||
| import cash.z.wallet.sdk.internal.ffi.ProposalOuterClass.Proposal | ||
|
|
||
| /** | ||
| * A transaction proposal created by the Rust backend in response to a Kotlin request. | ||
| * | ||
| * @param inner the parsed Proposal protobuf received across the FFI. | ||
| */ | ||
| class ProposalUnsafe( | ||
| private val inner: Proposal | ||
| ) { | ||
| init { | ||
| require(inner.feeRule != FeeRule.FeeRuleNotSpecified) { | ||
| "Fee rule must be specified" | ||
| } | ||
| } | ||
|
|
||
| companion object { | ||
| /** | ||
| * Parses a Proposal protobuf received across the FFI. | ||
| * | ||
| * @throws com.google.protobuf.InvalidProtocolBufferException | ||
| */ | ||
| @Throws(com.google.protobuf.InvalidProtocolBufferException::class) | ||
| fun parse(encoded: ByteArray): ProposalUnsafe { | ||
| val inner = Proposal.parseFrom(encoded) | ||
|
str4d marked this conversation as resolved.
|
||
| return ProposalUnsafe(inner) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Despite this being called
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is the way we do it with the other models as well. |
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Serializes this proposal for passing back across the FFI. | ||
| */ | ||
| fun toByteArray(): ByteArray { | ||
| return inner.toByteArray() | ||
| } | ||
|
|
||
| /** | ||
| * Returns the fee required by this proposal. | ||
| */ | ||
| fun feeRequired(): Long { | ||
| return inner.balance.feeRequired | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Copyright (c) 2023 The Zcash developers | ||
| // Distributed under the MIT software license, see the accompanying | ||
| // file COPYING or https://www.opensource.org/licenses/mit-license.php . | ||
|
|
||
| syntax = "proto3"; | ||
| package cash.z.wallet.sdk.ffi; | ||
| option java_package = "cash.z.wallet.sdk.internal.ffi"; | ||
|
|
||
| // A data structure that describes the inputs to be consumed and outputs to | ||
| // be produced in a proposed transaction. | ||
| message Proposal { | ||
|
str4d marked this conversation as resolved.
|
||
| uint32 protoVersion = 1; | ||
| // ZIP 321 serialized transaction request | ||
| string transactionRequest = 2; | ||
| // The anchor height to be used in creating the transaction, if any. | ||
| // Setting the anchor height to zero will disallow the use of any shielded | ||
| // inputs. | ||
| uint32 anchorHeight = 3; | ||
| // The inputs to be used in creating the transaction. | ||
| repeated ProposedInput inputs = 4; | ||
| // The total value, fee value, and change outputs of the proposed | ||
| // transaction | ||
| TransactionBalance balance = 5; | ||
| // The fee rule used in constructing this proposal | ||
| FeeRule feeRule = 6; | ||
| // The target height for which the proposal was constructed | ||
| // | ||
| // The chain must contain at least this many blocks in order for the proposal to | ||
| // be executed. | ||
| uint32 minTargetHeight = 7; | ||
| // A flag indicating whether the proposal is for a shielding transaction, | ||
| // used for determining which OVK to select for wallet-internal outputs. | ||
| bool isShielding = 8; | ||
| } | ||
|
|
||
| enum ValuePool { | ||
| // Protobuf requires that enums have a zero discriminant as the default | ||
| // value. However, we need to require that a known value pool is selected, | ||
| // and we do not want to fall back to any default, so sending the | ||
| // PoolNotSpecified value will be treated as an error. | ||
| PoolNotSpecified = 0; | ||
| // The transparent value pool (P2SH is not distinguished from P2PKH) | ||
| Transparent = 1; | ||
| // The Sapling value pool | ||
| Sapling = 2; | ||
| // The Orchard value pool | ||
| Orchard = 3; | ||
| } | ||
|
|
||
| // The unique identifier and value for each proposed input. | ||
| message ProposedInput { | ||
| bytes txid = 1; | ||
| ValuePool valuePool = 2; | ||
| uint32 index = 3; | ||
| uint64 value = 4; | ||
| } | ||
|
|
||
| // The fee rule used in constructing a Proposal | ||
| enum FeeRule { | ||
| // Protobuf requires that enums have a zero discriminant as the default | ||
| // value. However, we need to require that a known fee rule is selected, | ||
| // and we do not want to fall back to any default, so sending the | ||
| // FeeRuleNotSpecified value will be treated as an error. | ||
| FeeRuleNotSpecified = 0; | ||
| // 10000 ZAT | ||
| PreZip313 = 1; | ||
| // 1000 ZAT | ||
| Zip313 = 2; | ||
| // MAX(10000, 5000 * logical_actions) ZAT | ||
| Zip317 = 3; | ||
| } | ||
|
|
||
| // The proposed change outputs and fee value. | ||
| message TransactionBalance { | ||
| repeated ChangeValue proposedChange = 1; | ||
| uint64 feeRequired = 2; | ||
| } | ||
|
|
||
| // A proposed change output. If the transparent value pool is selected, | ||
| // the `memo` field must be null. | ||
| message ChangeValue { | ||
| uint64 value = 1; | ||
| ValuePool valuePool = 2; | ||
| MemoBytes memo = 3; | ||
| } | ||
|
|
||
| // An object wrapper for memo bytes, to facilitate representing the | ||
| // `change_memo == None` case. | ||
| message MemoBytes { | ||
| bytes value = 1; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be documented, or is it not exposed to the SDK user?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't intend for it to be exposed to the SDK user, but IDK if I succeeded within Kotlin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not ideal, as the class is still reachable from clients, but this is how we used to with, e.g., jni models too. We're helping ourselves with the
internalin the package.