make Memo and MemoBytes parameters nullable so they can be omitted when sending to transparent receivers.
update libzcashlc
This commit is contained in:
parent
7403bcc809
commit
5de1b50b29
|
@ -86,7 +86,7 @@
|
||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/zcash-hackworks/zcash-light-client-ffi",
|
"location" : "https://github.com/zcash-hackworks/zcash-light-client-ffi",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "0059f090e655667f9ee5ed3306bd87ca78c7711a"
|
"revision" : "57c2de3825aab0ab8b5f4100dc0184e52ca86ba1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
@ -16,7 +16,7 @@ let package = Package(
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.8.0"),
|
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.8.0"),
|
||||||
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.13.0"),
|
.package(url: "https://github.com/stephencelis/SQLite.swift.git", from: "0.13.0"),
|
||||||
.package(name:"libzcashlc", url: "https://github.com/zcash-hackworks/zcash-light-client-ffi", revision: "0059f090e655667f9ee5ed3306bd87ca78c7711a")
|
.package(name:"libzcashlc", url: "https://github.com/zcash-hackworks/zcash-light-client-ffi", revision: "57c2de3825aab0ab8b5f4100dc0184e52ca86ba1")
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
.target(
|
.target(
|
||||||
|
|
|
@ -61,7 +61,7 @@ struct PendingTransaction: PendingTransactionEntity, Decodable, Encodable {
|
||||||
raw: entity.raw,
|
raw: entity.raw,
|
||||||
id: entity.id,
|
id: entity.id,
|
||||||
value: entity.value,
|
value: entity.value,
|
||||||
memo: entity.memo == nil ? Data(MemoBytes.empty().bytes) : entity.memo,
|
memo: entity.memo,
|
||||||
rawTransactionId: entity.raw,
|
rawTransactionId: entity.raw,
|
||||||
fee: entity.fee
|
fee: entity.fee
|
||||||
)
|
)
|
||||||
|
@ -179,7 +179,13 @@ struct PendingTransaction: PendingTransactionEntity, Decodable, Encodable {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension PendingTransaction {
|
extension PendingTransaction {
|
||||||
init(value: Zatoshi, recipient: PendingTransactionRecipient, memo: MemoBytes, account index: Int) {
|
init(value: Zatoshi, recipient: PendingTransactionRecipient, memo: MemoBytes?, account index: Int) {
|
||||||
|
var memoData: Data?
|
||||||
|
|
||||||
|
if let memo = memo {
|
||||||
|
memoData = Data(memo.bytes)
|
||||||
|
}
|
||||||
|
|
||||||
self = PendingTransaction(
|
self = PendingTransaction(
|
||||||
recipient: recipient,
|
recipient: recipient,
|
||||||
accountIndex: index,
|
accountIndex: index,
|
||||||
|
@ -194,7 +200,7 @@ extension PendingTransaction {
|
||||||
raw: nil,
|
raw: nil,
|
||||||
id: nil,
|
id: nil,
|
||||||
value: value,
|
value: value,
|
||||||
memo: Data(memo.bytes),
|
memo: memoData,
|
||||||
rawTransactionId: nil,
|
rawTransactionId: nil,
|
||||||
fee: nil
|
fee: nil
|
||||||
)
|
)
|
||||||
|
|
|
@ -225,13 +225,8 @@ extension Optional where WrappedType == String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Optional where WrappedType == Data {
|
extension Data {
|
||||||
func intoMemoBytes() throws -> MemoBytes {
|
func intoMemoBytes() throws -> MemoBytes? {
|
||||||
switch self {
|
try .init(bytes: self.bytes)
|
||||||
case .none:
|
|
||||||
return .empty()
|
|
||||||
case .some(let data):
|
|
||||||
return try .init(bytes: data.bytes)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import Foundation
|
||||||
import libzcashlc
|
import libzcashlc
|
||||||
|
|
||||||
class ZcashRustBackend: ZcashRustBackendWelding {
|
class ZcashRustBackend: ZcashRustBackendWelding {
|
||||||
|
|
||||||
static let minimumConfirmations: UInt32 = 10
|
static let minimumConfirmations: UInt32 = 10
|
||||||
|
|
||||||
static func createAccount(dbData: URL, seed: [UInt8], networkType: NetworkType) throws -> UnifiedSpendingKey {
|
static func createAccount(dbData: URL, seed: [UInt8], networkType: NetworkType) throws -> UnifiedSpendingKey {
|
||||||
|
@ -37,14 +36,14 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
||||||
usk: UnifiedSpendingKey,
|
usk: UnifiedSpendingKey,
|
||||||
to address: String,
|
to address: String,
|
||||||
value: Int64,
|
value: Int64,
|
||||||
memo: MemoBytes,
|
memo: MemoBytes?,
|
||||||
spendParamsPath: String,
|
spendParamsPath: String,
|
||||||
outputParamsPath: String,
|
outputParamsPath: String,
|
||||||
networkType: NetworkType
|
networkType: NetworkType
|
||||||
) -> Int64 {
|
) -> Int64 {
|
||||||
let dbData = dbData.osStr()
|
let dbData = dbData.osStr()
|
||||||
|
|
||||||
return usk.bytes.withUnsafeBufferPointer{ uskPtr in
|
return usk.bytes.withUnsafeBufferPointer { uskPtr in
|
||||||
zcashlc_create_to_address(
|
zcashlc_create_to_address(
|
||||||
dbData.0,
|
dbData.0,
|
||||||
dbData.1,
|
dbData.1,
|
||||||
|
@ -52,7 +51,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
||||||
UInt(usk.bytes.count),
|
UInt(usk.bytes.count),
|
||||||
[CChar](address.utf8CString),
|
[CChar](address.utf8CString),
|
||||||
value,
|
value,
|
||||||
memo.bytes,
|
memo?.bytes,
|
||||||
spendParamsPath,
|
spendParamsPath,
|
||||||
UInt(spendParamsPath.lengthOfBytes(using: .utf8)),
|
UInt(spendParamsPath.lengthOfBytes(using: .utf8)),
|
||||||
outputParamsPath,
|
outputParamsPath,
|
||||||
|
@ -584,7 +583,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
||||||
dbCache: URL,
|
dbCache: URL,
|
||||||
dbData: URL,
|
dbData: URL,
|
||||||
usk: UnifiedSpendingKey,
|
usk: UnifiedSpendingKey,
|
||||||
memo: MemoBytes,
|
memo: MemoBytes?,
|
||||||
spendParamsPath: String,
|
spendParamsPath: String,
|
||||||
outputParamsPath: String,
|
outputParamsPath: String,
|
||||||
networkType: NetworkType
|
networkType: NetworkType
|
||||||
|
@ -597,7 +596,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
||||||
dbData.1,
|
dbData.1,
|
||||||
uskBuffer.baseAddress,
|
uskBuffer.baseAddress,
|
||||||
UInt(usk.bytes.count),
|
UInt(usk.bytes.count),
|
||||||
memo.bytes,
|
memo?.bytes,
|
||||||
spendParamsPath,
|
spendParamsPath,
|
||||||
UInt(spendParamsPath.lengthOfBytes(using: .utf8)),
|
UInt(spendParamsPath.lengthOfBytes(using: .utf8)),
|
||||||
outputParamsPath,
|
outputParamsPath,
|
||||||
|
|
|
@ -62,7 +62,7 @@ protocol ZcashRustBackendWelding {
|
||||||
/// - Parameter usk: `UnifiedSpendingKey` for the account that controls the funds to be spent.
|
/// - Parameter usk: `UnifiedSpendingKey` for the account that controls the funds to be spent.
|
||||||
/// - Parameter to: recipient address
|
/// - Parameter to: recipient address
|
||||||
/// - Parameter value: transaction amount in Zatoshi
|
/// - Parameter value: transaction amount in Zatoshi
|
||||||
/// - Parameter memo: the `Memo` for this transaction
|
/// - Parameter memo: the `MemoBytes` for this transaction. pass `nil` when sending to transparent receivers
|
||||||
/// - Parameter spendParamsPath: path escaped String for the filesystem locations where the spend parameters are located
|
/// - Parameter spendParamsPath: path escaped String for the filesystem locations where the spend parameters are located
|
||||||
/// - Parameter outputParamsPath: path escaped String for the filesystem locations where the output parameters are located
|
/// - Parameter outputParamsPath: path escaped String for the filesystem locations where the output parameters are located
|
||||||
/// - Parameter networkType: network type of this key
|
/// - Parameter networkType: network type of this key
|
||||||
|
@ -71,7 +71,7 @@ protocol ZcashRustBackendWelding {
|
||||||
usk: UnifiedSpendingKey,
|
usk: UnifiedSpendingKey,
|
||||||
to address: String,
|
to address: String,
|
||||||
value: Int64,
|
value: Int64,
|
||||||
memo: MemoBytes,
|
memo: MemoBytes?,
|
||||||
spendParamsPath: String,
|
spendParamsPath: String,
|
||||||
outputParamsPath: String,
|
outputParamsPath: String,
|
||||||
networkType: NetworkType
|
networkType: NetworkType
|
||||||
|
@ -451,7 +451,7 @@ protocol ZcashRustBackendWelding {
|
||||||
dbCache: URL,
|
dbCache: URL,
|
||||||
dbData: URL,
|
dbData: URL,
|
||||||
usk: UnifiedSpendingKey,
|
usk: UnifiedSpendingKey,
|
||||||
memo: MemoBytes,
|
memo: MemoBytes?,
|
||||||
spendParamsPath: String,
|
spendParamsPath: String,
|
||||||
outputParamsPath: String,
|
outputParamsPath: String,
|
||||||
networkType: NetworkType
|
networkType: NetworkType
|
||||||
|
|
|
@ -109,13 +109,13 @@ public protocol Synchronizer {
|
||||||
/// - Parameter spendingKey: the `UnifiedSpendingKey` that allows spends to occur.
|
/// - Parameter spendingKey: the `UnifiedSpendingKey` that allows spends to occur.
|
||||||
/// - Parameter zatoshi: the amount to send in Zatoshi.
|
/// - Parameter zatoshi: the amount to send in Zatoshi.
|
||||||
/// - Parameter toAddress: the recipient's address.
|
/// - Parameter toAddress: the recipient's address.
|
||||||
/// - Parameter memo: the memo to include as part of the transaction.
|
/// - Parameter memo: an `Optional<Memo>`with the memo to include as part of the transaction. send `nil` when sending to transparent receivers otherwise the function will throw an error
|
||||||
// swiftlint:disable:next function_parameter_count
|
// swiftlint:disable:next function_parameter_count
|
||||||
func sendToAddress(
|
func sendToAddress(
|
||||||
spendingKey: UnifiedSpendingKey,
|
spendingKey: UnifiedSpendingKey,
|
||||||
zatoshi: Zatoshi,
|
zatoshi: Zatoshi,
|
||||||
toAddress: Recipient,
|
toAddress: Recipient,
|
||||||
memo: Memo
|
memo: Memo?
|
||||||
) async throws -> PendingTransactionEntity
|
) async throws -> PendingTransactionEntity
|
||||||
|
|
||||||
/// Shields transparent funds from the given private key into the best shielded pool of the account associated to the given `UnifiedSpendingKey`.
|
/// Shields transparent funds from the given private key into the best shielded pool of the account associated to the given `UnifiedSpendingKey`.
|
||||||
|
|
|
@ -461,14 +461,19 @@ public class SDKSynchronizer: Synchronizer {
|
||||||
spendingKey: UnifiedSpendingKey,
|
spendingKey: UnifiedSpendingKey,
|
||||||
zatoshi: Zatoshi,
|
zatoshi: Zatoshi,
|
||||||
toAddress: Recipient,
|
toAddress: Recipient,
|
||||||
memo: Memo
|
memo: Memo?
|
||||||
) async throws -> PendingTransactionEntity {
|
) async throws -> PendingTransactionEntity {
|
||||||
do {
|
do {
|
||||||
try await initializer.downloadParametersIfNeeded()
|
try await initializer.downloadParametersIfNeeded()
|
||||||
} catch {
|
} catch {
|
||||||
throw SynchronizerError.parameterMissing(underlyingError: error)
|
throw SynchronizerError.parameterMissing(underlyingError: error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if case Recipient.transparent = toAddress,
|
||||||
|
memo != nil {
|
||||||
|
throw SynchronizerError.generalError(message: "Memos can't be sent to transparent addresses.")
|
||||||
|
}
|
||||||
|
|
||||||
return try await createToAddress(
|
return try await createToAddress(
|
||||||
spendingKey: spendingKey,
|
spendingKey: spendingKey,
|
||||||
zatoshi: zatoshi,
|
zatoshi: zatoshi,
|
||||||
|
@ -510,13 +515,13 @@ public class SDKSynchronizer: Synchronizer {
|
||||||
spendingKey: UnifiedSpendingKey,
|
spendingKey: UnifiedSpendingKey,
|
||||||
zatoshi: Zatoshi,
|
zatoshi: Zatoshi,
|
||||||
recipient: Recipient,
|
recipient: Recipient,
|
||||||
memo: Memo
|
memo: Memo?
|
||||||
) async throws -> PendingTransactionEntity {
|
) async throws -> PendingTransactionEntity {
|
||||||
do {
|
do {
|
||||||
let spend = try transactionManager.initSpend(
|
let spend = try transactionManager.initSpend(
|
||||||
zatoshi: zatoshi,
|
zatoshi: zatoshi,
|
||||||
recipient: .address(recipient),
|
recipient: .address(recipient),
|
||||||
memo: memo.asMemoBytes(),
|
memo: memo?.asMemoBytes(),
|
||||||
from: Int(spendingKey.account)
|
from: Int(spendingKey.account)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ class PersistentTransactionManager: OutboundTransactionManager {
|
||||||
func initSpend(
|
func initSpend(
|
||||||
zatoshi: Zatoshi,
|
zatoshi: Zatoshi,
|
||||||
recipient: PendingTransactionRecipient,
|
recipient: PendingTransactionRecipient,
|
||||||
memo: MemoBytes,
|
memo: MemoBytes?,
|
||||||
from accountIndex: Int
|
from accountIndex: Int
|
||||||
) throws -> PendingTransactionEntity {
|
) throws -> PendingTransactionEntity {
|
||||||
guard let insertedTx = try repository.find(
|
guard let insertedTx = try repository.find(
|
||||||
|
@ -72,7 +72,7 @@ class PersistentTransactionManager: OutboundTransactionManager {
|
||||||
do {
|
do {
|
||||||
let encodedTransaction = try await self.encoder.createShieldingTransaction(
|
let encodedTransaction = try await self.encoder.createShieldingTransaction(
|
||||||
spendingKey: spendingKey,
|
spendingKey: spendingKey,
|
||||||
memoBytes: try pendingTransaction.memo.intoMemoBytes(),
|
memoBytes: try pendingTransaction.memo?.intoMemoBytes(),
|
||||||
from: pendingTransaction.accountIndex
|
from: pendingTransaction.accountIndex
|
||||||
)
|
)
|
||||||
let transaction = try self.encoder.expandEncodedTransaction(encodedTransaction)
|
let transaction = try self.encoder.expandEncodedTransaction(encodedTransaction)
|
||||||
|
@ -115,7 +115,7 @@ class PersistentTransactionManager: OutboundTransactionManager {
|
||||||
spendingKey: spendingKey,
|
spendingKey: spendingKey,
|
||||||
zatoshi: pendingTransaction.value,
|
zatoshi: pendingTransaction.value,
|
||||||
to: toAddress!,
|
to: toAddress!,
|
||||||
memoBytes: try pendingTransaction.memo.intoMemoBytes(),
|
memoBytes: try pendingTransaction.memo?.intoMemoBytes(),
|
||||||
from: pendingTransaction.accountIndex
|
from: pendingTransaction.accountIndex
|
||||||
)
|
)
|
||||||
let transaction = try self.encoder.expandEncodedTransaction(encodedTransaction)
|
let transaction = try self.encoder.expandEncodedTransaction(encodedTransaction)
|
||||||
|
|
|
@ -34,7 +34,7 @@ protocol TransactionEncoder {
|
||||||
spendingKey: UnifiedSpendingKey,
|
spendingKey: UnifiedSpendingKey,
|
||||||
zatoshi: Zatoshi,
|
zatoshi: Zatoshi,
|
||||||
to address: String,
|
to address: String,
|
||||||
memoBytes: MemoBytes,
|
memoBytes: MemoBytes?,
|
||||||
from accountIndex: Int
|
from accountIndex: Int
|
||||||
) async throws -> EncodedTransaction
|
) async throws -> EncodedTransaction
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ protocol TransactionEncoder {
|
||||||
*/
|
*/
|
||||||
func createShieldingTransaction(
|
func createShieldingTransaction(
|
||||||
spendingKey: UnifiedSpendingKey,
|
spendingKey: UnifiedSpendingKey,
|
||||||
memoBytes: MemoBytes,
|
memoBytes: MemoBytes?,
|
||||||
from accountIndex: Int
|
from accountIndex: Int
|
||||||
) async throws -> EncodedTransaction
|
) async throws -> EncodedTransaction
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ protocol OutboundTransactionManager {
|
||||||
func initSpend(
|
func initSpend(
|
||||||
zatoshi: Zatoshi,
|
zatoshi: Zatoshi,
|
||||||
recipient: PendingTransactionRecipient,
|
recipient: PendingTransactionRecipient,
|
||||||
memo: MemoBytes,
|
memo: MemoBytes?,
|
||||||
from accountIndex: Int
|
from accountIndex: Int
|
||||||
) throws -> PendingTransactionEntity
|
) throws -> PendingTransactionEntity
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
||||||
spendingKey: UnifiedSpendingKey,
|
spendingKey: UnifiedSpendingKey,
|
||||||
zatoshi: Zatoshi,
|
zatoshi: Zatoshi,
|
||||||
to address: String,
|
to address: String,
|
||||||
memoBytes: MemoBytes,
|
memoBytes: MemoBytes?,
|
||||||
from accountIndex: Int
|
from accountIndex: Int
|
||||||
) async throws -> EncodedTransaction {
|
) async throws -> EncodedTransaction {
|
||||||
let txId = try createSpend(
|
let txId = try createSpend(
|
||||||
|
@ -80,7 +80,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
||||||
spendingKey: UnifiedSpendingKey,
|
spendingKey: UnifiedSpendingKey,
|
||||||
zatoshi: Zatoshi,
|
zatoshi: Zatoshi,
|
||||||
to address: String,
|
to address: String,
|
||||||
memoBytes: MemoBytes,
|
memoBytes: MemoBytes?,
|
||||||
from accountIndex: Int
|
from accountIndex: Int
|
||||||
) throws -> Int {
|
) throws -> Int {
|
||||||
guard ensureParams(spend: self.spendParamsURL, output: self.spendParamsURL) else {
|
guard ensureParams(spend: self.spendParamsURL, output: self.spendParamsURL) else {
|
||||||
|
@ -107,7 +107,7 @@ class WalletTransactionEncoder: TransactionEncoder {
|
||||||
|
|
||||||
func createShieldingTransaction(
|
func createShieldingTransaction(
|
||||||
spendingKey: UnifiedSpendingKey,
|
spendingKey: UnifiedSpendingKey,
|
||||||
memoBytes: MemoBytes,
|
memoBytes: MemoBytes?,
|
||||||
from accountIndex: Int
|
from accountIndex: Int
|
||||||
) async throws -> EncodedTransaction {
|
) async throws -> EncodedTransaction {
|
||||||
let txId = try createShieldingSpend(
|
let txId = try createShieldingSpend(
|
||||||
|
@ -129,7 +129,11 @@ class WalletTransactionEncoder: TransactionEncoder {
|
||||||
throw TransactionEncoderError.notFound(transactionId: txId)
|
throw TransactionEncoderError.notFound(transactionId: txId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func createShieldingSpend(spendingKey: UnifiedSpendingKey, memo: MemoBytes, accountIndex: Int) throws -> Int {
|
func createShieldingSpend(
|
||||||
|
spendingKey: UnifiedSpendingKey,
|
||||||
|
memo: MemoBytes?,
|
||||||
|
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