- async/await API update - code cleaned up from the unused APIs
This commit is contained in:
parent
28985a4e38
commit
46d8c04afc
|
@ -96,7 +96,7 @@ class PersistentTransactionManager: OutboundTransactionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let encodedTransaction = try self.encoder.createShieldingTransaction(
|
let encodedTransaction = try await self.encoder.createShieldingTransaction(
|
||||||
spendingKey: spendingKey,
|
spendingKey: spendingKey,
|
||||||
tSecretKey: tsk,
|
tSecretKey: tsk,
|
||||||
memo: pendingTransaction.memo?.asZcashTransactionMemo(),
|
memo: pendingTransaction.memo?.asZcashTransactionMemo(),
|
||||||
|
@ -126,7 +126,7 @@ class PersistentTransactionManager: OutboundTransactionManager {
|
||||||
pendingTransaction: PendingTransactionEntity
|
pendingTransaction: PendingTransactionEntity
|
||||||
) async throws -> PendingTransactionEntity {
|
) async throws -> PendingTransactionEntity {
|
||||||
do {
|
do {
|
||||||
let encodedTransaction = try self.encoder.createTransaction(
|
let encodedTransaction = try await self.encoder.createTransaction(
|
||||||
spendingKey: spendingKey,
|
spendingKey: spendingKey,
|
||||||
zatoshi: pendingTransaction.intValue,
|
zatoshi: pendingTransaction.intValue,
|
||||||
to: pendingTransaction.toAddress,
|
to: pendingTransaction.toAddress,
|
||||||
|
|
|
@ -39,31 +39,7 @@ protocol TransactionEncoder {
|
||||||
to address: String,
|
to address: String,
|
||||||
memo: String?,
|
memo: String?,
|
||||||
from accountIndex: Int
|
from accountIndex: Int
|
||||||
) throws -> EncodedTransaction
|
) async 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
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
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).
|
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,
|
tSecretKey: String,
|
||||||
memo: String?,
|
memo: String?,
|
||||||
from accountIndex: Int
|
from accountIndex: Int
|
||||||
) throws -> EncodedTransaction
|
) 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).
|
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Fetch the Transaction Entity from the encoded representation
|
Fetch the Transaction Entity from the encoded representation
|
||||||
|
|
|
@ -10,7 +10,6 @@ import Foundation
|
||||||
class WalletTransactionEncoder: TransactionEncoder {
|
class WalletTransactionEncoder: TransactionEncoder {
|
||||||
var rustBackend: ZcashRustBackendWelding.Type
|
var rustBackend: ZcashRustBackendWelding.Type
|
||||||
var repository: TransactionRepository
|
var repository: TransactionRepository
|
||||||
var queue: DispatchQueue
|
|
||||||
|
|
||||||
private var outputParamsURL: URL
|
private var outputParamsURL: URL
|
||||||
private var spendParamsURL: URL
|
private var spendParamsURL: URL
|
||||||
|
@ -34,7 +33,6 @@ class WalletTransactionEncoder: TransactionEncoder {
|
||||||
self.outputParamsURL = outputParams
|
self.outputParamsURL = outputParams
|
||||||
self.spendParamsURL = spendParams
|
self.spendParamsURL = spendParams
|
||||||
self.networkType = networkType
|
self.networkType = networkType
|
||||||
self.queue = DispatchQueue(label: "wallet.transaction.encoder.serial.queue")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
convenience init(initializer: Initializer) {
|
convenience init(initializer: Initializer) {
|
||||||
|
@ -55,7 +53,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
||||||
to address: String,
|
to address: String,
|
||||||
memo: String?,
|
memo: String?,
|
||||||
from accountIndex: Int
|
from accountIndex: Int
|
||||||
) throws -> EncodedTransaction {
|
) async throws -> EncodedTransaction {
|
||||||
let txId = try createSpend(
|
let txId = try createSpend(
|
||||||
spendingKey: spendingKey,
|
spendingKey: spendingKey,
|
||||||
zatoshi: zatoshi,
|
zatoshi: zatoshi,
|
||||||
|
@ -77,35 +75,6 @@ class WalletTransactionEncoder: TransactionEncoder {
|
||||||
throw TransactionEncoderError.notFound(transactionId: txId)
|
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 {
|
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 {
|
guard ensureParams(spend: self.spendParamsURL, output: self.spendParamsURL) else {
|
||||||
|
@ -136,7 +105,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
||||||
tSecretKey: String,
|
tSecretKey: String,
|
||||||
memo: String?,
|
memo: String?,
|
||||||
from accountIndex: Int
|
from accountIndex: Int
|
||||||
) throws -> EncodedTransaction {
|
) async throws -> EncodedTransaction {
|
||||||
let txId = try createShieldingSpend(
|
let txId = try createShieldingSpend(
|
||||||
spendingKey: spendingKey,
|
spendingKey: spendingKey,
|
||||||
tsk: tSecretKey,
|
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 {
|
func createShieldingSpend(spendingKey: String, tsk: String, memo: String?, accountIndex: Int) throws -> Int {
|
||||||
guard ensureParams(spend: self.spendParamsURL, output: self.spendParamsURL) else {
|
guard ensureParams(spend: self.spendParamsURL, output: self.spendParamsURL) else {
|
||||||
throw TransactionEncoderError.missingParams
|
throw TransactionEncoderError.missingParams
|
||||||
|
|
Loading…
Reference in New Issue