Skip to content

Commit

Permalink
Merge pull request #2 from XYOracleNetwork/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
carterharrison committed Feb 13, 2019
2 parents d87e331 + 3604275 commit c307a4a
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ target 'sdk-core-swift' do
# Pods for sdk-core-swift

pod 'PromisesSwift', '~> 1.2.3'
pod 'sdk-objectmodel-swift', '~> 0.1.1-beta.0'
pod 'sdk-objectmodel-swift', '~> 0.1.2-beta.0'

target 'sdk-core-swiftTests' do
inherit! :search_paths
Expand Down
10 changes: 5 additions & 5 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ PODS:
- PromisesObjC (1.2.5)
- PromisesSwift (1.2.5):
- PromisesObjC (= 1.2.5)
- sdk-objectmodel-swift (0.1.1-beta.0)
- sdk-objectmodel-swift (0.1.2-beta.0)

DEPENDENCIES:
- PromisesSwift (~> 1.2.3)
- sdk-objectmodel-swift (~> 0.1.1-beta.0)
- sdk-objectmodel-swift (~> 0.1.2-beta.0)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
Expand All @@ -17,8 +17,8 @@ SPEC REPOS:
SPEC CHECKSUMS:
PromisesObjC: 2b402ef5333bb9b436c74ee1bd7dcb2511b68caf
PromisesSwift: 63d93b8cc31b4245ca1014ff5cc24d6ae952a274
sdk-objectmodel-swift: 7356581ad62bf22700a195ecc266ef0a537ec31e
sdk-objectmodel-swift: c0ae76ff76772989d60a9ee9e53cd2ef24d8fb22

PODFILE CHECKSUM: 563cc283d09f32c96e9a624ae17efce027639b83
PODFILE CHECKSUM: 6073acd8291963907908efa4a70a821a541b7d54

COCOAPODS: 1.5.3
COCOAPODS: 1.6.0
2 changes: 1 addition & 1 deletion sdk-core-swift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'sdk-core-swift'
s.version = '0.1.2-beta.0'
s.version = '0.1.2-beta.2'
s.summary = 'Core Library for XYO Network in Swift.'

# This description is used to generate tags and improve search results.
Expand Down
31 changes: 4 additions & 27 deletions sdk-core-swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
3F217B3DD64FF1E6A136C46B /* Pods_sdk_core_swiftTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B18D506875636A5D6A1F6E96 /* Pods_sdk_core_swiftTests.framework */; };
8C361F3A2213C7710049B9EF /* XyoTcpPeer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C361F392213C7710049B9EF /* XyoTcpPeer.swift */; };
8C42B7C021F7C5CC006F6F86 /* sdk_core_swift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8C42B7B621F7C5CC006F6F86 /* sdk_core_swift.framework */; };
8C42B7C721F7C5CC006F6F86 /* sdk_core_swift.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C42B7B921F7C5CC006F6F86 /* sdk_core_swift.h */; settings = {ATTRIBUTES = (Public, ); }; };
8C54005021FF721B008A3CE3 /* XyoOriginChainCreator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8C54004F21FF721B008A3CE3 /* XyoOriginChainCreator.swift */; };
Expand Down Expand Up @@ -76,6 +77,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
8C361F392213C7710049B9EF /* XyoTcpPeer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XyoTcpPeer.swift; sourceTree = "<group>"; };
8C42B7B621F7C5CC006F6F86 /* sdk_core_swift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = sdk_core_swift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8C42B7B921F7C5CC006F6F86 /* sdk_core_swift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = sdk_core_swift.h; sourceTree = "<group>"; };
8C42B7BA21F7C5CC006F6F86 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -431,6 +433,7 @@
children = (
8CF3AE352200C83C00D6EED9 /* XyoTcpSocket.swift */,
8CF3AE392200FB9900D6EED9 /* XyoTcpSocketPipe.swift */,
8C361F392213C7710049B9EF /* XyoTcpPeer.swift */,
);
path = tcp;
sourceTree = "<group>";
Expand Down Expand Up @@ -487,7 +490,6 @@
8C42B7BB21F7C5CC006F6F86 /* Sources */,
8C42B7BC21F7C5CC006F6F86 /* Frameworks */,
8C42B7BD21F7C5CC006F6F86 /* Resources */,
EBE827EF746A572F50E39265 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
Expand Down Expand Up @@ -576,32 +578,6 @@
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
EBE827EF746A572F50E39265 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-sdk-core-swiftTests/Pods-sdk-core-swiftTests-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework",
"${BUILT_PRODUCTS_DIR}/PromisesSwift/Promises.framework",
"${BUILT_PRODUCTS_DIR}/sdk-objectmodel-swift/sdk_objectmodel_swift.framework",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
);
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBLPromises.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Promises.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/sdk_objectmodel_swift.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-sdk-core-swiftTests/Pods-sdk-core-swiftTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
F83AFD414FF04C8CAD185E95 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -657,6 +633,7 @@
8CF3AE3121FFE30D00D6EED9 /* XyoFlagProcedureCatalogue.swift in Sources */,
8C6542B321F7E8A100124CB0 /* XyoHasher.swift in Sources */,
8C6542B521F7E97F00124CB0 /* XyoSha256.swift in Sources */,
8C361F3A2213C7710049B9EF /* XyoTcpPeer.swift in Sources */,
8C6542D521F91A0E00124CB0 /* XyoBoundWitnessUtil.swift in Sources */,
8C6542E521FAA7A500124CB0 /* XyoZigZagBoundWitnessSession.swift in Sources */,
8C54005D21FF9797008A3CE3 /* XyoBridgeQueue.swift in Sources */,
Expand Down
6 changes: 3 additions & 3 deletions sdk-core-swift/boundWitness/XyoBoundWitness.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ open class XyoBoundWitness : XyoIterableStructure {
static func createMasterArrayWithSubArray (masterSchema : XyoObjectSchema,
subSchema : XyoObjectSchema,
masterItems: [XyoObjectStructure],
subItems: [XyoObjectStructure]) throws -> XyoObjectStructure {
let sub = try XyoIterableStructure.createUntypedIterableObject(schema: subSchema, values: subItems)
subItems: [XyoObjectStructure]) -> XyoObjectStructure {
let sub = XyoIterableStructure.createUntypedIterableObject(schema: subSchema, values: subItems)
var itemsInMaster : [XyoObjectStructure] = [sub]
itemsInMaster.append(contentsOf: masterItems)
return try XyoIterableStructure.createUntypedIterableObject(schema: masterSchema, values: itemsInMaster)
return XyoIterableStructure.createUntypedIterableObject(schema: masterSchema, values: itemsInMaster)
}
}
4 changes: 2 additions & 2 deletions sdk-core-swift/boundWitness/XyoBoundWitnessUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public struct XyoBoundWitnessUtil {
newBoundWitnessLedger.append(try removeTypeFromWitness(witness: witness, id: id))
}

let createBoundWitness = try XyoIterableStructure.createUntypedIterableObject(schema: XyoSchemas.BW, values: newBoundWitnessLedger).getBuffer()
let createBoundWitness = XyoIterableStructure.createUntypedIterableObject(schema: XyoSchemas.BW, values: newBoundWitnessLedger).getBuffer()
return XyoBoundWitness(value: createBoundWitness)
}

Expand All @@ -44,7 +44,7 @@ public struct XyoBoundWitnessUtil {
}
}

return try XyoIterableStructure.createUntypedIterableObject(schema: XyoSchemas.WITNESS, values: newWitnessContents)
return XyoIterableStructure.createUntypedIterableObject(schema: XyoSchemas.WITNESS, values: newWitnessContents)
}

public static func getPartyNumberFromPublicKey (publickey : XyoObjectStructure, boundWitness : XyoBoundWitness) throws -> Int? {
Expand Down
6 changes: 3 additions & 3 deletions sdk-core-swift/boundWitness/XyoZigZagBoundWitness.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class XyoZigZagBoundWitness : XyoBoundWitness {
self.signedPayload = signedPayload
self.unsignedPayload = unsignedPayload

super.init(value: try XyoIterableStructure.encodeUntypedIterableObject(schema: XyoSchemas.BW, values: []))
super.init(value: XyoIterableStructure.encodeUntypedIterableObject(schema: XyoSchemas.BW, values: []))
}

public func incomingData (transfer : XyoIterableStructure?, endpoint: Bool) throws -> XyoIterableStructure {
Expand Down Expand Up @@ -108,7 +108,7 @@ class XyoZigZagBoundWitness : XyoBoundWitness {
return try XyoIterableStructure.createTypedIterableObject(schema: XyoSchemas.FETTER_SET, values: fetters)
}

return try XyoIterableStructure.createUntypedIterableObject(schema: XyoSchemas.BW_FRAGMENT, values: items)
return XyoIterableStructure.createUntypedIterableObject(schema: XyoSchemas.BW_FRAGMENT, values: items)
}

private func getNumberOfWitnessesFromTransfer (transfer: XyoIterableStructure?) throws -> Int {
Expand Down Expand Up @@ -143,7 +143,7 @@ class XyoZigZagBoundWitness : XyoBoundWitness {
signatures.append(try signCurrent(signer: signer))
}

let witness = try XyoBoundWitness.createMasterArrayWithSubArray(masterSchema: XyoSchemas.WITNESS,
let witness = XyoBoundWitness.createMasterArrayWithSubArray(masterSchema: XyoSchemas.WITNESS,
subSchema: XyoSchemas.SIGNATURE_SET,
masterItems: unsignedPayload,
subItems: signatures)
Expand Down
2 changes: 0 additions & 2 deletions sdk-core-swift/network/tcp/XyoTcpPeer.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

//
// XyoTcpPeer.swift
// mod-ble-swift
//
// Created by Carter Harrison on 2/12/19.
//

import Foundation

public struct XyoTcpPeer {
Expand Down
2 changes: 1 addition & 1 deletion sdk-core-swift/node/XyoBridgingOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class XyoBridgingOption: XyoBoundWitnessOption {

if (blockHashes.count > 0) {
let hashSet = try XyoIterableStructure.createTypedIterableObject(schema: XyoSchemas.BRIDGE_HASH_SET, values: blockHashes)
let blockSet = try XyoIterableStructure.createUntypedIterableObject(schema: XyoSchemas.BRIDGE_BLOCK_SET, values: blocks)
let blockSet = XyoIterableStructure.createUntypedIterableObject(schema: XyoSchemas.BRIDGE_BLOCK_SET, values: blocks)

return XyoBoundWitnessHueresticPair(signedPayload: [hashSet], unsignedPayload: [blockSet])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import Foundation
import sdk_objectmodel_swift

public class XyoStrageProviderOriginBlockRepository: XyoOriginBlockRepository {
private static let BLOCK_INDEX_KEY : [UInt8] = [0x00, 0x00]
private let storageProvider : XyoStorageProvider
private let hasher : XyoHasher

public init(storageProvider : XyoStorageProvider, hasher : XyoHasher) throws {
public init(storageProvider : XyoStorageProvider, hasher : XyoHasher) {
self.storageProvider = storageProvider
self.hasher = hasher
}

public func removeOriginBlock (originBlockHash : [UInt8]) throws {
try storageProvider.delete(key: originBlockHash)
try updateBlockIndex(hashToRemove: originBlockHash)
}

public func getOriginBlock (originBlockHash : [UInt8]) throws -> XyoBoundWitness? {
Expand All @@ -35,9 +37,50 @@ public class XyoStrageProviderOriginBlockRepository: XyoOriginBlockRepository {
}

public func addOriginBlock (originBlock : XyoBoundWitness) throws {
let key = try originBlock.getHash(hasher: hasher).getBuffer().toByteArray()
let hash = try originBlock.getHash(hasher: hasher)
let key = hash.getBuffer().toByteArray()
let value = originBlock.getBuffer().toByteArray()

try storageProvider.write(key: key, value: value)
try updateBlockIndex(hashToAdd: hash)
}

private func getBlockIndex () throws -> XyoIterableStructure {
guard let value = try storageProvider.read(key: XyoStrageProviderOriginBlockRepository.BLOCK_INDEX_KEY) else {
return XyoIterableStructure.createUntypedIterableObject(schema: XyoSchemas.ARRAY_UNTYPED, values: [])
}

return XyoIterableStructure(value: XyoBuffer(data: value))
}

private func updateBlockIndex (hashToAdd : XyoObjectStructure) throws {
let currentIndex = try getBlockIndex()
try currentIndex.addElement(element: hashToAdd)
try storageProvider.write(key: XyoStrageProviderOriginBlockRepository.BLOCK_INDEX_KEY, value: currentIndex.getBuffer().toByteArray())
}

private func updateBlockIndex (hashToRemove : [UInt8]) throws {
var newHashes = [XyoObjectStructure]()
let currentIndex = try getBlockIndex().getNewIterator()

while try currentIndex.hasNext() {
let hashInList = try currentIndex.next()

if (hashInList.getBuffer().toByteArray() != hashToRemove) {
newHashes.append(hashInList)
}
}

let newIndex = XyoIterableStructure.createUntypedIterableObject(schema: XyoSchemas.ARRAY_UNTYPED, values: newHashes)
try storageProvider.write(key: XyoStrageProviderOriginBlockRepository.BLOCK_INDEX_KEY, value: newIndex.getBuffer().toByteArray())
}

public func getAllOriginBlockHashes () -> XyoIterableStructure {
do {
return try getBlockIndex()
} catch {
return XyoIterableStructure.createUntypedIterableObject(schema: XyoSchemas.ARRAY_UNTYPED, values: [])
}
}
}

0 comments on commit c307a4a

Please sign in to comment.