Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmcl committed Dec 1, 2023
2 parents b4ff0eb + dddafdc commit 837edfe
Show file tree
Hide file tree
Showing 30 changed files with 655 additions and 544 deletions.
25 changes: 15 additions & 10 deletions .github/workflows/docs-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ on:
- main
jobs:
build:
runs-on: ubuntu-latest
runs-on: macos-latest

steps:
- uses: actions/checkout@v2.3.4
- uses: actions/checkout@v4.1.1
with:
ref: main
- name: Swift Doc
uses: SwiftDocOrg/swift-doc@1.0.0-rc.1

- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
inputs: "Sources"
module-name: KukaiCoreSwift
format: "html"
output: "Documentation"
base-url: "https://kukai-core-swift.kukai.app/"
ruby-version: 3.0

- name: Install Jazzy
run: gem install jazzy

- name: Run Jazzy docs
run: jazzy --root-url https://kukai-core-swift.kukai.app/ --output Documentation

- name: Update Permissions
run: 'sudo chown --recursive $USER Documentation'
run: 'sudo chown -R $USER Documentation'

- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@4.1.4
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
languages: "swift"

- uses: mxcl/xcodebuild@v1.11.0
- uses: mxcl/xcodebuild@v2.0
with:
platform: ${{ matrix.platform }}
xcode: ${{ matrix.xcode }}
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
.library(name: "KukaiCoreSwift", targets: ["KukaiCoreSwift"]),
],
dependencies: [
.package(name: "KukaiCryptoSwift", url: "https://github.com/kukai-wallet/kukai-crypto-swift", from: "1.0.12"),
.package(name: "KukaiCryptoSwift", url: "https://github.com/kukai-wallet/kukai-crypto-swift", from: "1.0.14" /*.branch("feature/")*/),
//.package(url: "https://github.com/onevcat/Kingfisher.git", from: "7.6.2"),
.package(url: "https://github.com/simonmcl/Kingfisher.git", from: "1.0.0"),
.package(name: "CustomAuth", url: "https://github.com/torusresearch/customauth-swift-sdk", from: "6.0.0"),
Expand Down
2 changes: 1 addition & 1 deletion Sources/KukaiCoreSwift/Clients/BetterCallDevClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class BetterCallDevClient {
completion(nil, nil)

case .failure(let error):
os_log(.error, log: .kukaiCoreSwift, "Parse error: %@", "\(error)")
Logger.kukaiCoreSwift.error("Parse error: \(error)")
completion(nil, KukaiError.internalApplicationError(error: error))
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/KukaiCoreSwift/Clients/TezosNodeClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public class TezosNodeClient {
self?.feeEstimatorService.estimate(operations: operations, operationMetadata: metadata, constants: constants, walletAddress: walletAddress, base58EncodedPublicKey: base58EncodedPublicKey, completion: completion)

case .failure(let error):
os_log(.error, log: .kukaiCoreSwift, "Unable to fetch metadata: %@", "\(error)")
Logger.kukaiCoreSwift.error("Unable to fetch metadata: \(error)")
completion(Result.failure(error))
}
}
Expand All @@ -160,7 +160,7 @@ public class TezosNodeClient {
self?.send(operationPayload: operationPayload, operationMetadata: metadata, withWallet: wallet, completion: completion)

case .failure(let error):
os_log(.error, log: .kukaiCoreSwift, "Unable to fetch metadata: %@", "\(error)")
Logger.kukaiCoreSwift.error("Unable to fetch metadata: \(error)")
completion(Result.failure(error))
}
}
Expand Down Expand Up @@ -317,7 +317,7 @@ public class TezosNodeClient {
dispatchGroup.enter()
dexterQueriesQueue.async { [weak self] in
guard let url = self?.config.primaryNodeURL else {
os_log(.default, log: .kukaiCoreSwift, "Invalid server url: %@", self?.config.primaryNodeURL.absoluteString ?? "nil")
Logger.kukaiCoreSwift.info("Invalid server url: \(self?.config.primaryNodeURL.absoluteString ?? "nil")")
completion(false, KukaiError.internalApplicationError(error: NetworkService.NetworkError.invalidURL))
return
}
Expand All @@ -338,7 +338,7 @@ public class TezosNodeClient {
dispatchGroup.enter()
dexterQueriesQueue.async { [weak self] in
guard let url = self?.config.primaryNodeURL else {
os_log(.default, log: .kukaiCoreSwift, "Invalid server url: %@", self?.config.primaryNodeURL.absoluteString ?? "nil")
Logger.kukaiCoreSwift.info("Invalid server url: \(self?.config.primaryNodeURL.absoluteString ?? "nil")")
completion(false, KukaiError.internalApplicationError(error: NetworkService.NetworkError.invalidURL))
return
}
Expand Down
21 changes: 10 additions & 11 deletions Sources/KukaiCoreSwift/Clients/TzKTClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ public class TzKTClient {
completion(operations, nil)

case .failure(let error):
os_log(.error, log: .kukaiCoreSwift, "Parse error: %@", "\(error)")
Logger.tzkt.error("Parse error: \(error)")
completion(nil, KukaiError.internalApplicationError(error: error))
}
}
Expand Down Expand Up @@ -636,12 +636,11 @@ public class TzKTClient {
signalrConnection = HubConnectionBuilder(url: url).build()
}


// Register for SignalR operation events
signalrConnection?.on(method: "accounts", callback: { [weak self] argumentExtractor in
do {
let obj = try argumentExtractor.getArgument(type: AccountSubscriptionResponse.self)
os_log("Incoming object parsed: %@", log: .tzkt, type: .default, "\(obj)")
Logger.tzkt.info("Incoming object parsed: \(String(describing: obj))")

if let data = obj.data {
var changedAddress: [String] = []
Expand All @@ -653,7 +652,7 @@ public class TzKTClient {
}

} catch (let error) {
os_log("Failed to parse incoming websocket data: %@", log: .tzkt, type: .error, "\(error)")
Logger.tzkt.error("Failed to parse incoming websocket data: \(error)")
self?.signalrConnection?.stop()
self?.isListening = false
//completion(false, error, KukaiError.internalApplicationError(error: error))
Expand All @@ -667,7 +666,7 @@ public class TzKTClient {
Close the websocket from `listenForAccountChanges`
*/
public func stopListeningForAccountChanges() {
os_log(.default, log: .kukaiCoreSwift, "Cancelling listenForAccountChanges")
Logger.tzkt.info("Cancelling listenForAccountChanges")
signalrConnection?.stop()
isListening = false
}
Expand Down Expand Up @@ -949,7 +948,7 @@ public class TzKTClient {
dispatchGroupTransactions.leave()

case .failure(let error):
os_log(.error, log: .kukaiCoreSwift, "Parse error 1: %@", "\(error)")
Logger.tzkt.error("Parse error 1: \(error)")
dispatchGroupTransactions.leave()
}
}
Expand All @@ -969,7 +968,7 @@ public class TzKTClient {
dispatchGroupTransactions.leave()

case .failure(let error):
os_log(.error, log: .kukaiCoreSwift, "Parse error 2: %@", "\(error)")
Logger.tzkt.error("Parse error 2: \(error)")
dispatchGroupTransactions.leave()
}
}
Expand Down Expand Up @@ -1095,16 +1094,16 @@ extension TzKTClient: HubConnectionDelegate {
let subscription = AccountSubscription(addresses: addressesToWatch)
signalrConnection?.invoke(method: "SubscribeToAccounts", subscription) { [weak self] error in
if let error = error {
os_log("Subscribe to account changes failed: %@", log: .tzkt, type: .error, "\(error)")
Logger.tzkt.error("Subscribe to account changes failed: \(error)")
self?.signalrConnection?.stop()
} else {
os_log("Subscribe to account changes succeeded, waiting for objects", log: .tzkt, type: .default)
Logger.tzkt.info("Subscribe to account changes succeeded, waiting for objects")
}
}
}

public func connectionDidClose(error: Error?) {
os_log("SignalR connection closed: %@", log: .tzkt, type: .default, String(describing: error))
Logger.tzkt.error("SignalR connection closed: \(error)")

if newAddressesToWatch.count > 0 {
self.listenForAccountChanges(addresses: newAddressesToWatch)
Expand All @@ -1113,6 +1112,6 @@ extension TzKTClient: HubConnectionDelegate {
}

public func connectionDidFailToOpen(error: Error) {
os_log("Failed to open SignalR connection to listen for changes: %@", log: .tzkt, type: .error, "\(error)")
Logger.tzkt.error("Failed to open SignalR connection to listen for changes: \(error)")
}
}
25 changes: 14 additions & 11 deletions Sources/KukaiCoreSwift/Extensions/OSLogs+categories.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ import Foundation
import os.log

/// Extension to OSLog to create some custom categories for logging
extension OSLog {
public extension Logger {
private static var subsystem = Bundle.main.bundleIdentifier ?? "app.kukai.kukai-core-swift"

static let kukaiCoreSwift = OSLog(subsystem: subsystem, category: "KukaiCoreSwift")
static let walletCache = OSLog(subsystem: subsystem, category: "WalletCache")
static let kukaiCoreSwiftError = OSLog(subsystem: subsystem, category: "KukaiCoreSwift-error")
static let keychain = OSLog(subsystem: subsystem, category: "KukaiCoreSwift-keychain")
static let network = OSLog(subsystem: subsystem, category: "KukaiCoreSwift-network")
static let bcd = OSLog(subsystem: subsystem, category: "BetterCallDev")
static let tzkt = OSLog(subsystem: subsystem, category: "TzKT")
static let taquitoService = OSLog(subsystem: subsystem, category: "TaquitoService")
static let torus = OSLog(subsystem: subsystem, category: "Torus")
static let ledger = OSLog(subsystem: subsystem, category: "Ledger")
static let kukaiCoreSwift = Logger(subsystem: subsystem, category: "KukaiCoreSwift")
static let walletCache = Logger(subsystem: subsystem, category: "WalletCache")
static let kukaiCoreSwiftError = Logger(subsystem: subsystem, category: "KukaiCoreSwift-error")
static let keychain = Logger(subsystem: subsystem, category: "KukaiCoreSwift-keychain")
static let network = Logger(subsystem: subsystem, category: "KukaiCoreSwift-network")
static let bcd = Logger(subsystem: subsystem, category: "BetterCallDev")
static let tzkt = Logger(subsystem: subsystem, category: "TzKT")
static let taquitoService = Logger(subsystem: subsystem, category: "TaquitoService")
static let torus = Logger(subsystem: subsystem, category: "Torus")
static let ledger = Logger(subsystem: subsystem, category: "Ledger")

/// Used by the app importing this library
static let app = Logger(subsystem: subsystem, category: "app")
}
10 changes: 9 additions & 1 deletion Sources/KukaiCoreSwift/Extensions/URL+extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@ extension URL {
if let u = urlComponents.url {
self = u
} else {
os_log("Unable to appendQueryItem %@ to URL", log: .kukaiCoreSwift, type: .error, name)
Logger.kukaiCoreSwift.error("Unable to appendQueryItem \(name) to URL")
}
}

/// Helper to append a Int as a query param to a URL
mutating func appendQueryItem(name: String, value: Int) {
self.appendQueryItem(name: name, value: value.description)
}

func absoluteStringByTrimmingQuery() -> String? {
if var urlcomponents = URLComponents(url: self, resolvingAgainstBaseURL: false) {
urlcomponents.query = nil
return urlcomponents.string
}
return nil
}
}
6 changes: 3 additions & 3 deletions Sources/KukaiCoreSwift/Factories/OperationFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class OperationFactory {

// Return empty array if `TokenAmount` is a negaitve value
if tokenAmount < TokenAmount.zeroBalance(decimalPlaces: tokenAmount.decimalPlaces) {
os_log(.error, log: .kukaiCoreSwift, "Negative value passed to OperationFactory.sendOperation")
Logger.kukaiCoreSwift.error("Negative value passed to OperationFactory.sendOperation")
return []
}

Expand All @@ -49,7 +49,7 @@ public class OperationFactory {

case .nonfungible:
// Can't send an entire NFT group, need to rethink this
os_log(.error, log: .kukaiCoreSwift, "Can't send an entire NFT group. Must send individual NFT's from token.nfts array, via the other sendOperation")
Logger.kukaiCoreSwift.error("Can't send an entire NFT group. Must send individual NFT's from token.nfts array, via the other sendOperation")
return []
}
}
Expand All @@ -66,7 +66,7 @@ public class OperationFactory {

// Return empty array if `amount` is a negaitve value
if amount < 0 {
os_log(.error, log: .kukaiCoreSwift, "Negative value passed to OperationFactory.sendOperation")
Logger.kukaiCoreSwift.error("Negative value passed to OperationFactory.sendOperation")
return []
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/KukaiCoreSwift/Models/RPC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class RPC<T: Decodable> {
return try JSONEncoder().encode(encodable)

} catch(let error) {
os_log(.error, log: .kukaiCoreSwift, "Unable to encode object as string: %@", "\(error)")
Logger.kukaiCoreSwift.error("Unable to encode object as string: \(error)")
return nil
}
}
Expand Down Expand Up @@ -161,7 +161,7 @@ extension RPC where T == [OperationResponse] {
/// Creates an RPC to preapply an operation. This `OperationPayload` must have had its signature and protocol set
public static func preapply(operationPayload: OperationPayload) -> RPC<[OperationResponse]>? {
if operationPayload.signature == nil || operationPayload.protocol == nil {
os_log(.error, log: .kukaiCoreSwift, "RPC preapply was passed an operationPayload without a signature and/or protocol")
Logger.kukaiCoreSwift.error("RPC preapply was passed an operationPayload without a signature and/or protocol")
return nil
}

Expand Down
19 changes: 8 additions & 11 deletions Sources/KukaiCoreSwift/Models/RegularWallet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ public class RegularWallet: Wallet {

/**
Attempt to create an instance of a `RegularWallet` from an encoded string containing a private key
- parameter withBase58String: String containing the Base58 encoded private key, prefixed with the curve's secret
- parameter ellipticalCurve: The ellipcatical curve used to create the key
- parameter secp256k1WithBase58String: String containing the Base58 encoded private key, prefixed with the curve's secret
- parameter type: WalletType indicating the top most type of wallet
*/
public init?(withBase58String: String, ellipticalCurve: EllipticalCurve, type: WalletType) {
guard let privateKey = PrivateKey(withBase58String, signingCurve: ellipticalCurve),
public init?(secp256k1WithBase58String base58String: String, type: WalletType) {
guard let privateKey = PrivateKey(base58String, signingCurve: .secp256k1),
let pubKey = KeyPair.secp256k1PublicKey(fromPrivateKeyBytes: privateKey.bytes),
let tempAddress = pubKey.publicKeyHash else {
os_log("Failed to construct private/public key", log: .kukaiCoreSwift, type: .error)
Logger.kukaiCoreSwift.error("Failed to construct private/public key")
return nil
}

Expand All @@ -64,10 +63,9 @@ public class RegularWallet: Wallet {
Create a `RegularWallet` by supplying a `Mnemonic` and a passphrase (or "" if none).
- Parameter withMnemonic: A `Mnemonic` representing a BIP39 menmonic
- Parameter passphrase: String contianing a passphrase, or empty string if none
- Parameter ellipticalCurve: Optional: Choose the `EllipticalCurve` used to generate the wallet address
*/
public init?(withMnemonic mnemonic: Mnemonic, passphrase: String, ellipticalCurve: EllipticalCurve = .ed25519) {
guard let keyPair = KeyPair.regular(fromMnemonic: mnemonic, passphrase: passphrase, andSigningCurve: ellipticalCurve), let pkh = keyPair.publicKey.publicKeyHash else {
public init?(withMnemonic mnemonic: Mnemonic, passphrase: String) {
guard let keyPair = KeyPair.regular(fromMnemonic: mnemonic, passphrase: passphrase), let pkh = keyPair.publicKey.publicKeyHash else {
return nil
}

Expand All @@ -82,11 +80,10 @@ public class RegularWallet: Wallet {
Create a `RegularWallet` by asking for a mnemonic of a given number of words and a passphrase (or "" if none).
- Parameter withMnemonicLength: `Mnemonic.NumberOfWords` the number of words to use when creating a mnemonic
- Parameter passphrase: String contianing a passphrase, or empty string if none
- Parameter ellipticalCurve: Optional: Choose the `EllipticalCurve` used to generate the wallet address
*/
public convenience init?(withMnemonicLength length: Mnemonic.NumberOfWords, passphrase: String, ellipticalCurve: EllipticalCurve = .ed25519) {
public convenience init?(withMnemonicLength length: Mnemonic.NumberOfWords, passphrase: String) {
if let mnemonic = try? Mnemonic(numberOfWords: length) {
self.init(withMnemonic: mnemonic, passphrase: passphrase, ellipticalCurve: ellipticalCurve)
self.init(withMnemonic: mnemonic, passphrase: passphrase)

} else {
return nil
Expand Down
8 changes: 5 additions & 3 deletions Sources/KukaiCoreSwift/Models/Token.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public class Token: Codable, CustomStringConvertible {

// TODO: make failable init
if let faVersion = faVersion, faVersion == .fa2 && tokenId == nil {
os_log("Error: FA2 tokens require having a tokenId set, %@", log: .kukaiCoreSwift, type: .error, name ?? tokenContractAddress ?? "")
Logger.kukaiCoreSwift.error("Error: FA2 tokens require having a tokenId set, \(name ?? tokenContractAddress ?? "")")
}
}

Expand All @@ -139,7 +139,8 @@ public class Token: Codable, CustomStringConvertible {

// TODO: make failable init
if let faVersion = faVersion, faVersion == .fa2 && tokenId == nil {
os_log("Error: FA2 tokens require having a tokenId set, %@", log: .kukaiCoreSwift, type: .error, name ?? tokenContractAddress ?? "")
weak var weakSelf = self
Logger.kukaiCoreSwift.error("Error: FA2 tokens require having a tokenId set, \(weakSelf?.name ?? weakSelf?.tokenContractAddress ?? "")")
}
}

Expand All @@ -164,7 +165,8 @@ public class Token: Codable, CustomStringConvertible {

// TODO: make failable init
if let faVersion = faVersion, faVersion == .fa2 && tokenId == nil {
os_log("Error: FA2 tokens require having a tokenId set, %@", log: .kukaiCoreSwift, type: .error, name ?? tokenContractAddress ?? "")
weak var weakSelf = self
Logger.kukaiCoreSwift.error("Error: FA2 tokens require having a tokenId set, \(weakSelf?.name ?? weakSelf?.tokenContractAddress ?? "")")
}
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/KukaiCoreSwift/Models/TokenAmount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class TokenAmount: Codable {
*/
public init?(fromRpcAmount rpcAmount: String, decimalPlaces: Int) {
guard CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: rpcAmount)) else {
os_log(.error, log: .kukaiCoreSwift, "Can't set balance on a Token of tokenType.empty, or pass in a string with non digit characters. Entered: %@", rpcAmount)
Logger.kukaiCoreSwift.error("Can't set balance on a Token of tokenType.empty, or pass in a string with non digit characters. Entered: \(rpcAmount)")
return nil
}

Expand Down Expand Up @@ -126,7 +126,7 @@ public class TokenAmount: Codable {
*/
public convenience init?(fromNormalisedAmount normalisedAmount: String, decimalPlaces: Int) {
guard let decimal = Decimal(string: normalisedAmount.replacingOccurrences(of: (Locale.current.decimalSeparator ?? "."), with: ".")) else {
os_log(.error, log: .kukaiCoreSwift, "Can't set balance as can't parse string")
Logger.kukaiCoreSwift.error("Can't set balance as can't parse string")
return nil
}

Expand Down Expand Up @@ -277,7 +277,7 @@ public class TokenAmount: Codable {
let result = (lhs.decimalPlaces == rhs.decimalPlaces)

if !result {
os_log(.error, log: .kukaiCoreSwift, "Arithmetic function is not possible between tokens with different decimal places. Ignoring operation.")
Logger.kukaiCoreSwift.error("Arithmetic function is not possible between tokens with different decimal places. Ignoring operation.")
}

return result
Expand Down
Loading

0 comments on commit 837edfe

Please sign in to comment.