2024-01-08 15:02:52 -08:00
|
|
|
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.
|
2024-03-01 10:51:54 -08:00
|
|
|
typed.totalFeeRequired()
|
2024-01-08 15:02:52 -08:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2024-01-08 15:02:52 -08:00
|
|
|
/**
|
2024-03-01 10:51:54 -08:00
|
|
|
* Returns the total fee required by this proposal for its transactions.
|
2024-01-08 15:02:52 -08:00
|
|
|
*/
|
2024-03-01 10:51:54 -08:00
|
|
|
fun totalFeeRequired(): Zatoshi {
|
|
|
|
return Zatoshi(inner.totalFeeRequired())
|
2024-01-08 15:02:52 -08:00
|
|
|
}
|
2024-03-13 02:03:53 -07:00
|
|
|
|
|
|
|
fun toPrettyString(): String {
|
|
|
|
return "Transaction count: ${transactionCount()}, Total fee required: ${totalFeeRequired()}"
|
|
|
|
}
|
2024-01-08 15:02:52 -08:00
|
|
|
}
|