Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #238 from EOSIO/develop
Browse files Browse the repository at this point in the history
Release v0.2.0
  • Loading branch information
Brandon Fancher authored Oct 25, 2019
2 parents e573789 + 6f6474c commit 06a42e9
Show file tree
Hide file tree
Showing 260 changed files with 7,983 additions and 5,170 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ timeline.xctimeline
playground.xcworkspace

## Jazzy
docs/code/undocumented.json
docs/undocumented.json

# Swift Package Manager
#
Expand Down
8 changes: 5 additions & 3 deletions EosioSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'EosioSwift'
s.version = '0.1.3'
s.version = '0.2.0'
s.summary = 'EOSIO SDK for Swift - API for integrating with EOSIO-based blockchains.'
s.homepage = 'https://github.com/EOSIO/eosio-swift'
s.license = { :type => 'MIT', :text => <<-LICENSE
Expand All @@ -19,12 +19,14 @@ Pod::Spec.new do |s|
'Serguei Vinnitskii' => 'serguei.vinnitskii@block.one',
'Farid Rahmani' => 'farid.rahmani@block.one',
'Brandon Fancher' => 'brandon.fancher@block.one',
'Mark Johnson' => 'mark.johnson@block.one',
'Paul Kim' => 'paul.kim@block.one',
'Steve McCoole' => 'steve.mccoole@objectpartners.com',
'Ben Martell' => 'ben.martell@objectpartners.com' }

s.source = { :git => 'https://github.com/EOSIO/eosio-swift.git', :tag => "v" + s.version.to_s }

s.swift_version = '4.2'
s.swift_version = '5.0'
s.ios.deployment_target = '11.0'

s.source_files = 'EosioSwift/**/*.swift'
Expand All @@ -34,6 +36,6 @@ Pod::Spec.new do |s|
'SWIFT_COMPILATION_MODE' => 'wholemodule',
'ENABLE_BITCODE' => 'YES' }

s.ios.dependency 'BigInt', '~> 3.1'
s.ios.dependency 'BigInt', '~> 5.0'
s.ios.dependency 'PromiseKit', '~> 6.8'
end
17 changes: 12 additions & 5 deletions EosioSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
3EE762A22268C48D00D8DC33 /* EosioRpcProviderEndpointsPromises.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EE762A12268C48D00D8DC33 /* EosioRpcProviderEndpointsPromises.swift */; };
3EE762A422690E9200D8DC33 /* RpcProviderEndpointPromiseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EE762A322690E9200D8DC33 /* RpcProviderEndpointPromiseTests.swift */; };
4FD31C65A4889CF91BFCE984 /* Pods_EosioSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3E4478EE834B70DDF06A7FA /* Pods_EosioSwift.framework */; };
5D8C430D235F986700F3A146 /* DictionaryExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D8C430C235F986700F3A146 /* DictionaryExtensionTests.swift */; };
6B80D26921FA6DDF00716A7B /* EosioSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B80D25F21FA6DDF00716A7B /* EosioSwift.framework */; };
6B80D27021FA6DDF00716A7B /* EosioSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = 6B80D26221FA6DDF00716A7B /* EosioSwift.h */; settings = {ATTRIBUTES = (Public, ); }; };
8F49E8CF225E6E6A00082631 /* RpcProviderRequestModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F49E8CE225E6E6A00082631 /* RpcProviderRequestModels.swift */; };
Expand Down Expand Up @@ -99,6 +100,7 @@
3EE762A322690E9200D8DC33 /* RpcProviderEndpointPromiseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RpcProviderEndpointPromiseTests.swift; sourceTree = "<group>"; };
5835070C5F7998E17BF06017 /* Pods_EosioSwiftTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_EosioSwiftTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5ACC322368A39C81F88A1553 /* Pods-EosioSwift.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EosioSwift.debug.xcconfig"; path = "Pods/Target Support Files/Pods-EosioSwift/Pods-EosioSwift.debug.xcconfig"; sourceTree = "<group>"; };
5D8C430C235F986700F3A146 /* DictionaryExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DictionaryExtensionTests.swift; sourceTree = "<group>"; };
6B80D25F21FA6DDF00716A7B /* EosioSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = EosioSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6B80D26221FA6DDF00716A7B /* EosioSwift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EosioSwift.h; sourceTree = "<group>"; };
6B80D26321FA6DDF00716A7B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -258,6 +260,7 @@
isa = PBXGroup;
children = (
8F6B04CA22287B1D00215CD0 /* DataExtensionsTests.swift */,
5D8C430C235F986700F3A146 /* DictionaryExtensionTests.swift */,
8F6B04C722287B1D00215CD0 /* EncodableExtensionTests.swift */,
8F6B04CB22287B1D00215CD0 /* EosioNameTests.swift */,
8F6B04C922287B1D00215CD0 /* StringExtensionsTests.swift */,
Expand Down Expand Up @@ -440,10 +443,11 @@
TargetAttributes = {
6B80D25E21FA6DDF00716A7B = {
CreatedOnToolsVersion = 10.1;
LastSwiftMigration = 1010;
LastSwiftMigration = 1110;
};
6B80D26721FA6DDF00716A7B = {
CreatedOnToolsVersion = 10.1;
LastSwiftMigration = 1110;
};
};
};
Expand Down Expand Up @@ -616,6 +620,7 @@
8F6B04CE22287B1D00215CD0 /* StringExtensionsTests.swift in Sources */,
BBAC7BCE225266A40035CDBC /* DateExtensionTests.swift in Sources */,
8F77127D2232FD6D004256D3 /* EosioTransactionTests.swift in Sources */,
5D8C430D235F986700F3A146 /* DictionaryExtensionTests.swift in Sources */,
1F9DCB7A22569A2600853105 /* EosioRpcProviderTests.swift in Sources */,
B4E8F6C222320EB700FA7E63 /* RIPEMD160Tests.swift in Sources */,
8F6B04CF22287B1D00215CD0 /* DataExtensionsTests.swift in Sources */,
Expand Down Expand Up @@ -785,11 +790,12 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.2.0;
PRODUCT_BUNDLE_IDENTIFIER = one.block.EosioSwift;
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 @@ -814,10 +820,11 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 0.2.0;
PRODUCT_BUNDLE_IDENTIFIER = one.block.EosioSwift;
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 @@ -838,7 +845,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = one.block.EosioSwiftTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -859,7 +866,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = one.block.EosioSwiftTests;
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 EosioSwift/Crypto/Base58String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public extension Data {
let byteString = [UInt8](string.utf8)

for ch in byteString.reversed() {
if let index = alphabet.index(of: ch) {
if let index = alphabet.firstIndex(of: ch) {
answer = answer + (j * BigUInt(index))
j *= radix
} else {
Expand Down
35 changes: 22 additions & 13 deletions EosioSwift/Crypto/RIPEMD160.swift
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,20 @@ public struct RIPEMD160 {
}

public mutating func update(data: Data) {
data.withUnsafeBytes { (ptr: UnsafePointer<UInt8>) in
var ptr = ptr
data.withUnsafeBytes { ptr in
let typedPtr = ptr.bindMemory(to: UInt8.self)
guard var ptr = typedPtr.baseAddress else { return }
var length = data.count
var X = [UInt32](repeating: 0, count: 16)

// Process remaining bytes from last call:
if buffer.count > 0 && buffer.count + length >= 64 {
let amount = 64 - buffer.count
buffer.append(ptr, count: amount)
buffer.withUnsafeBytes { _ = memcpy(&X, $0, 64) }
buffer.withUnsafeBytes { ptr in
guard let baseAddress = ptr.baseAddress else { return }
_ = memcpy(&X, baseAddress, 64)
}
compress(X)
ptr += amount
length -= amount
Expand All @@ -329,15 +333,18 @@ public struct RIPEMD160 {
}
// Save remaining unprocessed bytes:
buffer = Data(bytes: ptr, count: length)
count += Int64(data.count)
}
count += Int64(data.count)
}

public mutating func finalize() -> Data {
var X = [UInt32](repeating: 0, count: 16)
/* append the bit m_n == 1 */
buffer.append(0x80)
buffer.withUnsafeBytes { _ = memcpy(&X, $0, buffer.count) }
buffer.withUnsafeBytes { ptr in
guard let baseAddress = ptr.baseAddress else { return }
_ = memcpy(&X, baseAddress, buffer.count)
}

if (count & 63) > 55 {
/* length goes to next block */
Expand All @@ -353,12 +360,14 @@ public struct RIPEMD160 {
compress(X)

var data = Data(count: 20)
data.withUnsafeMutableBytes { (ptr: UnsafeMutablePointer<UInt32>) in
ptr[0] = MDbuf.0
ptr[1] = MDbuf.1
ptr[2] = MDbuf.2
ptr[3] = MDbuf.3
ptr[4] = MDbuf.4
data.withUnsafeMutableBytes { ptr in
let typedPtr = ptr.bindMemory(to: UInt32.self)
guard let baseAddress = typedPtr.baseAddress else { return }
baseAddress[0] = MDbuf.0
baseAddress[1] = MDbuf.1
baseAddress[2] = MDbuf.2
baseAddress[3] = MDbuf.3
baseAddress[4] = MDbuf.4
}

buffer = Data()
Expand Down Expand Up @@ -386,8 +395,8 @@ public extension RIPEMD160 {
var key = key
key.count = 64 // Truncate to 64 bytes or fill-up with zeros.

let outerKeyPad = Data(bytes: key.map { $0 ^ 0x5c })
let innerKeyPad = Data(bytes: key.map { $0 ^ 0x36 })
let outerKeyPad = Data(key.map { $0 ^ 0x5c })
let innerKeyPad = Data(key.map { $0 ^ 0x36 })

var innerMd = RIPEMD160()
innerMd.update(data: innerKeyPad)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,15 @@ extension EosioRpcProvider {
completion(EosioResult(success: result, failure: error)!)
}
}

/// Call `chain/send_transaction`. Send a transaction to the blockchain!
///
/// - Parameters:
/// - requestParameters: An `EosioRpcSendTransactionRequest`.
/// - completion: Called with the response, as an `EosioResult` consisting of an `EosioRpcTransactionResponse` and an optional `EosioError`.
public func sendTransaction(requestParameters: EosioRpcSendTransactionRequest, completion: @escaping (EosioResult<EosioRpcTransactionResponse, EosioError>) -> Void) {
getResource(rpc: "chain/send_transaction", requestParameters: requestParameters) {(result: EosioRpcTransactionResponse?, error: EosioError?) in
completion(EosioResult(success: result, failure: error)!)
}
}
}
20 changes: 20 additions & 0 deletions EosioSwift/EosioRpcProvider/Models/RpcProviderRequestModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,23 @@ public struct EosioRpcHistoryControlledAccountsRequest: Codable {
self.controllingAccount = controllingAccount
}
}

/// The request struct for `send_transaction` RPC requests.
public struct EosioRpcSendTransactionRequest: Codable {
/// Array of signatures as Strings.
public var signatures = [String]()
/// Compression
public var compression = 0
/// Context free data, packed.
public var packedContextFreeData = ""
/// The serialized transaction as a hex String.
public var packedTrx = ""

/// Initialize an `EosioRpcSendTransactionRequest`.
public init(signatures: [String] = [], compression: Int = 0, packedContextFreeData: String = "", packedTrx: String = "") {
self.signatures = signatures
self.compression = compression
self.packedContextFreeData = packedContextFreeData
self.packedTrx = packedTrx
}
}
17 changes: 7 additions & 10 deletions EosioSwift/EosioRpcProvider/Models/RpcProviderResponseModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -778,17 +778,17 @@ public struct EosioRpcActionsResponseAction: Decodable, EosioRpcResponseProtocol
case accountActionSequence = "account_action_seq"
case blockNumber = "block_num"
case blockTime = "block_time"
case actionTrance = "action_trace"
case actionTrace = "action_trace"
}

public init(from decoder: Decoder) throws {
let contanter = try decoder.container(keyedBy: CustomCodingKeys.self)
let container = try decoder.container(keyedBy: CustomCodingKeys.self)

globalActionSequence = try contanter.decode(EosioUInt64.self, forKey: .globalActionSequence)
accountActionSequence = try contanter.decode(Int32.self, forKey: .accountActionSequence)
blockNumber = try contanter.decode(UInt32.self, forKey: .blockNumber)
blockTime = try contanter.decode(String.self, forKey: .blockTime)
actionTrace = try contanter.decode(EosioRpcActionsResponseActionTrace.self, forKey: .actionTrance)
globalActionSequence = try container.decode(EosioUInt64.self, forKey: .globalActionSequence)
accountActionSequence = try container.decode(Int32.self, forKey: .accountActionSequence)
blockNumber = try container.decode(UInt32.self, forKey: .blockNumber)
blockTime = try container.decode(String.self, forKey: .blockTime)
actionTrace = try container.decode(EosioRpcActionsResponseActionTrace.self, forKey: .actionTrace)
}
}

Expand All @@ -806,7 +806,6 @@ public struct EosioRpcActionsResponseActionTrace: Decodable, EosioRpcResponsePro
public var producerBlockId: String?
public var accountRamDeltas: [EosioRpcActionsResponseActionTrActDeltas]
public var exception: [String: Any]?
public var inlineTrances: [EosioRpcActionsResponseActionTrace]

enum CustomCodingKeys: String, CodingKey {
case receipt
Expand All @@ -820,7 +819,6 @@ public struct EosioRpcActionsResponseActionTrace: Decodable, EosioRpcResponsePro
case producerBlockId = "producer_block_id"
case accountRamDeltas = "account_ram_deltas"
case exception = "except"
case inlineTrances = "inline_traces"
}

public init(from decoder: Decoder) throws {
Expand All @@ -839,7 +837,6 @@ public struct EosioRpcActionsResponseActionTrace: Decodable, EosioRpcResponsePro

let exceptionContainer = try? container.nestedContainer(keyedBy: DynamicKey.self, forKey: .exception)
exception = exceptionContainer?.decodeDynamicKeyValues() ?? [String: Any]()
inlineTrances = try container.decode([EosioRpcActionsResponseActionTrace].self, forKey: .inlineTrances)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,28 @@ public struct EosioRpcPushTransactionRequest: Codable {
/// Request struct for requests to `v1/chain/get_block`.
/// To be compatible with EOSIO SDK for Swift, RPC endpoints must, at a minimum, accept these parameters.
public struct EosioRpcBlockRequest: Codable {
enum CodingKeys: String, CodingKey {
case blockNumberOrId = "block_num_or_id"
}
/// The number or ID of the block you are fetching.
public var blockNumOrId: UInt64

/// Initialize an `EosioRpcBlockRequest`.
@available(*, deprecated, message: "Please use blockNumberOrId instead.")
public var blockNumOrId: UInt64 {
get {
return UInt64(blockNumberOrId) ?? 0
}
set {
blockNumberOrId = String(newValue)
}
}
/// The number or ID of the block you are fetching.
public var blockNumberOrId: String
/// Initialize an `EosioRpcBlockRequest` with a block number.
public init(blockNumOrId: UInt64 = 1) {
self.blockNumOrId = blockNumOrId
self.blockNumberOrId = String(blockNumOrId)
}
/// Initialize an `EosioRpcBlockRequest` with a block number or id.
public init(blockNumOrId: String) {
self.blockNumberOrId = blockNumOrId
}
}

Expand Down
Loading

0 comments on commit 06a42e9

Please sign in to comment.