2019-11-26 14:32:20 -08:00
|
|
|
//
|
|
|
|
// TransactionEncoder.swift
|
|
|
|
// ZcashLightClientKit
|
|
|
|
//
|
|
|
|
// Created by Francisco Gindre on 11/20/19.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
typealias TransactionEncoderResultBlock = (_ result: Result<EncodedTransaction,Error>) -> Void
|
|
|
|
|
|
|
|
public enum TransactionEncoderError: Error {
|
2019-12-03 07:19:44 -08:00
|
|
|
case notFound(transactionId: Int)
|
|
|
|
case NotEncoded(transactionId: Int)
|
2019-11-26 14:32:20 -08:00
|
|
|
case missingParams
|
|
|
|
case spendingKeyWrongNetwork
|
2020-06-04 14:36:25 -07:00
|
|
|
case couldNotExpand(txId: Data)
|
2019-11-26 14:32:20 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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).
|
|
|
|
Blocking
|
2020-02-26 08:54:48 -08: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)
|
2020-02-26 08:54:48 -08:00
|
|
|
- Parameter accountIndex: index of the account that will be used to send the funds
|
|
|
|
|
|
|
|
- Throws: a TransactionEncoderError
|
2019-11-26 14:32:20 -08:00
|
|
|
*/
|
2019-12-03 07:19:44 -08:00
|
|
|
func createTransaction(spendingKey: String, zatoshi: Int, to: String, memo: String?, from accountIndex: Int) throws -> EncodedTransaction
|
2019-11-26 14:32:20 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
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
|
2020-02-26 08:54:48 -08: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)
|
2020-02-26 08:54:48 -08:00
|
|
|
- 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
|
2019-11-26 14:32:20 -08:00
|
|
|
*/
|
2019-12-03 07:19:44 -08:00
|
|
|
func createTransaction(spendingKey: String, zatoshi: Int, to: String, memo: String?, from accountIndex: Int, result: @escaping TransactionEncoderResultBlock)
|
2019-11-26 14:32:20 -08:00
|
|
|
|
2020-06-04 14:36:25 -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
|
2019-11-26 14:32:20 -08:00
|
|
|
}
|