Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"object": { | ||
"pins": [ | ||
{ | ||
"package": "Alamofire", | ||
"repositoryURL": "https://github.com/Alamofire/Alamofire.git", | ||
"state": { | ||
"branch": null, | ||
"revision": "d120af1e8638c7da36c8481fd61a66c0c08dc4fc", | ||
"version": "5.4.4" | ||
} | ||
}, | ||
{ | ||
"package": "AnyCodable", | ||
"repositoryURL": "https://github.com/Flight-School/AnyCodable", | ||
"state": { | ||
"branch": null, | ||
"revision": "b1a7a8a6186f2fcb28f7bda67cfc545de48b3c80", | ||
"version": "0.6.2" | ||
} | ||
} | ||
] | ||
}, | ||
"version": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// swift-tools-version:5.5 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Example", | ||
platforms: [ | ||
.iOS(.v13), | ||
.macOS(.v10_15), | ||
.tvOS(.v13), | ||
.watchOS(.v3), | ||
], | ||
dependencies: [ | ||
// Use either local package name or github-published | ||
.package(name:"BlockfrostSwiftSDK", path: "../"), | ||
|
||
// Requires .product in target.executableTarget.dependencies | ||
//.package(url: "https://github.com/blockfrost/blockfrost-swift.git", from: "0.0.1"), | ||
|
||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package. A target can define a module or a test suite. | ||
// Targets can depend on other targets in this package, and on products in packages this package depends on. | ||
.executableTarget( | ||
name: "Example", | ||
dependencies: [ | ||
// Used when BlockfrostSwiftSDK is local dep. | ||
"BlockfrostSwiftSDK", | ||
|
||
// uncomment if using github | ||
//.product(name: "BlockfrostSwiftSDK", package: "blockfrost-swift"), | ||
]), | ||
|
||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Example app for Blockfrost Swift SDK | ||
|
||
Very simple example app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import Foundation | ||
import BlockfrostSwiftSDK | ||
|
||
public final class Example { | ||
let exampleAddr = "addr1q8zu4smzyf2r2mfqjd6tc6vxf2p8rccdfk82ye3eut2udkw9etpkygj5x4kjpym5h35cvj5zw83s6nvw5fnrnck4cmvshkfm4y" | ||
private let arguments: [String] | ||
|
||
public init(arguments: [String] = CommandLine.arguments) { | ||
self.arguments = arguments | ||
} | ||
|
||
public func run() throws { | ||
let group = DispatchGroup() | ||
group.enter() | ||
|
||
// Default config, resolved to mainnet, project id from env var BF_MAINNET_PROJECT_ID | ||
// Using global response queue as main will be blocked, waiting for a result | ||
BlockfrostStaticConfig.apiResponseQueue = .global() | ||
if BlockfrostStaticConfig.projectId == nil { | ||
fatalError("Please, set project id in BF_MAINNET_PROJECT_ID env var") | ||
} | ||
|
||
print("Querying address: \(exampleAddr)") | ||
let api = CardanoAddressesAPI() | ||
_ = api.getAddressDetails(address: exampleAddr) { resp in | ||
switch (resp) { | ||
case let .failure(err): | ||
print("Error getting an address: \(self.exampleAddr): \(err)") | ||
break | ||
case let .success(r): | ||
print("Address data: \(r), \(r.address), \(r.txCount), \(r.sentSum)") | ||
print("JSON-encoded: \(String(data: (try? CodableHelper.encode(r).get()) ?? Data(), encoding: .utf8) ?? "-")") | ||
break | ||
} | ||
group.leave() | ||
} | ||
|
||
// Wait for async to complete | ||
group.wait() | ||
|
||
// Explicit configuration | ||
let config = BlockfrostConfig.mainnetDefault().clone() | ||
config.projectId = "non-existent" // your project id here | ||
config.apiResponseQueue = .global() | ||
group.enter() | ||
|
||
print("\n\nQuery 2: invalid project ID") | ||
let api2 = CardanoAddressesAPI(config: config) | ||
_ = api2.getAddressDetails(address: exampleAddr) { resp in | ||
switch (resp) { | ||
case let .failure(err): | ||
print("Error getting an address: \(err)") | ||
break | ||
case let .success(r): | ||
print("Address data: \(r)") | ||
break | ||
} | ||
group.leave() | ||
} | ||
|
||
// Wait for async to complete | ||
group.wait() | ||
print("run() finished") | ||
} | ||
} | ||
|
||
|
||
let tool = Example() | ||
do { | ||
try tool.run() | ||
} catch { | ||
print("An error occurred: \(error)") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
PDIR="/tmp/.build-blockfrost-swift" | ||
swift build --skip-update --product Example --build-path "$PDIR" | ||
exec "$PDIR/debug/Example" |