Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c53c4e4
Delete untyped decode methods.
yaroslavyaroslav Apr 28, 2022
e4012bf
Add generic encodeHex methods to `(Un)KeyedEncodingContainer`
yaroslavyaroslav May 3, 2022
d86583b
Update `Encodable+Extensions` to be generic.
yaroslavyaroslav May 10, 2022
24dc3a8
Making memos to methods.
yaroslavyaroslav May 13, 2022
cd751ee
`JSONRPCParam` enum implementation.
yaroslavyaroslav May 14, 2022
fb4c10d
`JSONRPCparams` replaced with `[JSONRPCParameter]` in outgoing API ca…
yaroslavyaroslav May 15, 2022
88c84bb
To create `JSONRPCrequest` parameters should conforms `JSONRPCParamet…
yaroslavyaroslav May 17, 2022
72e7ad9
Move JSONRPCParameter to separate file.
yaroslavyaroslav May 18, 2022
9f79702
Update UInt64 to UInt since this accuracy isn't required.
yaroslavyaroslav May 19, 2022
d7953dc
Change UInt64 to UInt.
yaroslavyaroslav May 22, 2022
e439b04
Remove commented out piece of code
yaroslavyaroslav May 22, 2022
1a7734e
Make Counter.increment() static method mode clear
yaroslavyaroslav May 22, 2022
8398c5d
Fix feeHistory logic bug
yaroslavyaroslav May 22, 2022
8c0e119
Make async/await internal API consistent
yaroslavyaroslav May 22, 2022
dfe4f72
Delete duplicate BlockNumber enum in FeeHistory.
yaroslavyaroslav May 22, 2022
e4fcc1d
Add EthJSONRPC enum to encapsulate REST logic.
yaroslavyaroslav May 23, 2022
f1ab07d
Method `sendRequest<U>(with call: EthJSONRPC) async throws -> EthResp…
yaroslavyaroslav May 24, 2022
9e0343c
Rename request types
yaroslavyaroslav May 24, 2022
5db2272
Implement most of required protocols to make decoding responses to ge…
yaroslavyaroslav May 25, 2022
245cc0d
Make `APIRequestParameterType` internal.
yaroslavyaroslav May 25, 2022
2a54eec
Refactor API a bit.
yaroslavyaroslav May 26, 2022
4e69483
Update for new Network layer:
yaroslavyaroslav May 26, 2022
635009a
Update for network layer:
yaroslavyaroslav May 27, 2022
27a28e2
Update clients code for changes made
yaroslavyaroslav May 27, 2022
351b671
Update for network layer:
yaroslavyaroslav May 27, 2022
7c5126a
Refactor code a bit.
yaroslavyaroslav May 27, 2022
412972b
Update for network layer:
yaroslavyaroslav May 27, 2022
2de0d21
Revert `BigUInt` to `UInt` type changes.
yaroslavyaroslav May 27, 2022
8207727
Rename API calls files and folder
yaroslavyaroslav May 27, 2022
216686e
Encapsulate request methods into APIRequest enum.
yaroslavyaroslav May 31, 2022
dddf1f2
Rename `getTransactionCount(address:, onBlock:)` to `getTransactionCo…
yaroslavyaroslav May 31, 2022
65c5a53
Add TxPool and getLog implementation
yaroslavyaroslav May 31, 2022
b24948f
Temporary disable Websocket provider.
yaroslavyaroslav May 31, 2022
0bc450b
Delete old HTTP(S) network code.
yaroslavyaroslav May 31, 2022
983d084
Temporary comment out not failed to build tests.
yaroslavyaroslav May 31, 2022
bbe64ef
Comment out some duplicating code.
yaroslavyaroslav May 31, 2022
16d6f1c
Delete `Web3+Eth.swift` since its purpose were to make Promise method…
yaroslavyaroslav May 31, 2022
6611999
Rename deleted methods in tests and BrowserFunctions to new one.
yaroslavyaroslav May 31, 2022
fec0bc0
Little code formatting
yaroslavyaroslav Jun 1, 2022
78301bd
Fix wrong sendTransaction request bug.
yaroslavyaroslav Jun 2, 2022
41ac98f
Fix `gasLimit` and `gasPrice` request bug.
yaroslavyaroslav Jun 2, 2022
23ef94a
Add Data type support by conforming `LiteralInitiableFromString` prot…
yaroslavyaroslav Jun 2, 2022
fa80d43
Implement `GetLogs` call.
yaroslavyaroslav Jun 3, 2022
90e2061
Update Web3HTTPProvider
yaroslavyaroslav Jun 5, 2022
55732ab
Delete unused `URLSession.data` method method.
yaroslavyaroslav Jun 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Delete old HTTP(S) network code.
  • Loading branch information
yaroslavyaroslav committed May 31, 2022
commit 0bc450baea54d110b221702872d064bb200cc954
6 changes: 0 additions & 6 deletions Sources/web3swift/Web3/Web3+Instance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ import BigInt
public class web3 {
public var provider: Web3Provider
public var transactionOptions: TransactionOptions = TransactionOptions.defaultOptions
public var defaultBlock = "latest"

/// Add a provider request to the dispatch queue.
public func dispatch(_ request: JSONRPCrequest) async throws -> JSONRPCresponse {
try await provider.sendAsync(request)
}

/// Raw initializer using a Web3Provider protocol object, dispatch queue and request dispatcher.
public init(provider prov: Web3Provider) {
Expand Down
231 changes: 0 additions & 231 deletions Sources/web3swift/Web3/Web3+JSONRPC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,237 +23,6 @@ public struct Counter {
}
}

/// JSON RPC request structure for serialization and deserialization purposes.
//public struct JSONRPCrequest<T: Encodable>: Encodable {
public struct JSONRPCrequest: Encodable {
public var jsonrpc: String = "2.0"
public var method: JSONRPCmethod?
public var params: [RequestParameter] = []
public var id: UInt = Counter.increment()

enum CodingKeys: String, CodingKey {
case jsonrpc
case method
case params
case id
}

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(jsonrpc, forKey: .jsonrpc)
try container.encode(method?.rawValue, forKey: .method)
try container.encode(params, forKey: .params)
try container.encode(id, forKey: .id)
}

public var isValid: Bool {
get {
if self.method == nil {
return false
}
guard let method = self.method else {return false}
return method.requiredNumOfParameters == self.params.count
}
}
}

/// JSON RPC batch request structure for serialization and deserialization purposes.
public struct JSONRPCrequestBatch: Encodable {
var requests: [JSONRPCrequest]

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(self.requests)
}
}

/// JSON RPC response structure for serialization and deserialization purposes.
public struct JSONRPCresponse: Decodable{
public var id: Int
public var jsonrpc = "2.0"
public var result: Any?
public var error: ErrorMessage?
public var message: String?

enum JSONRPCresponseKeys: String, CodingKey {
case id = "id"
case jsonrpc = "jsonrpc"
case result = "result"
case error = "error"
}

public init(id: Int, jsonrpc: String, result: Any?, error: ErrorMessage?) {
self.id = id
self.jsonrpc = jsonrpc
self.result = result
self.error = error
}

public struct ErrorMessage: Decodable {
public var code: Int
public var message: String
}

internal var decodableTypes: [Decodable.Type] = [
[EventLog].self,
[TransactionDetails].self,
[TransactionReceipt].self,
[Block].self,
[String].self,
[Int].self,
[Bool].self,
EventLog.self,
TransactionDetails.self,
TransactionReceipt.self,
Block.self,
String.self,
Int.self,
Bool.self,
[String: String].self,
[String: Int].self,
[String: [String: [String: [String]]]].self,
Web3.Oracle.FeeHistory.self
]

// FIXME: Make me a real generic
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: JSONRPCresponseKeys.self)
let id: Int = try container.decode(Int.self, forKey: .id)
let jsonrpc: String = try container.decode(String.self, forKey: .jsonrpc)
let errorMessage = try container.decodeIfPresent(ErrorMessage.self, forKey: .error)
if errorMessage != nil {
self.init(id: id, jsonrpc: jsonrpc, result: nil, error: errorMessage)
return
}
// TODO: make me generic (DecodableFromHex or Decodable)
/// This is all available types of `result` to init
/// Now its type is `Any?`, since you're typecasting this any to exact each response,
/// coz you're knowing response to what request it would be,
/// and you're could be sure about API Response structure.
///
/// So since we're typecasting this explicitly each tyme, `result` property could be set
/// to protocol type like `Decodable` or `DevodableFromHex` or something,
/// and this code could be reduced so hard.
var result: Any? = nil
if let rawValue = try? container.decodeIfPresent(String.self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent(Int.self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent(Bool.self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent(EventLog.self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent(Block.self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent(TransactionReceipt.self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent(TransactionDetails.self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent([EventLog].self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent([Block].self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent([TransactionReceipt].self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent([TransactionDetails].self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent(TxPoolStatus.self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent(TxPoolContent.self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent([Bool].self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent([Int].self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent([String].self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent([String: String].self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent([String: Int].self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent([String: [String: [String: String]]].self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent([String: [String: [String: [String: String?]]]].self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent(Web3.Oracle.FeeHistory.self, forKey: .result) {
result = rawValue
}
self.init(id: id, jsonrpc: jsonrpc, result: result, error: nil)
}

// FIXME: Make me a real generic
// MARK: - This fits for DecodableFromHex
/// Get the JSON RCP reponse value by deserializing it into some native <T> class.
///
/// Returns nil if serialization fails
public func getValue<T>() -> T? {
let type = T.self

if type == BigUInt.self {
guard let string = self.result as? String else {return nil}
guard let value = BigUInt(string.stripHexPrefix(), radix: 16) else {return nil}
return value as? T
} else if type == BigInt.self {
guard let string = self.result as? String else {return nil}
guard let value = BigInt(string.stripHexPrefix(), radix: 16) else {return nil}
return value as? T
} else if type == Data.self {
guard let string = self.result as? String else {return nil}
guard let value = Data.fromHex(string) else {return nil}
return value as? T
} else if type == EthereumAddress.self {
guard let string = self.result as? String else {return nil}
guard let value = EthereumAddress(string, ignoreChecksum: true) else {return nil}
return value as? T
}
// else if slf == String.self {
// guard let value = self.result as? T else {return nil}
// return value
// } else if slf == Int.self {
// guard let value = self.result as? T else {return nil}
// return value
// }
else if type == [BigUInt].self {
guard let string = self.result as? [String] else {return nil}
let values = string.compactMap { (str) -> BigUInt? in
return BigUInt(str.stripHexPrefix(), radix: 16)
}
return values as? T
} else if type == [BigInt].self {
guard let string = self.result as? [String] else {return nil}
let values = string.compactMap { (str) -> BigInt? in
return BigInt(str.stripHexPrefix(), radix: 16)
}
return values as? T
} else if type == [Data].self {
guard let string = self.result as? [String] else {return nil}
let values = string.compactMap { (str) -> Data? in
return Data.fromHex(str)
}
return values as? T
} else if type == [EthereumAddress].self {
guard let string = self.result as? [String] else {return nil}
let values = string.compactMap { (str) -> EthereumAddress? in
return EthereumAddress(str, ignoreChecksum: true)
}
return values as? T
}
guard let value = self.result as? T else {return nil}
return value
}
}

/// JSON RPC batch response structure for serialization and deserialization purposes.
public struct JSONRPCresponseBatch: Decodable {
var responses: [JSONRPCresponse]

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let responses = try container.decode([JSONRPCresponse].self)
self.responses = responses
}
}

/// Transaction parameters JSON structure for interaction with Ethereum node.
public struct TransactionParameters: Codable {
/// accessList parameter JSON structure
Expand Down
92 changes: 0 additions & 92 deletions Sources/web3swift/Web3/Web3+Methods.swift

This file was deleted.