Skip to content

Commit

Permalink
Merge pull request #209 from matter-labs/infuraV3update
Browse files Browse the repository at this point in the history
infura v3 complete update
  • Loading branch information
BaldyAsh authored Jun 24, 2019
2 parents 5c0e7e8 + c5212c1 commit e94f2e1
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github "mxcl/PromiseKit" ~> 6.8.4
github "attaswift/BigInt" ~> 3.1
github "attaswift/BigInt" ~> 4.0
github "daltoniam/Starscream" ~> 3.1.0
github "krzyzanowskim/CryptoSwift" ~> 1.0.0
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Build Status](https://travis-ci.com/matter-labs/web3swift.svg?branch=develop)](https://travis-ci.com/matter-labs/web3swift)
[![Swift](https://img.shields.io/badge/Swift-5.0-orange.svg?style=flat)](https://developer.apple.com/swift/)
[![Platform](https://img.shields.io/cocoapods/p/web3swift.svg?style=flat)](http://cocoapods.org/pods/web3.swift.pod)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/web3swift.svg?style=flat)](http://cocoapods.org/pods/web3.swift.pod)
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/web3.swift.pod.svg?style=flat)](http://cocoapods.org/pods/web3.swift.pod)
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![License](https://img.shields.io/cocoapods/l/web3swift.svg?style=flat)](http://cocoapods.org/pods/web3.swift.pod)
[![support](https://brianmacdonald.github.io/Ethonate/svg/eth-support-blue.svg)](https://brianmacdonald.github.io/Ethonate/address#0xe22b8979739d724343bd002f9f432f5990879901)
Expand Down
15 changes: 15 additions & 0 deletions Sources/web3swift/Web3/Web3+Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Web3+Constants.swift
// web3swift
//
// Created by Anton on 24/06/2019.
// Copyright © 2019 Bankex Foundation. All rights reserved.
//

import Foundation

struct Constants {
static let infuraHttpScheme = ".infura.io/v3/"
static let infuraWsScheme = ".infura.io/ws/v3/"
static let infuraToken = "4406c3acf862426c83991f1752c46dd8"
}
8 changes: 3 additions & 5 deletions Sources/web3swift/Web3/Web3+InfuraProviders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ public enum BlockNumber {
/// Custom Web3 HTTP provider of Infura nodes.
public final class InfuraProvider: Web3HttpProvider {
public init?(_ net:Networks, accessToken token: String? = nil, keystoreManager manager: KeystoreManager? = nil) {
var requestURLstring = "https://" + net.name + ".infura.io/"
if token != nil {
requestURLstring = requestURLstring + token!
}
var requestURLstring = "https://" + net.name + Constants.infuraHttpScheme
requestURLstring += token != nil ? token! : Constants.infuraToken
let providerURL = URL(string: requestURLstring)
super.init(providerURL!, network: net, keystoreManager: manager)
}
Expand All @@ -55,7 +53,7 @@ public final class InfuraWebsocketProvider: WebsocketProvider {
|| network == Networks.Ropsten
|| network == Networks.Mainnet else {return nil}
let networkName = network.name
let urlString = "wss://\(networkName).infura.io/ws/v3/"
let urlString = "wss://" + networkName + Constants.infuraWsScheme
guard URL(string: urlString) != nil else {return nil}
super.init(urlString,
delegate: delegate,
Expand Down
56 changes: 23 additions & 33 deletions Sources/web3swift/Web3/Web3+WebsocketProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ public class WebsocketProvider: Web3Provider, IWebsocketProvider, WebSocketDeleg
if !(endpointString.hasPrefix("wss://") || endpointString.hasPrefix("ws://")) {
return nil
}
if net == nil {
if endpointString.hasPrefix("wss://") && endpointString.hasSuffix(".infura.io/ws") {
if endpointString.hasPrefix("wss://") && endpointString.hasSuffix(Constants.infuraWsScheme) {
if net == nil {
let networkString = endpointString.replacingOccurrences(of: "wss://", with: "")
.replacingOccurrences(of: ".infura.io/ws", with: "")
.replacingOccurrences(of: Constants.infuraWsScheme, with: "")
switch networkString {
case "mainnet":
network = Networks.Mainnet
Expand All @@ -143,17 +143,17 @@ public class WebsocketProvider: Web3Provider, IWebsocketProvider, WebSocketDeleg
default:
break
}
} else {
network = net
}
if network != nil {
endpointString += projectId ?? Constants.infuraToken
}
} else {
network = net
}
if network != nil {
endpointString += projectId ?? "4406c3acf862426c83991f1752c46dd8"
}
url = URL(string: endpointString)!
delegate = wsdelegate
attachedKeystoreManager = manager
socket = WebSocket(url: endpoint)
socket = WebSocket(url: url)
socket.delegate = self
}

Expand All @@ -162,22 +162,16 @@ public class WebsocketProvider: Web3Provider, IWebsocketProvider, WebSocketDeleg
projectId: String? = nil,
keystoreManager manager: KeystoreManager? = nil,
network net: Networks? = nil) {
guard URL(string: endpoint) != nil else {return nil}
var finalEndpoint = endpoint
websocketConnected = false
var endpointString = endpoint
if !(endpointString.hasPrefix("wss://") || endpointString.hasPrefix("ws://")) {
if !(endpoint.hasPrefix("wss://") || endpoint.hasPrefix("ws://")) {
return nil
}
if net == nil {
if endpointString.hasPrefix("wss://")
&& (endpointString.hasSuffix(".infura.io/ws/v3/")
|| endpointString.hasSuffix(".infura.io/ws/v3")
|| endpointString.hasSuffix(".infura.io/ws/")
|| endpointString.hasSuffix(".infura.io/ws")) {
let networkString = endpointString.replacingOccurrences(of: "wss://", with: "")
.replacingOccurrences(of: ".infura.io/ws/v3/", with: "")
.replacingOccurrences(of: ".infura.io/ws/v3", with: "")
.replacingOccurrences(of: ".infura.io/ws/", with: "")
.replacingOccurrences(of: ".infura.io/ws", with: "")
if endpoint.hasPrefix("wss://") && endpoint.hasSuffix(Constants.infuraWsScheme) {
if net == nil {
let networkString = endpoint.replacingOccurrences(of: "wss://", with: "")
.replacingOccurrences(of: Constants.infuraWsScheme, with: "")
switch networkString {
case "mainnet":
network = Networks.Mainnet
Expand All @@ -190,21 +184,17 @@ public class WebsocketProvider: Web3Provider, IWebsocketProvider, WebSocketDeleg
default:
break
}
} else {
network = net
}
if network != nil {
finalEndpoint += projectId ?? Constants.infuraToken
}
} else {
network = net
}
if network != nil {
if endpointString.hasSuffix(".infura.io/ws/v3") { endpointString += "/"}
else if endpointString.hasSuffix(".infura.io/ws/") { endpointString += "v3/"}
else if endpointString.hasSuffix(".infura.io/ws") { endpointString += "/v3/"}
endpointString += projectId ?? "4406c3acf862426c83991f1752c46dd8"
}
guard let endpointUrl = URL(string: endpointString) else {return nil}
url = endpointUrl
url = URL(string: finalEndpoint)!
delegate = wsdelegate
attachedKeystoreManager = manager
socket = WebSocket(url: endpointUrl)
socket = WebSocket(url: url)
socket.delegate = self
}

Expand Down
4 changes: 2 additions & 2 deletions Web3swift.pod.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'Web3swift.pod'
spec.version = '2.2.0'
spec.version = '2.2.1'
spec.ios.deployment_target = "9.0"
spec.osx.deployment_target = "10.11"
spec.license = { :type => 'Apache License 2.0', :file => 'LICENSE.md' }
Expand All @@ -13,7 +13,7 @@ Pod::Spec.new do |spec|
spec.module_name = 'web3swift'
spec.frameworks = 'CoreImage'
spec.dependency 'PromiseKit', '~> 6.8.4'
spec.dependency 'BigInt', '~> 3.1'
spec.dependency 'BigInt', '~> 4.0'
spec.dependency 'Starscream', '~> 3.1.0'
spec.dependency 'CryptoSwift', '~> 1.0.0'
spec.dependency 'secp256k1.c', '~> 0.1'
Expand Down
4 changes: 2 additions & 2 deletions web3swift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'web3swift'
spec.version = '2.2.0'
spec.version = '2.2.1'
spec.ios.deployment_target = "9.0"
spec.osx.deployment_target = "10.11"
spec.license = { :type => 'Apache License 2.0', :file => 'LICENSE.md' }
Expand All @@ -12,7 +12,7 @@ Pod::Spec.new do |spec|
spec.swift_version = '5.0'
spec.frameworks = 'CoreImage'
spec.dependency 'PromiseKit', '~> 6.8.4'
spec.dependency 'BigInt', '~> 3.1'
spec.dependency 'BigInt', '~> 4.0'
spec.dependency 'Starscream', '~> 3.1.0'
spec.dependency 'CryptoSwift', '~> 1.0.0'
spec.dependency 'secp256k1.c', '~> 0.1'
Expand Down
16 changes: 11 additions & 5 deletions web3swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
3AA816372276E48400F5DB52 /* web3swift_Eventloop_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA816222276E48400F5DB52 /* web3swift_Eventloop_Tests.swift */; };
3AA816382276E48400F5DB52 /* web3swift_Websockets_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA816232276E48400F5DB52 /* web3swift_Websockets_Tests.swift */; };
3AA8163A2276E4AE00F5DB52 /* SECP256k1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA816392276E4AE00F5DB52 /* SECP256k1.swift */; };
3AEF4ABF22C0B6BE00AC7929 /* Web3+Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AEF4ABE22C0B6BE00AC7929 /* Web3+Constants.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -383,6 +384,7 @@
3AA8163F2276E5A800F5DB52 /* LICENSE.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = LICENSE.md; sourceTree = "<group>"; };
3AA816402276E5A800F5DB52 /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
3AA816412276E5A900F5DB52 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
3AEF4ABE22C0B6BE00AC7929 /* Web3+Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Web3+Constants.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -697,6 +699,7 @@
3AA815542276E44100F5DB52 /* Web3+Utils.swift */,
3AA815552276E44100F5DB52 /* Web3+MutatingTransaction.swift */,
3AA815562276E44100F5DB52 /* Web3+JSONRPC.swift */,
3AEF4ABE22C0B6BE00AC7929 /* Web3+Constants.swift */,
3AA815572276E44100F5DB52 /* Web3+Instance.swift */,
3AA815582276E44100F5DB52 /* Web3+Contract.swift */,
3AA815592276E44100F5DB52 /* Web3+EventParser.swift */,
Expand Down Expand Up @@ -1177,6 +1180,7 @@
3AA816062276E44100F5DB52 /* Web3+ST20.swift in Sources */,
3AA815FA2276E44100F5DB52 /* Promise+Web3+Eth+GetAccounts.swift in Sources */,
3AA815E72276E44100F5DB52 /* Array+Extension.swift in Sources */,
3AEF4ABF22C0B6BE00AC7929 /* Web3+Constants.swift in Sources */,
3AA815DD2276E44100F5DB52 /* Web3+Options.swift in Sources */,
3AA815A92276E44100F5DB52 /* ENSReverseRegistrar.swift in Sources */,
3AA815EF2276E44100F5DB52 /* Promise+HttpProvider.swift in Sources */,
Expand Down Expand Up @@ -1449,7 +1453,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 8DB897QKJA;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down Expand Up @@ -1496,7 +1500,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 8DB897QKJA;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down Expand Up @@ -1545,7 +1549,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 8DB897QKJA;
"FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]" = "$(SRCROOT)/Carthage/Build/iOS";
"FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]" = "$(SRCROOT)/Carthage/Build/iOS";
"FRAMEWORK_SEARCH_PATHS[sdk=macosx*]" = "$(SRCROOT)/Carthage/Build/Mac";
Expand Down Expand Up @@ -1577,7 +1581,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = 8DB897QKJA;
"FRAMEWORK_SEARCH_PATHS[sdk=iphoneos*]" = "$(SRCROOT)/Carthage/Build/iOS";
"FRAMEWORK_SEARCH_PATHS[sdk=iphonesimulator*]" = "$(SRCROOT)/Carthage/Build/iOS";
"FRAMEWORK_SEARCH_PATHS[sdk=macosx*]" = "$(SRCROOT)/Carthage/Build/Mac";
Expand Down Expand Up @@ -1607,10 +1611,11 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_IDENTITY = "Mac Developer";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 8DB897QKJA;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down Expand Up @@ -1647,6 +1652,7 @@
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 8DB897QKJA;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
Expand Down

0 comments on commit e94f2e1

Please sign in to comment.