Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example tool #8

Merged
merged 4 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: fmt
fmt:
swift package plugin --allow-writing-to-package-directory swiftformat
swift package plugin --allow-writing-to-package-directory swiftformat ./examples

.PHONY: generate-grpc
generate-grpc:
Expand Down
149 changes: 149 additions & 0 deletions examples/get-cryptographic-parameters/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"pins" : [
{
"identity" : "base58",
"kind" : "remoteSourceControl",
"location" : "https://github.com/anquii/Base58.git",
"state" : {
"revision" : "7e4a1e4e6813c750ed2f9e80a0494c608eebb2ca",
"version" : "1.0.1"
}
},
{
"identity" : "base58check",
"kind" : "remoteSourceControl",
"location" : "https://github.com/anquii/Base58Check.git",
"state" : {
"revision" : "f35a770ff7f3fd553cc44057f492c0107cc7b481",
"version" : "1.0.1"
}
},
{
"identity" : "bigint",
"kind" : "remoteSourceControl",
"location" : "https://github.com/attaswift/BigInt.git",
"state" : {
"revision" : "0ed110f7555c34ff468e72e1686e59721f2b0da6",
"version" : "5.3.0"
}
},
{
"identity" : "concordium-swift-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Concordium/concordium-swift-sdk.git",
"state" : {
"branch" : "main",
"revision" : "89c89678e905fa5bca721a83213201d5b04b3b92"
}
},
{
"identity" : "grpc-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/grpc/grpc-swift.git",
"state" : {
"revision" : "6ade19f0b57f5fc436dfecfced83f3c84d1095b9",
"version" : "1.21.0"
}
},
{
"identity" : "swift-atomics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-atomics.git",
"state" : {
"revision" : "cd142fd2f64be2100422d658e7411e39489da985",
"version" : "1.2.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "d029d9d39c87bed85b1c50adee7c41795261a192",
"version" : "1.0.6"
}
},
{
"identity" : "swift-http-types",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-http-types",
"state" : {
"revision" : "1827dc94bdab2eb5f2fc804e9b0cb43574282566",
"version" : "1.0.2"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed",
"version" : "1.5.3"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "702cd7c56d5d44eeba73fdf83918339b26dc855c",
"version" : "2.62.0"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "798c962495593a23fdea0c0c63fd55571d8dff51",
"version" : "1.20.0"
}
},
{
"identity" : "swift-nio-http2",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "3bd9004b9d685ed6b629760fc84903e48efec806",
"version" : "1.29.0"
}
},
{
"identity" : "swift-nio-ssl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "320bd978cceb8e88c125dcbb774943a92f6286e9",
"version" : "2.25.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "ebf8b9c365a6ce043bf6e6326a04b15589bd285e",
"version" : "1.20.0"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "65e8f29b2d63c4e38e736b25c27b83e012159be8",
"version" : "1.25.2"
}
},
{
"identity" : "swiftformat",
"kind" : "remoteSourceControl",
"location" : "https://github.com/nicklockwood/SwiftFormat.git",
"state" : {
"revision" : "fef156a6135e584985ed26713dd2e9ee41f952cb",
"version" : "0.53.0"
}
}
],
"version" : 2
}
21 changes: 21 additions & 0 deletions examples/get-cryptographic-parameters/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// swift-tools-version: 5.9

import PackageDescription

let package = Package(
name: "concordium-swift-sdk-cli",
platforms: [
.macOS(.v10_15),
],
dependencies: [
.package(url: "https://github.com/Concordium/concordium-swift-sdk.git", branch: "main"),
],
targets: [
.executableTarget(
name: "concordium-swift-sdk-cli",
dependencies: [
.product(name: "ConcordiumSwiftSDK", package: "concordium-swift-sdk"),
]
),
]
)
25 changes: 25 additions & 0 deletions examples/get-cryptographic-parameters/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Example: getCryptographicParameters

Small example program for illustrating how to use the SDK from a consuming application.
The SDK is added with the version defined as the `main` branch.
Note that this is not a fixed reference and the cache may retain old revisions of that branch.
Real applications should always use a specific version.

The program just creates a `Client` and calls the method `getCryptographicParameters` on it (of last finalized block).
No command line arguments are accepted.
The program assumes to find a running node on localhost port 20000.
The tool `socat` may be used to redirect the requests to a node running on IP `<ip>`, port `<port>`:

```shell
socat TCP-LISTEN:20000,fork TCP:<ip>:<port>
```

The result is printed as a simple struct dump.

## Usage

Build and run the program:

```shell
swift run
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ConcordiumSwiftSDK
import GRPC
import NIOPosix
import XCTest

// Run the following command in a terminal to redirect to a node running on a different host/port:
// socat TCP-LISTEN:20000,fork TCP:<ip>:<port>
let channelTarget = ConnectionTarget.host("localhost", port: 20000)

let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
defer {
try! group.syncShutdownGracefully()
}

let channel = try GRPCChannelPool.with(
target: channelTarget,
transportSecurity: .plaintext,
eventLoopGroup: group
)
defer {
try! channel.close().wait()
}

let client = Client(channel: channel)
let res = try await client.getCryptographicParameters(at: .lastFinal)
print(res)