Skip to content

Commit 749829f

Browse files
Move Core features to Core module.
It's building (but not testing yet)
1 parent 4e48da8 commit 749829f

File tree

151 files changed

+870
-650
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+870
-650
lines changed

Package.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ let package = Package(
1919
products: [
2020
.library(name: "web3swift", targets: ["web3swift"])
2121
],
22-
2322
dependencies: [
2423
.package(url: "https://github.com/attaswift/BigInt.git", from: "5.3.0"),
2524
.package(url: "https://github.com/daltoniam/Starscream.git", from: "4.0.4"),
2625
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", from: "1.5.1")
2726
],
2827
targets: [
2928
.target(name: "secp256k1"),
29+
.target(
30+
name: "Core",
31+
dependencies: ["BigInt", "secp256k1", "CryptoSwift"]
32+
),
3033
.target(
3134
name: "web3swift",
32-
dependencies: ["BigInt", "secp256k1", "Starscream", "CryptoSwift"],
35+
dependencies: ["Core", "BigInt", "secp256k1", "Starscream", "CryptoSwift"],
3336
exclude: excludeFiles,
3437
resources: [
3538
.copy("./Browser/browser.js"),

Sources/web3swift/Convenience/Array+Extension.swift renamed to Sources/Core/Convenience/Array+Extension.swift

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,3 @@ extension Array where Element: Comparable {
2828
return sortedArray
2929
}
3030
}
31-
32-
extension Array where Element: BinaryInteger {
33-
// TODO: Make me generic
34-
/// Calculates mean value of a dataset
35-
/// - Returns: Mean value of a dataset, nil if dataset is empty
36-
func mean() -> BigUInt? {
37-
guard !self.isEmpty else { return nil }
38-
return BigUInt(self.reduce(0, +)) / BigUInt(self.count)
39-
}
40-
41-
42-
/// Calculates percentile of dataset on which get called.
43-
/// - Parameter value: Percentile value.
44-
/// - Returns: Item from dataset that is belongs to given percentile, nil if dataset is empty.
45-
func percentile(of value: Double) -> Element? {
46-
guard !self.isEmpty else { return nil }
47-
48-
let normalizedValue = value / 100 * Double(self.count)
49-
let index = Int(ceil(normalizedValue))
50-
51-
let sorted_data = self.sorted()
52-
guard index < self.count else { return sorted_data[sorted_data.count - 1] }
53-
return sorted_data[index]
54-
}
55-
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// RIPEMD160_SO.swift
3+
// web3swift
4+
//
5+
// Created by Alexander Vlasov on 10.01.2018.
6+
//
7+
8+
import Foundation
9+
import struct BigInt.BigUInt
10+
11+
extension BigUInt {
12+
init?(_ naturalUnits: String, _ ethereumUnits: Utilities.Units) {
13+
guard let value = Utilities.parseToBigUInt(naturalUnits, units: ethereumUnits) else {return nil}
14+
self = value
15+
}
16+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Yaroslav Yashin on 11.07.2022.
6+
//
7+
8+
import Foundation
9+
import BigInt
10+
11+
public enum BlockNumber {
12+
case pending
13+
/// Latest block of a chain
14+
case latest
15+
/// Earliest block of a chain
16+
case earliest
17+
/// Exact block number
18+
case exact(BigUInt)
19+
20+
/// Block number as a hex string
21+
public var stringValue: String {
22+
switch self {
23+
case .pending:
24+
return "pending"
25+
case .latest:
26+
return "latest"
27+
case .earliest:
28+
return "earliest"
29+
case .exact(let number):
30+
return String(number, radix: 16).addHexPrefix()
31+
}
32+
}
33+
}

Sources/web3swift/Convenience/Data+Extension.swift renamed to Sources/Core/Convenience/Data+Extension.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@ public extension Data {
6060
return nil
6161
}
6262

63-
static func fromHex(_ hex: String) -> Data? {
64-
let string = hex.lowercased().stripHexPrefix()
65-
let array = Array<UInt8>(hex: string)
66-
if (array.count == 0) {
67-
if (hex == "0x" || hex == "") {
68-
return Data()
69-
} else {
70-
return nil
71-
}
72-
}
73-
return Data(array)
74-
}
75-
7663
func bitsInRange(_ startingBit: Int, _ length: Int) -> UInt64? { // return max of 8 bytes for simplicity, non-public
7764
if startingBit + length / 8 > self.count, length > 64, startingBit > 0, length >= 1 {return nil}
7865
let bytes = self[(startingBit/8) ..< (startingBit+length+7)/8]

0 commit comments

Comments
 (0)