[WIP]Get UTXOs
This commit is contained in:
parent
bedeb89316
commit
6b48695744
|
@ -0,0 +1,22 @@
|
||||||
|
//
|
||||||
|
// UnspentTransactionOutputDAO.swift
|
||||||
|
// ZcashLightClientKit
|
||||||
|
//
|
||||||
|
// Created by Francisco Gindre on 12/9/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
struct UTXO: UnspentTransactionOutputEntity {
|
||||||
|
var address: String
|
||||||
|
|
||||||
|
var txid: Data
|
||||||
|
|
||||||
|
var index: Int32
|
||||||
|
|
||||||
|
var script: Data
|
||||||
|
|
||||||
|
var valueZat: Int64
|
||||||
|
|
||||||
|
var height: UInt64
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
//
|
||||||
|
// UnspentTransactionOutputEntity.swift
|
||||||
|
// ZcashLightClientKit
|
||||||
|
//
|
||||||
|
// Created by Francisco Gindre on 12/9/20.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
public protocol UnspentTransactionOutputEntity {
|
||||||
|
|
||||||
|
var address: String { get set }
|
||||||
|
|
||||||
|
var txid: Data {get set}
|
||||||
|
|
||||||
|
var index: Int32 {get set}
|
||||||
|
|
||||||
|
var script: Data {get set}
|
||||||
|
|
||||||
|
var valueZat: Int64 {get set}
|
||||||
|
|
||||||
|
var height: UInt64 {get set}
|
||||||
|
|
||||||
|
}
|
|
@ -75,8 +75,7 @@ public class LightWalletGRPCService {
|
||||||
requestIDProvider: .autogenerated,
|
requestIDProvider: .autogenerated,
|
||||||
requestIDHeader: nil,
|
requestIDHeader: nil,
|
||||||
cacheable: false)
|
cacheable: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension LightWalletGRPCService: LightWalletService {
|
extension LightWalletGRPCService: LightWalletService {
|
||||||
|
@ -218,6 +217,39 @@ extension LightWalletGRPCService: LightWalletService {
|
||||||
}
|
}
|
||||||
return height
|
return height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func fetchUTXOs(for tAddress: String, result: @escaping (Result<[UnspentTransactionOutputEntity], LightWalletServiceError>) -> Void) {
|
||||||
|
queue.async { [weak self] in
|
||||||
|
guard let self = self else { return }
|
||||||
|
let arg = GetAddressUtxosArg.with { (utxoArgs) in
|
||||||
|
utxoArgs.address = tAddress
|
||||||
|
}
|
||||||
|
var utxos = [UnspentTransactionOutputEntity]()
|
||||||
|
let response = self.compactTxStreamer.getAddressUtxosStream(arg) { (reply) in
|
||||||
|
utxos.append(
|
||||||
|
UTXO(address: tAddress,
|
||||||
|
txid: reply.txid,
|
||||||
|
index: reply.index,
|
||||||
|
script: reply.script,
|
||||||
|
valueZat: reply.valueZat,
|
||||||
|
height: UInt64(reply.valueZat)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
let status = try response.status.wait()
|
||||||
|
switch status.code {
|
||||||
|
case .ok:
|
||||||
|
result(.success(utxos))
|
||||||
|
default:
|
||||||
|
result(.failure(.mapCode(status)))
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
result(.failure(error.mapToServiceError()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Error {
|
extension Error {
|
||||||
|
|
|
@ -168,4 +168,7 @@ public protocol LightWalletService {
|
||||||
- Returns: LightWalletServiceResponse
|
- Returns: LightWalletServiceResponse
|
||||||
*/
|
*/
|
||||||
func fetchTransaction(txId: Data, result: @escaping (Result<TransactionEntity,LightWalletServiceError>) -> Void)
|
func fetchTransaction(txId: Data, result: @escaping (Result<TransactionEntity,LightWalletServiceError>) -> Void)
|
||||||
|
|
||||||
|
|
||||||
|
func fetchUTXOs(for tAddress: String, result: @escaping(Result<[UnspentTransactionOutputEntity], LightWalletServiceError>) -> Void)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue