ZcashLightClientKit/Sources/ZcashLightClientKit/Transaction/TransactionEncoder.swift

117 lines
4.5 KiB
Swift
Raw Normal View History

//
// TransactionEncoder.swift
// ZcashLightClientKit
//
// Created by Francisco Gindre on 11/20/19.
//
import Foundation
2021-09-15 05:21:29 -07:00
typealias TransactionEncoderResultBlock = (_ result: Result<EncodedTransaction, Error>) -> Void
public enum TransactionEncoderError: Error {
case notFound(transactionId: Int)
2021-09-15 05:21:29 -07:00
case notEncoded(transactionId: Int)
case missingParams
case spendingKeyWrongNetwork
case couldNotExpand(txId: Data)
}
protocol TransactionEncoder {
/**
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).
2021-09-17 06:49:58 -07:00
Blocking
2021-09-17 06:49:58 -07:00
- 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
2021-09-17 06:49:58 -07:00
- Throws: a TransactionEncoderError
*/
2021-09-15 05:21:29 -07:00
func createTransaction(
spendingKey: String,
zatoshi: Int,
2021-09-17 06:49:58 -07:00
to address: String,
2021-09-15 05:21:29 -07:00
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).
2021-09-17 06:49:58 -07:00
Non-blocking
2021-09-17 06:49:58 -07:00
- Parameters:
- Parameter spendingKey: a string containing the spending key
- Parameter zatoshi: the amount to send in zatoshis
- Parameter to: string containing the recipient address
2020-03-26 07:27:55 -07:00
- Parameter memo: string containing the memo (optional)
- Parameter accountIndex: index of the account that will be used to send the funds
2020-03-26 07:27:55 -07:00
- Parameter result: a non escaping closure that receives a Result containing either an EncodedTransaction or a TransactionEncoderError
*/
2021-09-17 06:49:58 -07:00
// swiftlint:disable:next function_parameter_count
2021-09-15 05:21:29 -07:00
func createTransaction(
spendingKey: String,
zatoshi: Int,
2021-09-17 06:49:58 -07:00
to address: String,
2021-09-15 05:21:29 -07:00
memo: String?,
from accountIndex: Int,
result: @escaping TransactionEncoderResultBlock
)
2020-12-23 15:01:09 -08:00
/**
2021-09-17 06:49:58 -07:00
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).
Blocking
2020-12-23 15:01:09 -08:00
2021-09-17 06:49:58 -07:00
- 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
2020-12-23 15:01:09 -08:00
2021-09-17 06:49:58 -07:00
- Throws: a TransactionEncoderError
2020-12-23 15:01:09 -08:00
*/
2021-09-15 05:21:29 -07:00
func createShieldingTransaction(
spendingKey: String,
tSecretKey: String,
memo: String?,
from accountIndex: Int
) throws -> EncodedTransaction
2020-12-23 15:01:09 -08:00
/**
2021-09-17 06:49:58 -07:00
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
2020-12-23 15:01:09 -08:00
2021-09-17 06:49:58 -07:00
- 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
2020-12-23 15:01:09 -08:00
2021-09-17 06:49:58 -07:00
- Returns: a TransactionEncoderResultBlock
2020-12-23 15:01:09 -08:00
*/
2021-09-15 05:21:29 -07:00
func createShieldingTransaction(
spendingKey: String,
tSecretKey: String,
memo: String?,
from accountIndex: Int,
result: @escaping TransactionEncoderResultBlock
)
2020-12-23 15:01:09 -08:00
/**
2021-09-17 06:49:58 -07:00
Fetch the Transaction Entity from the encoded representation
- Parameter encodedTransaction: The encoded transaction to expand
- Returns: a TransactionEntity based on the given Encoded Transaction
- Throws: a TransactionEncoderError
*/
func expandEncodedTransaction(_ encodedTransaction: EncodedTransaction) throws -> TransactionEntity
}