From 8d3532cc22706ab24de7027cae3840d50f1b1cfe Mon Sep 17 00:00:00 2001 From: Michael Bisgaard Olesen Date: Wed, 17 Jan 2024 13:12:24 +0100 Subject: [PATCH 1/4] Add example tool --- .../Package.resolved | 148 ++++++++++++++++++ .../Package.swift | 21 +++ .../get-cryptographic-parameters/README.md | 20 +++ .../concordium-swift-sdk-cli/main.swift | 26 +++ 4 files changed, 215 insertions(+) create mode 100644 examples/get-cryptographic-parameters/Package.resolved create mode 100644 examples/get-cryptographic-parameters/Package.swift create mode 100644 examples/get-cryptographic-parameters/README.md create mode 100644 examples/get-cryptographic-parameters/Sources/concordium-swift-sdk-cli/main.swift diff --git a/examples/get-cryptographic-parameters/Package.resolved b/examples/get-cryptographic-parameters/Package.resolved new file mode 100644 index 0000000..925990f --- /dev/null +++ b/examples/get-cryptographic-parameters/Package.resolved @@ -0,0 +1,148 @@ +{ + "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" : { + "revision" : "8700cc6316d24057e9e30445b31ef07c28ec992f" + } + }, + { + "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 +} diff --git a/examples/get-cryptographic-parameters/Package.swift b/examples/get-cryptographic-parameters/Package.swift new file mode 100644 index 0000000..1dd8d1d --- /dev/null +++ b/examples/get-cryptographic-parameters/Package.swift @@ -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", revision: "8700cc6316d24057e9e30445b31ef07c28ec992f"), + ], + targets: [ + .executableTarget( + name: "concordium-swift-sdk-cli", + dependencies: [ + .product(name: "ConcordiumSwiftSDK", package: "concordium-swift-sdk"), + ] + ), + ] +) diff --git a/examples/get-cryptographic-parameters/README.md b/examples/get-cryptographic-parameters/README.md new file mode 100644 index 0000000..e3d5199 --- /dev/null +++ b/examples/get-cryptographic-parameters/README.md @@ -0,0 +1,20 @@ +# Example: getCryptographicParameters + +Small example program for illustrating how to use the SDK from a consuming application. + +The program just creates a `Client` and calls the method `getCryptographicParameters` on it. +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 ``, port ``: + +```shell +socat TCP-LISTEN:20000,fork TCP:: +``` + +## Usage + +Build and run the program: + +```shell +swift run +``` diff --git a/examples/get-cryptographic-parameters/Sources/concordium-swift-sdk-cli/main.swift b/examples/get-cryptographic-parameters/Sources/concordium-swift-sdk-cli/main.swift new file mode 100644 index 0000000..332a63e --- /dev/null +++ b/examples/get-cryptographic-parameters/Sources/concordium-swift-sdk-cli/main.swift @@ -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:: +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) From e88a1b29085ea93b2e8d418601427bbea356bade Mon Sep 17 00:00:00 2001 From: Michael Bisgaard Olesen Date: Wed, 17 Jan 2024 13:49:38 +0100 Subject: [PATCH 2/4] Update --- examples/get-cryptographic-parameters/Package.resolved | 3 ++- examples/get-cryptographic-parameters/Package.swift | 2 +- examples/get-cryptographic-parameters/README.md | 7 ++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/get-cryptographic-parameters/Package.resolved b/examples/get-cryptographic-parameters/Package.resolved index 925990f..3c7f888 100644 --- a/examples/get-cryptographic-parameters/Package.resolved +++ b/examples/get-cryptographic-parameters/Package.resolved @@ -32,7 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Concordium/concordium-swift-sdk.git", "state" : { - "revision" : "8700cc6316d24057e9e30445b31ef07c28ec992f" + "branch" : "main", + "revision" : "89c89678e905fa5bca721a83213201d5b04b3b92" } }, { diff --git a/examples/get-cryptographic-parameters/Package.swift b/examples/get-cryptographic-parameters/Package.swift index 1dd8d1d..301a575 100644 --- a/examples/get-cryptographic-parameters/Package.swift +++ b/examples/get-cryptographic-parameters/Package.swift @@ -8,7 +8,7 @@ let package = Package( .macOS(.v10_15), ], dependencies: [ - .package(url: "https://github.com/Concordium/concordium-swift-sdk.git", revision: "8700cc6316d24057e9e30445b31ef07c28ec992f"), + .package(url: "https://github.com/Concordium/concordium-swift-sdk.git", branch: "main"), ], targets: [ .executableTarget( diff --git a/examples/get-cryptographic-parameters/README.md b/examples/get-cryptographic-parameters/README.md index e3d5199..d1a23d6 100644 --- a/examples/get-cryptographic-parameters/README.md +++ b/examples/get-cryptographic-parameters/README.md @@ -1,8 +1,11 @@ # Example: getCryptographicParameters Small example program for illustrating how to use the SDK from a consuming application. +The library is included with the version defined as the `main` branch. +Note that this is not a fixed reference and the cache may contain an old revision of that branch. +Real applications should always use a specific version. -The program just creates a `Client` and calls the method `getCryptographicParameters` on it. +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 ``, port ``: @@ -11,6 +14,8 @@ The tool `socat` may be used to redirect the requests to a node running on IP `< socat TCP-LISTEN:20000,fork TCP:: ``` +The result is printed as a simple struct dump. + ## Usage Build and run the program: From 474d30c0fd883c983ae23e2e7acc514640194f06 Mon Sep 17 00:00:00 2001 From: Michael Bisgaard Olesen Date: Wed, 17 Jan 2024 14:12:05 +0100 Subject: [PATCH 3/4] Update makefile fmt command --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 10b1a21..f6a3e12 100644 --- a/Makefile +++ b/Makefile @@ -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: From 07e780547e5ac1de0151fb99fe7c7e26795bbcea Mon Sep 17 00:00:00 2001 From: Michael Bisgaard Olesen Date: Wed, 17 Jan 2024 14:23:05 +0100 Subject: [PATCH 4/4] Wording --- examples/get-cryptographic-parameters/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/get-cryptographic-parameters/README.md b/examples/get-cryptographic-parameters/README.md index d1a23d6..fd932f5 100644 --- a/examples/get-cryptographic-parameters/README.md +++ b/examples/get-cryptographic-parameters/README.md @@ -1,8 +1,8 @@ # Example: getCryptographicParameters Small example program for illustrating how to use the SDK from a consuming application. -The library is included with the version defined as the `main` branch. -Note that this is not a fixed reference and the cache may contain an old revision of that branch. +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).