zcash-android-wallet-sdk/sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/Proposal.kt

59 lines
1.6 KiB
Kotlin
Raw Normal View History

package cash.z.ecc.android.sdk.model
import cash.z.ecc.android.sdk.internal.model.ProposalUnsafe
/**
* A transaction proposal created by the Rust backend in response to a Kotlin request.
*
* @param inner the type-unsafe Proposal protobuf received across the FFI.
*/
class Proposal(
private val inner: ProposalUnsafe
) {
companion object {
/**
* @throws IllegalArgumentException if the proposal is invalid.
*/
@Throws(IllegalArgumentException::class)
fun fromUnsafe(proposal: ProposalUnsafe): Proposal {
val typed = Proposal(proposal)
// Check for type errors eagerly, to ensure that the caller won't
// encounter these errors later.
typed.totalFeeRequired()
return typed
}
}
/**
* Exposes the type-unsafe proposal variant for passing across the FFI.
*/
fun toUnsafe(): ProposalUnsafe {
return inner
}
2024-03-07 11:49:18 -08:00
/**
* Returns the number of transactions that this proposal will create.
*
* This is equal to the number of `TransactionSubmitResult`s that will be returned
* from `Synchronizer.createProposedTransactions`.
*
* Proposals always create at least one transaction.
*/
fun transactionCount(): Int {
return inner.transactionCount()
}
/**
* Returns the total fee required by this proposal for its transactions.
*/
fun totalFeeRequired(): Zatoshi {
return Zatoshi(inner.totalFeeRequired())
}
fun toPrettyString(): String {
return "Transaction count: ${transactionCount()}, Total fee required: ${totalFeeRequired()}"
}
}