Deprecate `Synchronizer.sendToAddress` and `Synchronizer.shieldFunds`
This commit is contained in:
parent
a27fbda8c0
commit
d2fa400531
|
@ -16,8 +16,11 @@ and this library adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
still provided. See more in the class documentation
|
||||
`sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/WalletBalance.kt`
|
||||
- `Synchronizer.transparentBalances: WalletBalance` to `Synchronizer.transparentBalance: Zatoshi`
|
||||
- `WalletSnapshot.transparentBalance: WalletBalance` to `WalletSnapshot.transparentBalance: Zatoshi`
|
||||
- `WalletSnapshot.transparentBalance: WalletBalance` to `WalletSnapshot.transparentBalance: Zatoshi`
|
||||
- `Memo.MAX_MEMO_LENGTH_BYTES` is now available in public API
|
||||
- `Synchronizer.sendToAddress` and `Synchronizer.shieldFunds` have been
|
||||
deprecated, and will be removed in 2.1.0 (which will create multiple
|
||||
transactions at once for some recipients).
|
||||
|
||||
### Added
|
||||
- APIs that enable constructing a proposal for transferring or shielding funds,
|
||||
|
|
|
@ -105,7 +105,15 @@ class TestWallet(
|
|||
memo: String = "",
|
||||
amount: Zatoshi = Zatoshi(500L)
|
||||
): TestWallet {
|
||||
synchronizer.sendToAddress(shieldedSpendingKey, amount, address, memo)
|
||||
synchronizer.createProposedTransactions(
|
||||
synchronizer.proposeTransfer(
|
||||
shieldedSpendingKey.account,
|
||||
address,
|
||||
amount,
|
||||
memo
|
||||
),
|
||||
shieldedSpendingKey
|
||||
)
|
||||
return this
|
||||
}
|
||||
|
||||
|
@ -121,7 +129,10 @@ class TestWallet(
|
|||
|
||||
synchronizer.getTransparentBalance(transparentAddress).let { walletBalance ->
|
||||
if (walletBalance.value > 0L) {
|
||||
synchronizer.shieldFunds(shieldedSpendingKey)
|
||||
synchronizer.createProposedTransactions(
|
||||
synchronizer.proposeShielding(shieldedSpendingKey.account),
|
||||
shieldedSpendingKey
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -189,7 +189,15 @@ class SampleCodeTest {
|
|||
ZcashNetwork.Mainnet,
|
||||
Account.DEFAULT
|
||||
)
|
||||
synchronizer.sendToAddress(spendingKey, amount, address, memo)
|
||||
synchronizer.createProposedTransactions(
|
||||
synchronizer.proposeTransfer(
|
||||
spendingKey.account,
|
||||
address,
|
||||
amount,
|
||||
memo
|
||||
),
|
||||
spendingKey
|
||||
)
|
||||
}
|
||||
|
||||
// /////////////////////////////////////////////////////
|
||||
|
|
|
@ -60,13 +60,18 @@ class GetBalanceFragment : BaseDemoFragment<FragmentGetBalanceBinding>() {
|
|||
binding.shield.apply {
|
||||
setOnClickListener {
|
||||
lifecycleScope.launch {
|
||||
sharedViewModel.synchronizerFlow.value?.shieldFunds(
|
||||
val usk =
|
||||
DerivationTool.getInstance().deriveUnifiedSpendingKey(
|
||||
seed,
|
||||
network,
|
||||
Account.DEFAULT
|
||||
)
|
||||
)
|
||||
sharedViewModel.synchronizerFlow.value?.let { synchronizer ->
|
||||
synchronizer.createProposedTransactions(
|
||||
synchronizer.proposeShielding(usk.account),
|
||||
usk
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,12 +145,17 @@ class SendFragment : BaseDemoFragment<FragmentSendBinding>() {
|
|||
val amount = amountInput.text.toString().toDouble().convertZecToZatoshi()
|
||||
val toAddress = addressInput.text.toString().trim()
|
||||
lifecycleScope.launch {
|
||||
sharedViewModel.synchronizerFlow.value?.sendToAddress(
|
||||
spendingKey,
|
||||
amount,
|
||||
toAddress,
|
||||
"Funds from Demo App"
|
||||
)
|
||||
sharedViewModel.synchronizerFlow.value?.let { synchronizer ->
|
||||
synchronizer.createProposedTransactions(
|
||||
synchronizer.proposeTransfer(
|
||||
spendingKey.account,
|
||||
toAddress,
|
||||
amount,
|
||||
"Funds from Demo App"
|
||||
),
|
||||
spendingKey
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
mainActivity()?.hideKeyboard()
|
||||
|
|
|
@ -22,6 +22,7 @@ import cash.z.ecc.android.sdk.model.Account
|
|||
import cash.z.ecc.android.sdk.model.BlockHeight
|
||||
import cash.z.ecc.android.sdk.model.PercentDecimal
|
||||
import cash.z.ecc.android.sdk.model.PersistableWallet
|
||||
import cash.z.ecc.android.sdk.model.TransactionSubmitResult
|
||||
import cash.z.ecc.android.sdk.model.WalletAddresses
|
||||
import cash.z.ecc.android.sdk.model.WalletBalance
|
||||
import cash.z.ecc.android.sdk.model.Zatoshi
|
||||
|
@ -47,6 +48,7 @@ import kotlinx.coroutines.flow.flatMapLatest
|
|||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.toList
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
|
@ -202,7 +204,7 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
|||
viewModelScope.launch {
|
||||
val spendingKey = spendingKey.filterNotNull().first()
|
||||
runCatching { synchronizer.send(spendingKey, zecSend) }
|
||||
.onSuccess { mutableSendState.value = SendState.Sent(it) }
|
||||
.onSuccess { mutableSendState.value = SendState.Sent(it.toList()) }
|
||||
.onFailure { mutableSendState.value = SendState.Error(it) }
|
||||
}
|
||||
} else {
|
||||
|
@ -226,8 +228,13 @@ class WalletViewModel(application: Application) : AndroidViewModel(application)
|
|||
if (null != synchronizer) {
|
||||
viewModelScope.launch {
|
||||
val spendingKey = spendingKey.filterNotNull().first()
|
||||
kotlin.runCatching { synchronizer.shieldFunds(spendingKey) }
|
||||
.onSuccess { mutableSendState.value = SendState.Sent(it) }
|
||||
kotlin.runCatching {
|
||||
synchronizer.createProposedTransactions(
|
||||
synchronizer.proposeShielding(spendingKey.account),
|
||||
spendingKey
|
||||
)
|
||||
}
|
||||
.onSuccess { mutableSendState.value = SendState.Sent(it.toList()) }
|
||||
.onFailure { mutableSendState.value = SendState.Error(it) }
|
||||
}
|
||||
} else {
|
||||
|
@ -302,7 +309,7 @@ sealed class SendState {
|
|||
override fun toString(): String = "Sending"
|
||||
}
|
||||
|
||||
class Sent(val localTxId: Long) : SendState() {
|
||||
class Sent(val txIds: List<TransactionSubmitResult>) : SendState() {
|
||||
override fun toString(): String = "Sent"
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,12 @@ data class ZecSend(val destination: WalletAddress, val amount: Zatoshi, val memo
|
|||
suspend fun Synchronizer.send(
|
||||
spendingKey: UnifiedSpendingKey,
|
||||
send: ZecSend
|
||||
) = sendToAddress(
|
||||
spendingKey,
|
||||
send.amount,
|
||||
send.destination.address,
|
||||
send.memo.value
|
||||
) = createProposedTransactions(
|
||||
proposeTransfer(
|
||||
spendingKey.account,
|
||||
send.destination.address,
|
||||
send.amount,
|
||||
send.memo.value
|
||||
),
|
||||
spendingKey
|
||||
)
|
||||
|
|
|
@ -112,11 +112,14 @@ class TestnetIntegrationTest : ScopedTest() {
|
|||
Account.DEFAULT
|
||||
)
|
||||
log("sending to address")
|
||||
synchronizer.sendToAddress(
|
||||
spendingKey,
|
||||
ZcashSdk.MINERS_FEE,
|
||||
toAddress,
|
||||
"first mainnet tx from the SDK"
|
||||
synchronizer.createProposedTransactions(
|
||||
synchronizer.proposeTransfer(
|
||||
spendingKey.account,
|
||||
toAddress,
|
||||
ZcashSdk.MINERS_FEE,
|
||||
"first mainnet tx from the SDK"
|
||||
),
|
||||
spendingKey
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -106,7 +106,15 @@ class TestWallet(
|
|||
memo: String = "",
|
||||
amount: Zatoshi = Zatoshi(500L)
|
||||
): TestWallet {
|
||||
synchronizer.sendToAddress(spendingKey, amount, address, memo)
|
||||
synchronizer.createProposedTransactions(
|
||||
synchronizer.proposeTransfer(
|
||||
spendingKey.account,
|
||||
address,
|
||||
amount,
|
||||
memo
|
||||
),
|
||||
spendingKey
|
||||
)
|
||||
return this
|
||||
}
|
||||
|
||||
|
@ -124,7 +132,7 @@ class TestWallet(
|
|||
Twig.debug { "FOUND utxo balance of total: $walletBalance" }
|
||||
|
||||
if (walletBalance.value > 0L) {
|
||||
synchronizer.shieldFunds(spendingKey)
|
||||
synchronizer.createProposedTransactions(synchronizer.proposeShielding(spendingKey.account), spendingKey)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -598,6 +598,13 @@ class SdkSynchronizer private constructor(
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
message = "Upcoming SDK 2.1 will create multiple transactions at once for some recipients.",
|
||||
replaceWith =
|
||||
ReplaceWith(
|
||||
"createProposedTransactions(proposeTransfer(usk.account, toAddress, amount, memo), usk)"
|
||||
)
|
||||
)
|
||||
@Throws(TransactionEncoderException::class, TransactionSubmitException::class)
|
||||
override suspend fun sendToAddress(
|
||||
usk: UnifiedSpendingKey,
|
||||
|
@ -624,6 +631,13 @@ class SdkSynchronizer private constructor(
|
|||
}
|
||||
}
|
||||
|
||||
@Deprecated(
|
||||
message = "Upcoming SDK 2.1 will create multiple transactions at once for some recipients.",
|
||||
replaceWith =
|
||||
ReplaceWith(
|
||||
"createProposedTransactions(proposeShielding(usk.account, memo), usk)"
|
||||
)
|
||||
)
|
||||
@Throws(TransactionEncoderException::class, TransactionSubmitException::class)
|
||||
override suspend fun shieldFunds(
|
||||
usk: UnifiedSpendingKey,
|
||||
|
|
|
@ -226,6 +226,13 @@ interface Synchronizer {
|
|||
* useful for updating the UI without needing to poll. Of course, polling is always an option
|
||||
* for any wallet that wants to ignore this return value.
|
||||
*/
|
||||
@Deprecated(
|
||||
message = "Upcoming SDK 2.1 will create multiple transactions at once for some recipients.",
|
||||
replaceWith =
|
||||
ReplaceWith(
|
||||
"createProposedTransactions(proposeTransfer(usk.account, toAddress, amount, memo), usk)"
|
||||
)
|
||||
)
|
||||
suspend fun sendToAddress(
|
||||
usk: UnifiedSpendingKey,
|
||||
amount: Zatoshi,
|
||||
|
@ -233,6 +240,13 @@ interface Synchronizer {
|
|||
memo: String = ""
|
||||
): Long
|
||||
|
||||
@Deprecated(
|
||||
message = "Upcoming SDK 2.1 will create multiple transactions at once for some recipients.",
|
||||
replaceWith =
|
||||
ReplaceWith(
|
||||
"createProposedTransactions(proposeShielding(usk.account, memo), usk)"
|
||||
)
|
||||
)
|
||||
suspend fun shieldFunds(
|
||||
usk: UnifiedSpendingKey,
|
||||
memo: String = ZcashSdk.DEFAULT_SHIELD_FUNDS_MEMO_PREFIX
|
||||
|
|
Loading…
Reference in New Issue