Skip to content

Commit

Permalink
Merge pull request #63 from cryptape/rc/v0.23
Browse files Browse the repository at this point in the history
Rc/v0.23
  • Loading branch information
XiaoLu authored Apr 30, 2019
2 parents 3f12ab5 + de73b85 commit edc5950
Show file tree
Hide file tree
Showing 23 changed files with 389 additions and 203 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: objective-c
osx_image: xcode10.1
osx_image: xcode10.2
xcode_workspace: CITA.xcworkspace
xcode_scheme: CITA
xcode_destination: platform=iOS Simulator,OS=11.3,name=iPhone X
xcode_destination: platform=iOS Simulator,OS=12.2,name=iPhone X
before_install:
- echo "{\"rpcServer\":\"$TEST_RPC_SERVER\"}" > Tests/Config.json
- travis_wait pod repo update --silent
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
All notable changes to this project will be documented in this file.

# [v0.23](https://github.com/cryptape/cita-sdk-swift/compare/v0.22...v0.23) (2019-04-30)

### CHANGES

* [Feature] Add `getVersion` interface
* [Feature] Add `peersInfo` interface

# [v0.22](https://github.com/cryptape/cita-sdk-swift/compare/v0.21...v0.22) (2019-03-28)

### CHANGES
Expand Down
2 changes: 1 addition & 1 deletion CITA.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CITA"
s.version = "0.22.0"
s.version = "0.23.0"
s.summary = "CITA SDK implementation in Swift for iOS"

s.description = <<-DESC
Expand Down
26 changes: 20 additions & 6 deletions CITA.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@
1AD65FA12122A1F900AA4C84 /* TransactionSendingResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AD65FA02122A1F900AA4C84 /* TransactionSendingResult.swift */; };
1AD65FA62122AF4400AA4C84 /* SignerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AD65FA42122AF2F00AA4C84 /* SignerTest.swift */; };
89733041217EB559001B8D93 /* MessageSigner.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89733040217EB559001B8D93 /* MessageSigner.swift */; };
89C046D7226D6B7300140A0D /* PeersInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89C046D6226D6B7300140A0D /* PeersInfo.swift */; };
89C046D9226D6D1700140A0D /* Version.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89C046D8226D6D1700140A0D /* Version.swift */; };
89CDA5F121E848F00049A244 /* CITAError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89CDA5F021E848F00049A244 /* CITAError.swift */; };
89CDA5F421E848FD0049A244 /* CITA.h in Headers */ = {isa = PBXBuildFile; fileRef = 89CDA5F221E848FD0049A244 /* CITA.h */; settings = {ATTRIBUTES = (Public, ); }; };
89CDA5F521E848FD0049A244 /* CITA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89CDA5F321E848FD0049A244 /* CITA.swift */; };
89CDA5F821E849570049A244 /* CITATests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89CDA5F621E849220049A244 /* CITATests.swift */; };
89CE3F9E22530042001DF3F3 /* Secp256k1Error.swift in Sources */ = {isa = PBXBuildFile; fileRef = 89CE3F9D22530042001DF3F3 /* Secp256k1Error.swift */; };
A761B95773C2431357D1B0B9 /* Pods_CITA.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A425B554C4D9A6E8284FEAC /* Pods_CITA.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -120,10 +123,13 @@
7FF8D9768BC7235E22EC11C8 /* Pods-CITA.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CITA.release.xcconfig"; path = "Pods/Target Support Files/Pods-CITA/Pods-CITA.release.xcconfig"; sourceTree = "<group>"; };
89733040217EB559001B8D93 /* MessageSigner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageSigner.swift; sourceTree = "<group>"; };
8990CDB62160682F00205129 /* Config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Config.json; sourceTree = "<group>"; };
89C046D6226D6B7300140A0D /* PeersInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PeersInfo.swift; sourceTree = "<group>"; };
89C046D8226D6D1700140A0D /* Version.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = "<group>"; };
89CDA5F021E848F00049A244 /* CITAError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CITAError.swift; sourceTree = "<group>"; };
89CDA5F221E848FD0049A244 /* CITA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CITA.h; sourceTree = "<group>"; };
89CDA5F321E848FD0049A244 /* CITA.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CITA.swift; sourceTree = "<group>"; };
89CDA5F621E849220049A244 /* CITATests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CITATests.swift; sourceTree = "<group>"; };
89CE3F9D22530042001DF3F3 /* Secp256k1Error.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Secp256k1Error.swift; sourceTree = "<group>"; };
D9D78017E61E65184F73D1F8 /* Pods-CITA.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CITA.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CITA/Pods-CITA.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -230,6 +236,7 @@
1AB5C6D9212125A200148587 /* Int+Extension.swift */,
1AD65F8F21217AC000AA4C84 /* DecodeUtils.swift */,
1AD65F9C2122999900AA4C84 /* Secp251k1.swift */,
89CE3F9D22530042001DF3F3 /* Secp256k1Error.swift */,
1A6B2B2821533FA5003420A0 /* Address.swift */,
89CDA5F021E848F00049A244 /* CITAError.swift */,
1A9204DF2161B20B004B54DC /* Utils.swift */,
Expand Down Expand Up @@ -261,6 +268,8 @@
1AD65FA02122A1F900AA4C84 /* TransactionSendingResult.swift */,
1A0D0C022185A717003E680D /* EventLog.swift */,
1A0D0C042185A861003E680D /* BloomFilter.swift */,
89C046D6226D6B7300140A0D /* PeersInfo.swift */,
89C046D8226D6D1700140A0D /* Version.swift */,
);
path = Structures;
sourceTree = "<group>";
Expand Down Expand Up @@ -480,7 +489,7 @@
"${BUILT_PRODUCTS_DIR}/PromiseKit/PromiseKit.framework",
"${BUILT_PRODUCTS_DIR}/SipHash/SipHash.framework",
"${BUILT_PRODUCTS_DIR}/SwiftProtobuf/SwiftProtobuf.framework",
"${BUILT_PRODUCTS_DIR}/secp256k1_swift/secp256k1_swift.framework",
"${BUILT_PRODUCTS_DIR}/secp256k1.swift/secp256k1.framework",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
Expand All @@ -491,7 +500,7 @@
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/PromiseKit.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SipHash.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftProtobuf.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/secp256k1_swift.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/secp256k1.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
Expand Down Expand Up @@ -536,6 +545,9 @@
1AD65F8E2121795B00AA4C84 /* TransactionReceipt.swift in Sources */,
1AD65F97212294C800AA4C84 /* Transaction.swift in Sources */,
1A0D0C032185A717003E680D /* EventLog.swift in Sources */,
89C046D7226D6B7300140A0D /* PeersInfo.swift in Sources */,
89CE3F9E22530042001DF3F3 /* Secp256k1Error.swift in Sources */,
89C046D9226D6D1700140A0D /* Version.swift in Sources */,
1ACBC9B52184596300F20B8B /* Proof.swift in Sources */,
1A6B2B2921533FA5003420A0 /* Address.swift in Sources */,
1A67ED5F211D55E500DCE871 /* MetaData.swift in Sources */,
Expand Down Expand Up @@ -645,6 +657,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -701,6 +714,7 @@
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 5.0;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -730,7 +744,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -757,7 +771,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.cryptape.cita;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -775,7 +789,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.cryptape.CITATests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -793,7 +807,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.cryptape.CITATests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ target 'CITA' do
inhibit_all_warnings!

pod "SwiftProtobuf", "~> 1.2.0"
pod "secp256k1_swift", "~> 1.0.3", modular_headers: true
pod "secp256k1.swift", "~> 0.1.4"
pod "CryptoSwift", "~> 0.13"
pod "BigInt", "~> 3.1"
pod "PromiseKit", "~> 6.5"
Expand Down
10 changes: 5 additions & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PODS:
- PromiseKit/CorePromise
- PromiseKit/UIKit (6.5.2):
- PromiseKit/CorePromise
- secp256k1_swift (1.0.3)
- secp256k1.swift (0.1.4)
- SipHash (1.2.2)
- SwiftLint (0.31.0)
- SwiftProtobuf (1.2.0)
Expand All @@ -20,7 +20,7 @@ DEPENDENCIES:
- BigInt (~> 3.1)
- CryptoSwift (~> 0.13)
- PromiseKit (~> 6.5)
- secp256k1_swift (~> 1.0.3)
- secp256k1.swift (~> 0.1.4)
- SwiftLint
- SwiftProtobuf (~> 1.2.0)

Expand All @@ -29,7 +29,7 @@ SPEC REPOS:
- BigInt
- CryptoSwift
- PromiseKit
- secp256k1_swift
- secp256k1.swift
- SipHash
- SwiftLint
- SwiftProtobuf
Expand All @@ -38,11 +38,11 @@ SPEC CHECKSUMS:
BigInt: 76b5dfdfa3e2e478d4ffdf161aeede5502e2742f
CryptoSwift: 16e78bebf567bad1c87b2d58f6547f25b74c31aa
PromiseKit: 27c1601bfb73405871b805bcb8cf7e55c4dad3db
secp256k1_swift: 4fc5c4b2d2c6d21ee8ccb868cdc92da12f38bed9
secp256k1.swift: a7e7a214f6db6ce5db32cc6b2b45e5c4dd633634
SipHash: fad90a4683e420c52ef28063063dbbce248ea6d4
SwiftLint: 7a0227733d786395817373b2d0ca799fd0093ff3
SwiftProtobuf: 91a9856079044ef4ec762b2344c763cd9e5a73c1

PODFILE CHECKSUM: cf438304f8b025b5d1c4d4dadd53cdaa4a9ca640
PODFILE CHECKSUM: 6c0144b0b3972b2e1abcf8da5af7ed150c7e9104

COCOAPODS: 1.6.1
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Refer to [docs.nervos.org/cita](https://docs.nervos.org/cita/#/rpc_guide/rpc) fo

To build CITA SDK, you'll need:

* Swift 4.2 and later
* Xcode 10 and later
* Swift 5 and later
* Xcode 10.2 and later
* [CocoaPods](https://cocoapods.org)

### Installation
Expand Down
4 changes: 2 additions & 2 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ cita-sdk-swift 是用于集成 [CITA](https://www.citahub.com/) 的原生 Swift

### 系统要求
如果你想构建 CITA SDK,你需要:
* Swift 4.2 及以后。
* Xcode 10 及以后
* Swift 5.0 及以后。
* Xcode 10.2 及以后
* [CocoaPods](https://cocoapods.org)

### 安装
Expand Down
2 changes: 1 addition & 1 deletion Source/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.22.0</string>
<string>0.23.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
14 changes: 14 additions & 0 deletions Source/RPC/RPC+API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public extension RPC {
return try peerCountPromise().wait()
}

/// Obtain other node information connected to the node, including the `address` of the node and the node `ip`.
///
/// - Returns: PeerInfo
func peersInfo() throws -> PeerInfo {
return try peersInfoPromise().wait()
}

/// Get the number of most recent block.
///
/// - Returns: Current block height.
Expand All @@ -35,6 +42,13 @@ public extension RPC {
return try sendRawTransaction(signedTx: signedTx.toHexString().addHexPrefix())
}

/// Get the version number of the current CITA.
///
/// - Returns: Version
func getVersion() throws -> Version {
return try getVersionPromise().wait()
}

/// Send signed transaction to CITA.
///
/// - Parameter signedTx: Signed transaction hex string.
Expand Down
8 changes: 8 additions & 0 deletions Source/RPC/RPC+Promises.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ internal extension RPC {
return apiPromise(.peerCount, parameters: [])
}

func peersInfoPromise() -> Promise<PeerInfo> {
return apiPromise(.peersInfo, parameters: [])
}

func blockNumberPromise() -> Promise<BigUInt> {
return apiPromise(.blockNumber, parameters: [])
}
Expand All @@ -45,6 +49,10 @@ internal extension RPC {
return apiPromise(.sendRawTransaction, parameters: [signedTx])
}

func getVersionPromise() -> Promise<Version> {
return apiPromise(.getVersion, parameters: [])
}

func getBlockByHashPromise(hash: String, fullTransactions: Bool) -> Promise<Block> {
return apiPromise(.getBlockByHash, parameters: [hash, fullTransactions])
}
Expand Down
4 changes: 4 additions & 0 deletions Source/RPC/Request/Method.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import Foundation

public enum Method: String, Encodable {
case peerCount
case peersInfo
case blockNumber
case sendRawTransaction
case getVersion
case getBlockByHash
case getBlockByNumber
case getTransactionReceipt
Expand All @@ -35,8 +37,10 @@ public enum Method: String, Encodable {
var requiredNumOfParameters: Int {
let mapping: [Method: Int] = [
.peerCount: 0,
.peersInfo: 0,
.blockNumber: 0,
.sendRawTransaction: 1,
.getVersion: 0,
.getBlockByHash: 2,
.getBlockByNumber: 2,
.getTransactionReceipt: 1,
Expand Down
6 changes: 6 additions & 0 deletions Source/RPC/Request/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public struct Response: Decodable {
[String].self,
[Int].self,
[Bool].self,
PeerInfo.self,
Version.self,
EventLog.self,
TransactionDetails.self,
TransactionReceipt.self,
Expand Down Expand Up @@ -75,6 +77,10 @@ public struct Response: Decodable {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent(Bool.self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent(PeerInfo.self, forKey: .result) {
result = rawValue
} else if let rawValue = try? container.decodeIfPresent(Version.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) {
Expand Down
34 changes: 34 additions & 0 deletions Source/RPC/Structures/PeersInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// PeersInfo.swift
// CITA
//
// Created by XiaoLu on 2019/4/22.
// Copyright © 2019 Cryptape. All rights reserved.
//

import Foundation
import BigInt

public struct PeerInfo: Decodable {
public var amount: BigUInt
public var peers: [String: String]
public var errorMessage: String?

enum CodingKeys: String, CodingKey {
case amount
case peers
case errorMessage
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
guard let amount = try DecodeUtils.decodeIntToBigUInt(container, key: .amount) else { throw CITAError.dataError }
self.amount = amount

let peers = try container.decode([String: String].self, forKey: .peers)
self.peers = peers

let errorMessage = try? container.decode(String.self, forKey: .errorMessage)
self.errorMessage = errorMessage
}
}
13 changes: 13 additions & 0 deletions Source/RPC/Structures/Version.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Version.swift
// CITA
//
// Created by XiaoLu on 2019/4/22.
// Copyright © 2019 Cryptape. All rights reserved.
//

import Foundation

public struct Version: Decodable {
public var softwareVersion: String
}
2 changes: 1 addition & 1 deletion Source/Signer/MessageSigner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public struct MessageSigner {
guard let privateKeyData = Data.fromHex(privateKey) else {
throw SignError.invalidPrivateKey
}
let serializedSignature = Secp256k1.signForRecovery(hash: hash, privateKey: privateKeyData, useExtraEntropy: useExtraEntropy).serializedSignature
let serializedSignature = try? Secp256k1.signForRecovery(hash: hash, privateKey: privateKeyData, useExtraEntropy: useExtraEntropy).serializedSignature
guard let signature = serializedSignature else {
throw SignError.invalidSignature
}
Expand Down
Loading

0 comments on commit edc5950

Please sign in to comment.