|
| 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