Skip to content
This repository was archived by the owner on Sep 13, 2024. It is now read-only.

Commit 13fab26

Browse files
committed
Added Objective C support #192
1 parent 912b796 commit 13fab26

17 files changed

+3226
-97
lines changed

Sources/ObjectiveC/Bridging.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// Bridging.swift
3+
// web3swift
4+
//
5+
// Created by Dmitry on 09/11/2018.
6+
// Copyright © 2018 Bankex Foundation. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public protocol SwiftBridgeable {
12+
associatedtype SwiftType
13+
var swift: SwiftType { get }
14+
}
15+
public protocol SwiftContainer: SwiftBridgeable {
16+
init(_ swift: SwiftType)
17+
}
18+
19+
//public extension _ObjectiveCBridgeable where _ObjectiveCType: SwiftBridgeable, _ObjectiveCType.SwiftType == Self {
20+
// static func _forceBridgeFromObjectiveC(_ source: _ObjectiveCType, result: inout Self?) {
21+
// result = source.swift
22+
// }
23+
//
24+
// static func _conditionallyBridgeFromObjectiveC(_ source: _ObjectiveCType, result: inout Self?) -> Bool {
25+
// result = source.swift
26+
// return true
27+
// }
28+
//
29+
// static func _unconditionallyBridgeFromObjectiveC(_ source: _ObjectiveCType?) -> Self {
30+
// return source!.swift
31+
// }
32+
//}
33+
34+
//extension _ObjectiveCBridgeable {
35+
// var objc: _ObjectiveCType {
36+
// return _bridgeToObjectiveC()
37+
// }
38+
//}

Sources/ObjectiveC/W3Contract.swift

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//
2+
// W3Contract.swift
3+
// web3swift
4+
//
5+
// Created by Dmitry on 10/11/2018.
6+
// Copyright © 2018 Bankex Foundation. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
extension ContractV2.EventFilter {
12+
public var objc: W3ContractEventFilter {
13+
return W3ContractEventFilter(self)
14+
}
15+
}
16+
@objc public class W3ContractEventFilter: NSObject, SwiftContainer {
17+
public var swift: ContractV2.EventFilter
18+
public required init(_ swift: ContractV2.EventFilter) {
19+
self.swift = swift
20+
}
21+
22+
@objc public var parameterName: String {
23+
get { return swift.parameterName }
24+
set { swift.parameterName = newValue }
25+
}
26+
@objc public var parameterValues: [AnyObject] {
27+
get { return swift.parameterValues }
28+
set { swift.parameterValues = newValue }
29+
}
30+
}
31+
@objc public class W3ContractParsedEvent: NSObject {
32+
@objc public let eventName: String?
33+
@objc public let eventData: [String: Any]?
34+
init(eventName: String?, eventData: [String: Any]?) {
35+
self.eventName = eventName
36+
self.eventData = eventData
37+
}
38+
}
39+
40+
extension ContractProtocol {
41+
public var objc: W3Contract {
42+
return W3Contract(self as! ContractV2)
43+
}
44+
}
45+
46+
@objc public class W3Contract: NSObject, W3OptionsInheritable, SwiftContainer {
47+
public var swift: ContractV2
48+
var _swiftOptions: Web3Options {
49+
get { return swift.options }
50+
set { swift.options = newValue }
51+
}
52+
public required init(_ swift: ContractV2) {
53+
self.swift = swift
54+
super.init()
55+
options = W3Options(object: self)
56+
}
57+
58+
@objc public var allEvents: [String] {
59+
return swift.allEvents
60+
}
61+
62+
@objc public var allMethods: [String] {
63+
return swift.allMethods
64+
}
65+
66+
@objc public var address: W3Address? {
67+
get { return swift.address?.objc }
68+
set { swift.address = newValue?.swift }
69+
}
70+
71+
@objc public var options: W3Options!
72+
73+
@objc public init(_ abiString: String, at address: W3Address? = nil) throws {
74+
swift = try ContractV2(abiString, at: address?.swift)
75+
}
76+
77+
@objc public func deploy(bytecode: Data, parameters: [Any], extraData: Data?, options: W3Options?) throws -> W3EthereumTransaction {
78+
let extraData = extraData ?? Data()
79+
return try swift.deploy(bytecode: bytecode, parameters: parameters, extraData: extraData, options: options?.swift).objc
80+
}
81+
82+
@objc public func method(_ method: String, parameters: [Any], extraData: Data?, options: W3Options?) throws -> W3EthereumTransaction {
83+
let extraData = extraData ?? Data()
84+
return try swift.method(method, parameters: parameters, extraData: extraData, options: options?.swift).objc
85+
}
86+
87+
@objc public func parseEvent(_ eventLog: W3EventLog) -> W3ContractParsedEvent {
88+
let (name,data) = swift.parseEvent(eventLog.swift)
89+
return W3ContractParsedEvent(eventName: name, eventData: data)
90+
}
91+
92+
@objc public func testBloomForEventPrecence(eventName: String, bloom: W3EthereumBloomFilter) -> Bool {
93+
return swift.testBloomForEventPrecence(eventName: eventName, bloom: bloom.swift) ?? false
94+
}
95+
96+
@objc public func decodeReturnData(_ method: String, data: Data) -> [String: Any]? {
97+
return swift.decodeReturnData(method, data: data)
98+
}
99+
100+
@objc public func decodeInputData(_ method: String, data: Data) -> [String: Any]? {
101+
return swift.decodeInputData(method, data: data)
102+
}
103+
104+
@objc public func decodeInputData(_ data: Data) -> [String: Any]? {
105+
return swift.decodeInputData(data)
106+
}
107+
}
108+

0 commit comments

Comments
 (0)