[#546] TransactionEncoder To Async/Await (#547)

- async/await API update
- code cleaned up from the unused APIs
This commit is contained in:
Lukas Korba 2022-10-03 12:44:33 +02:00 committed by GitHub
parent 28985a4e38
commit 46d8c04afc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 95 deletions

View File

@ -96,7 +96,7 @@ class PersistentTransactionManager: OutboundTransactionManager {
}
do {
let encodedTransaction = try self.encoder.createShieldingTransaction(
let encodedTransaction = try await self.encoder.createShieldingTransaction(
spendingKey: spendingKey,
tSecretKey: tsk,
memo: pendingTransaction.memo?.asZcashTransactionMemo(),
@ -126,7 +126,7 @@ class PersistentTransactionManager: OutboundTransactionManager {
pendingTransaction: PendingTransactionEntity
) async throws -> PendingTransactionEntity {
do {
let encodedTransaction = try self.encoder.createTransaction(
let encodedTransaction = try await self.encoder.createTransaction(
spendingKey: spendingKey,
zatoshi: pendingTransaction.intValue,
to: pendingTransaction.toAddress,

View File

@ -39,31 +39,7 @@ protocol TransactionEncoder {
to address: String,
memo: String?,
from accountIndex: Int
) throws -> EncodedTransaction
/**
Creates a transaction, throwing an exception whenever things are missing. When the provided wallet implementation
doesn't throw an exception, we wrap the issue into a descriptive exception ourselves (rather than using
double-bangs for things).
Non-blocking
- Parameters:
- Parameter spendingKey: a string containing the spending key
- Parameter zatoshi: the amount to send in zatoshis
- Parameter to: string containing the recipient address
- Parameter memo: string containing the memo (optional)
- Parameter accountIndex: index of the account that will be used to send the funds
- Parameter result: a non escaping closure that receives a Result containing either an EncodedTransaction or a TransactionEncoderError
*/
// swiftlint:disable:next function_parameter_count
func createTransaction(
spendingKey: String,
zatoshi: Int,
to address: String,
memo: String?,
from accountIndex: Int,
result: @escaping TransactionEncoderResultBlock
)
) async throws -> EncodedTransaction
/**
Creates a transaction that will attempt to shield transparent funds that are present on the cacheDB .throwing an exception whenever things are missing. When the provided wallet implementation doesn't throw an exception, we wrap the issue into a descriptive exception ourselves (rather than using double-bangs for things).
@ -82,29 +58,7 @@ protocol TransactionEncoder {
tSecretKey: String,
memo: String?,
from accountIndex: Int
) throws -> EncodedTransaction
/**
Creates a transaction that will attempt to shield transparent funds that are present on the cacheDB .throwing an exception whenever things are missing. When the provided wallet implementation doesn't throw an exception, we wrap the issue into a descriptive exception ourselves (rather than using double-bangs for things).
Non-Blocking
- Parameters:
- Parameter spendingKey: a string containing the spending key
- Parameter tSecretKey: transparent secret key to spend the UTXOs
- Parameter memo: string containing the memo (optional)
- Parameter accountIndex: index of the account that will be used to send the funds
- Returns: a TransactionEncoderResultBlock
*/
func createShieldingTransaction(
spendingKey: String,
tSecretKey: String,
memo: String?,
from accountIndex: Int,
result: @escaping TransactionEncoderResultBlock
)
) async throws -> EncodedTransaction
/**
Fetch the Transaction Entity from the encoded representation

View File

@ -10,7 +10,6 @@ import Foundation
class WalletTransactionEncoder: TransactionEncoder {
var rustBackend: ZcashRustBackendWelding.Type
var repository: TransactionRepository
var queue: DispatchQueue
private var outputParamsURL: URL
private var spendParamsURL: URL
@ -34,7 +33,6 @@ class WalletTransactionEncoder: TransactionEncoder {
self.outputParamsURL = outputParams
self.spendParamsURL = spendParams
self.networkType = networkType
self.queue = DispatchQueue(label: "wallet.transaction.encoder.serial.queue")
}
convenience init(initializer: Initializer) {
@ -55,7 +53,7 @@ class WalletTransactionEncoder: TransactionEncoder {
to address: String,
memo: String?,
from accountIndex: Int
) throws -> EncodedTransaction {
) async throws -> EncodedTransaction {
let txId = try createSpend(
spendingKey: spendingKey,
zatoshi: zatoshi,
@ -77,35 +75,6 @@ class WalletTransactionEncoder: TransactionEncoder {
throw TransactionEncoderError.notFound(transactionId: txId)
}
}
// swiftlint:disable:next function_parameter_count
func createTransaction(
spendingKey: String,
zatoshi: Int,
to address: String,
memo: String?,
from accountIndex: Int,
result: @escaping TransactionEncoderResultBlock
) {
queue.async { [weak self] in
guard let self = self else { return }
do {
result(
.success(
try self.createTransaction(
spendingKey: spendingKey,
zatoshi: zatoshi,
to: address,
memo: memo,
from: accountIndex
)
)
)
} catch {
result(.failure(error))
}
}
}
func createSpend(spendingKey: String, zatoshi: Int, to address: String, memo: String?, from accountIndex: Int) throws -> Int {
guard ensureParams(spend: self.spendParamsURL, output: self.spendParamsURL) else {
@ -136,7 +105,7 @@ class WalletTransactionEncoder: TransactionEncoder {
tSecretKey: String,
memo: String?,
from accountIndex: Int
) throws -> EncodedTransaction {
) async throws -> EncodedTransaction {
let txId = try createShieldingSpend(
spendingKey: spendingKey,
tsk: tSecretKey,
@ -158,18 +127,6 @@ class WalletTransactionEncoder: TransactionEncoder {
}
}
func createShieldingTransaction(
spendingKey: String,
tSecretKey: String,
memo: String?,
from accountIndex: Int,
result: @escaping TransactionEncoderResultBlock
) {
queue.async {
result(.failure(RustWeldingError.genericError(message: "not implemented")))
}
}
func createShieldingSpend(spendingKey: String, tsk: String, memo: String?, accountIndex: Int) throws -> Int {
guard ensureParams(spend: self.spendParamsURL, output: self.spendParamsURL) else {
throw TransactionEncoderError.missingParams