Expose shielding threshold in `Synchronizer.proposeShielding`
`Synchronizer.shieldFunds` is not altered because it is deprecated.
This commit is contained in:
parent
d2fa400531
commit
e36bbdec7a
|
@ -30,6 +30,7 @@ interface Backend {
|
||||||
|
|
||||||
suspend fun proposeShielding(
|
suspend fun proposeShielding(
|
||||||
account: Int,
|
account: Int,
|
||||||
|
shieldingThreshold: Long,
|
||||||
memo: ByteArray? = byteArrayOf()
|
memo: ByteArray? = byteArrayOf()
|
||||||
): ProposalUnsafe
|
): ProposalUnsafe
|
||||||
|
|
||||||
|
|
|
@ -307,6 +307,7 @@ class RustBackend private constructor(
|
||||||
|
|
||||||
override suspend fun proposeShielding(
|
override suspend fun proposeShielding(
|
||||||
account: Int,
|
account: Int,
|
||||||
|
shieldingThreshold: Long,
|
||||||
memo: ByteArray?
|
memo: ByteArray?
|
||||||
): ProposalUnsafe {
|
): ProposalUnsafe {
|
||||||
return withContext(SdkDispatchers.DATABASE_IO) {
|
return withContext(SdkDispatchers.DATABASE_IO) {
|
||||||
|
@ -314,6 +315,7 @@ class RustBackend private constructor(
|
||||||
proposeShielding(
|
proposeShielding(
|
||||||
dataDbFile.absolutePath,
|
dataDbFile.absolutePath,
|
||||||
account,
|
account,
|
||||||
|
shieldingThreshold,
|
||||||
memo ?: ByteArray(0),
|
memo ?: ByteArray(0),
|
||||||
networkId = networkId,
|
networkId = networkId,
|
||||||
useZip317Fees = IS_USE_ZIP_317_FEES
|
useZip317Fees = IS_USE_ZIP_317_FEES
|
||||||
|
@ -584,6 +586,7 @@ class RustBackend private constructor(
|
||||||
private external fun proposeShielding(
|
private external fun proposeShielding(
|
||||||
dbDataPath: String,
|
dbDataPath: String,
|
||||||
account: Int,
|
account: Int,
|
||||||
|
shieldingThreshold: Long,
|
||||||
memo: ByteArray,
|
memo: ByteArray,
|
||||||
networkId: Int,
|
networkId: Int,
|
||||||
useZip317Fees: Boolean
|
useZip317Fees: Boolean
|
||||||
|
|
|
@ -1480,6 +1480,7 @@ pub extern "C" fn Java_cash_z_ecc_android_sdk_internal_jni_RustBackend_proposeSh
|
||||||
_: JClass<'local>,
|
_: JClass<'local>,
|
||||||
db_data: JString<'local>,
|
db_data: JString<'local>,
|
||||||
account: jint,
|
account: jint,
|
||||||
|
shielding_threshold: jlong,
|
||||||
memo: JByteArray<'local>,
|
memo: JByteArray<'local>,
|
||||||
network_id: jint,
|
network_id: jint,
|
||||||
use_zip317_fees: jboolean,
|
use_zip317_fees: jboolean,
|
||||||
|
@ -1489,6 +1490,8 @@ pub extern "C" fn Java_cash_z_ecc_android_sdk_internal_jni_RustBackend_proposeSh
|
||||||
let network = parse_network(network_id as u32)?;
|
let network = parse_network(network_id as u32)?;
|
||||||
let mut db_data = wallet_db(env, network, db_data)?;
|
let mut db_data = wallet_db(env, network, db_data)?;
|
||||||
let account = account_id_from_jint(account)?;
|
let account = account_id_from_jint(account)?;
|
||||||
|
let shielding_threshold = NonNegativeAmount::from_nonnegative_i64(shielding_threshold)
|
||||||
|
.map_err(|()| format_err!("Invalid shielding threshold, out of range"))?;
|
||||||
let memo_bytes = env.convert_byte_array(memo).unwrap();
|
let memo_bytes = env.convert_byte_array(memo).unwrap();
|
||||||
|
|
||||||
let min_confirmations = 0;
|
let min_confirmations = 0;
|
||||||
|
@ -1520,8 +1523,6 @@ pub extern "C" fn Java_cash_z_ecc_android_sdk_internal_jni_RustBackend_proposeSh
|
||||||
|
|
||||||
let input_selector = zip317_helper(Some(MemoBytes::from(&memo)), use_zip317_fees);
|
let input_selector = zip317_helper(Some(MemoBytes::from(&memo)), use_zip317_fees);
|
||||||
|
|
||||||
let shielding_threshold = NonNegativeAmount::from_u64(100000).unwrap();
|
|
||||||
|
|
||||||
let proposal = propose_shielding::<_, _, _, Infallible>(
|
let proposal = propose_shielding::<_, _, _, Infallible>(
|
||||||
&mut db_data,
|
&mut db_data,
|
||||||
&network,
|
&network,
|
||||||
|
|
|
@ -130,7 +130,7 @@ class TestWallet(
|
||||||
synchronizer.getTransparentBalance(transparentAddress).let { walletBalance ->
|
synchronizer.getTransparentBalance(transparentAddress).let { walletBalance ->
|
||||||
if (walletBalance.value > 0L) {
|
if (walletBalance.value > 0L) {
|
||||||
synchronizer.createProposedTransactions(
|
synchronizer.createProposedTransactions(
|
||||||
synchronizer.proposeShielding(shieldedSpendingKey.account),
|
synchronizer.proposeShielding(shieldedSpendingKey.account, Zatoshi(100000)),
|
||||||
shieldedSpendingKey
|
shieldedSpendingKey
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,7 @@ class GetBalanceFragment : BaseDemoFragment<FragmentGetBalanceBinding>() {
|
||||||
reportTraceEvent(SyncBlockchainBenchmarkTrace.Event.BALANCE_SCREEN_END)
|
reportTraceEvent(SyncBlockchainBenchmarkTrace.Event.BALANCE_SCREEN_END)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("MagicNumber")
|
||||||
override fun onViewCreated(
|
override fun onViewCreated(
|
||||||
view: View,
|
view: View,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
|
@ -68,7 +69,7 @@ class GetBalanceFragment : BaseDemoFragment<FragmentGetBalanceBinding>() {
|
||||||
)
|
)
|
||||||
sharedViewModel.synchronizerFlow.value?.let { synchronizer ->
|
sharedViewModel.synchronizerFlow.value?.let { synchronizer ->
|
||||||
synchronizer.createProposedTransactions(
|
synchronizer.createProposedTransactions(
|
||||||
synchronizer.proposeShielding(usk.account),
|
synchronizer.proposeShielding(usk.account, Zatoshi(100000)),
|
||||||
usk
|
usk
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,6 +217,7 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
||||||
*
|
*
|
||||||
* Observe the result via [sendState].
|
* Observe the result via [sendState].
|
||||||
*/
|
*/
|
||||||
|
@Suppress("MagicNumber")
|
||||||
fun shieldFunds() {
|
fun shieldFunds() {
|
||||||
if (sendState.value is SendState.Sending) {
|
if (sendState.value is SendState.Sending) {
|
||||||
return
|
return
|
||||||
|
@ -230,7 +231,7 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
||||||
val spendingKey = spendingKey.filterNotNull().first()
|
val spendingKey = spendingKey.filterNotNull().first()
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
synchronizer.createProposedTransactions(
|
synchronizer.createProposedTransactions(
|
||||||
synchronizer.proposeShielding(spendingKey.account),
|
synchronizer.proposeShielding(spendingKey.account, Zatoshi(100000)),
|
||||||
spendingKey
|
spendingKey
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,10 @@ class TestWallet(
|
||||||
Twig.debug { "FOUND utxo balance of total: $walletBalance" }
|
Twig.debug { "FOUND utxo balance of total: $walletBalance" }
|
||||||
|
|
||||||
if (walletBalance.value > 0L) {
|
if (walletBalance.value > 0L) {
|
||||||
synchronizer.createProposedTransactions(synchronizer.proposeShielding(spendingKey.account), spendingKey)
|
synchronizer.createProposedTransactions(
|
||||||
|
synchronizer.proposeShielding(spendingKey.account, Zatoshi(100000)),
|
||||||
|
spendingKey
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,7 @@ internal class FakeRustBackend(
|
||||||
|
|
||||||
override suspend fun proposeShielding(
|
override suspend fun proposeShielding(
|
||||||
account: Int,
|
account: Int,
|
||||||
|
shieldingThreshold: Long,
|
||||||
memo: ByteArray?
|
memo: ByteArray?
|
||||||
): ProposalUnsafe {
|
): ProposalUnsafe {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
|
|
|
@ -569,8 +569,9 @@ class SdkSynchronizer private constructor(
|
||||||
@Throws(TransactionEncoderException::class)
|
@Throws(TransactionEncoderException::class)
|
||||||
override suspend fun proposeShielding(
|
override suspend fun proposeShielding(
|
||||||
account: Account,
|
account: Account,
|
||||||
|
shieldingThreshold: Zatoshi,
|
||||||
memo: String
|
memo: String
|
||||||
): Proposal = txManager.proposeShielding(account, memo)
|
): Proposal = txManager.proposeShielding(account, shieldingThreshold, memo)
|
||||||
|
|
||||||
@Throws(TransactionEncoderException::class)
|
@Throws(TransactionEncoderException::class)
|
||||||
override suspend fun createProposedTransactions(
|
override suspend fun createProposedTransactions(
|
||||||
|
@ -635,7 +636,7 @@ class SdkSynchronizer private constructor(
|
||||||
message = "Upcoming SDK 2.1 will create multiple transactions at once for some recipients.",
|
message = "Upcoming SDK 2.1 will create multiple transactions at once for some recipients.",
|
||||||
replaceWith =
|
replaceWith =
|
||||||
ReplaceWith(
|
ReplaceWith(
|
||||||
"createProposedTransactions(proposeShielding(usk.account, memo), usk)"
|
"createProposedTransactions(proposeShielding(usk.account, shieldingThreshold, memo), usk)"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@Throws(TransactionEncoderException::class, TransactionSubmitException::class)
|
@Throws(TransactionEncoderException::class, TransactionSubmitException::class)
|
||||||
|
|
|
@ -190,10 +190,13 @@ interface Synchronizer {
|
||||||
* Creates a proposal for shielding any transparent funds received by the given account.
|
* Creates a proposal for shielding any transparent funds received by the given account.
|
||||||
*
|
*
|
||||||
* @param account the account for which to shield funds.
|
* @param account the account for which to shield funds.
|
||||||
|
* @param shieldingThreshold the minimum transparent balance required before a
|
||||||
|
* proposal will be created.
|
||||||
* @param memo the optional memo to include as part of the proposal's transactions.
|
* @param memo the optional memo to include as part of the proposal's transactions.
|
||||||
*/
|
*/
|
||||||
suspend fun proposeShielding(
|
suspend fun proposeShielding(
|
||||||
account: Account,
|
account: Account,
|
||||||
|
shieldingThreshold: Zatoshi,
|
||||||
memo: String = ZcashSdk.DEFAULT_SHIELD_FUNDS_MEMO_PREFIX
|
memo: String = ZcashSdk.DEFAULT_SHIELD_FUNDS_MEMO_PREFIX
|
||||||
): Proposal
|
): Proposal
|
||||||
|
|
||||||
|
@ -244,7 +247,7 @@ interface Synchronizer {
|
||||||
message = "Upcoming SDK 2.1 will create multiple transactions at once for some recipients.",
|
message = "Upcoming SDK 2.1 will create multiple transactions at once for some recipients.",
|
||||||
replaceWith =
|
replaceWith =
|
||||||
ReplaceWith(
|
ReplaceWith(
|
||||||
"createProposedTransactions(proposeShielding(usk.account, memo), usk)"
|
"createProposedTransactions(proposeShielding(usk.account, shieldingThreshold, memo), usk)"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
suspend fun shieldFunds(
|
suspend fun shieldFunds(
|
||||||
|
|
|
@ -34,6 +34,7 @@ internal interface TypesafeBackend {
|
||||||
|
|
||||||
suspend fun proposeShielding(
|
suspend fun proposeShielding(
|
||||||
account: Account,
|
account: Account,
|
||||||
|
shieldingThreshold: Long,
|
||||||
memo: ByteArray? = byteArrayOf()
|
memo: ByteArray? = byteArrayOf()
|
||||||
): Proposal
|
): Proposal
|
||||||
|
|
||||||
|
|
|
@ -53,11 +53,13 @@ internal class TypesafeBackendImpl(private val backend: Backend) : TypesafeBacke
|
||||||
|
|
||||||
override suspend fun proposeShielding(
|
override suspend fun proposeShielding(
|
||||||
account: Account,
|
account: Account,
|
||||||
|
shieldingThreshold: Long,
|
||||||
memo: ByteArray?
|
memo: ByteArray?
|
||||||
): Proposal =
|
): Proposal =
|
||||||
Proposal.fromUnsafe(
|
Proposal.fromUnsafe(
|
||||||
backend.proposeShielding(
|
backend.proposeShielding(
|
||||||
account.value,
|
account.value,
|
||||||
|
shieldingThreshold,
|
||||||
memo
|
memo
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -56,10 +56,13 @@ internal interface OutboundTransactionManager {
|
||||||
* Creates a proposal for shielding any transparent funds received by the given account.
|
* Creates a proposal for shielding any transparent funds received by the given account.
|
||||||
*
|
*
|
||||||
* @param account the account for which to shield funds.
|
* @param account the account for which to shield funds.
|
||||||
|
* @param shieldingThreshold the minimum transparent balance required before a
|
||||||
|
* proposal will be created.
|
||||||
* @param memo the optional memo to include as part of the proposal's transactions.
|
* @param memo the optional memo to include as part of the proposal's transactions.
|
||||||
*/
|
*/
|
||||||
suspend fun proposeShielding(
|
suspend fun proposeShielding(
|
||||||
account: Account,
|
account: Account,
|
||||||
|
shieldingThreshold: Zatoshi,
|
||||||
memo: String
|
memo: String
|
||||||
): Proposal
|
): Proposal
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,9 @@ internal class OutboundTransactionManagerImpl(
|
||||||
|
|
||||||
override suspend fun proposeShielding(
|
override suspend fun proposeShielding(
|
||||||
account: Account,
|
account: Account,
|
||||||
|
shieldingThreshold: Zatoshi,
|
||||||
memo: String
|
memo: String
|
||||||
): Proposal = encoder.proposeShielding(account, memo.toByteArray())
|
): Proposal = encoder.proposeShielding(account, shieldingThreshold, memo.toByteArray())
|
||||||
|
|
||||||
override suspend fun createProposedTransactions(
|
override suspend fun createProposedTransactions(
|
||||||
proposal: Proposal,
|
proposal: Proposal,
|
||||||
|
|
|
@ -61,10 +61,13 @@ internal interface TransactionEncoder {
|
||||||
* Creates a proposal for shielding any transparent funds sent to the given account.
|
* Creates a proposal for shielding any transparent funds sent to the given account.
|
||||||
*
|
*
|
||||||
* @param account the account for which to shield funds.
|
* @param account the account for which to shield funds.
|
||||||
|
* @param shieldingThreshold the minimum transparent balance required before a
|
||||||
|
* proposal will be created.
|
||||||
* @param memo the optional memo to include as part of the proposal's transactions.
|
* @param memo the optional memo to include as part of the proposal's transactions.
|
||||||
*/
|
*/
|
||||||
suspend fun proposeShielding(
|
suspend fun proposeShielding(
|
||||||
account: Account,
|
account: Account,
|
||||||
|
shieldingThreshold: Zatoshi,
|
||||||
memo: ByteArray? = byteArrayOf()
|
memo: ByteArray? = byteArrayOf()
|
||||||
): Proposal
|
): Proposal
|
||||||
|
|
||||||
|
|
|
@ -96,11 +96,12 @@ internal class TransactionEncoderImpl(
|
||||||
|
|
||||||
override suspend fun proposeShielding(
|
override suspend fun proposeShielding(
|
||||||
account: Account,
|
account: Account,
|
||||||
|
shieldingThreshold: Zatoshi,
|
||||||
memo: ByteArray?
|
memo: ByteArray?
|
||||||
): Proposal {
|
): Proposal {
|
||||||
@Suppress("TooGenericExceptionCaught")
|
@Suppress("TooGenericExceptionCaught")
|
||||||
return try {
|
return try {
|
||||||
backend.proposeShielding(account, memo)
|
backend.proposeShielding(account, shieldingThreshold.value, memo)
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
// TODO [#680]: if this error matches: Insufficient balance (have 0, need 1000 including fee)
|
// TODO [#680]: if this error matches: Insufficient balance (have 0, need 1000 including fee)
|
||||||
// then consider custom error that says no UTXOs existed to shield
|
// then consider custom error that says no UTXOs existed to shield
|
||||||
|
@ -229,6 +230,7 @@ internal class TransactionEncoderImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("MagicNumber")
|
||||||
private suspend fun createShieldingSpend(
|
private suspend fun createShieldingSpend(
|
||||||
usk: UnifiedSpendingKey,
|
usk: UnifiedSpendingKey,
|
||||||
memo: ByteArray? = byteArrayOf()
|
memo: ByteArray? = byteArrayOf()
|
||||||
|
@ -237,7 +239,7 @@ internal class TransactionEncoderImpl(
|
||||||
return try {
|
return try {
|
||||||
saplingParamTool.ensureParams(saplingParamTool.properties.paramsDirectory)
|
saplingParamTool.ensureParams(saplingParamTool.properties.paramsDirectory)
|
||||||
Twig.debug { "params exist! attempting to shield..." }
|
Twig.debug { "params exist! attempting to shield..." }
|
||||||
val proposal = backend.proposeShielding(usk.account, memo)
|
val proposal = backend.proposeShielding(usk.account, 100000, memo)
|
||||||
backend.createProposedTransaction(proposal, usk)
|
backend.createProposedTransaction(proposal, usk)
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
// TODO [#680]: if this error matches: Insufficient balance (have 0, need 1000 including fee)
|
// TODO [#680]: if this error matches: Insufficient balance (have 0, need 1000 including fee)
|
||||||
|
|
Loading…
Reference in New Issue