Build blockchain applications in Swift on top of the Tendermint consensus. swift-abci
uses SwiftNIO as its server core.
- Swift version: 5.3.x
- SwiftNIO version: 2.0.x
- ABCI version: 0.33.8 (tendermint 0.33.8-1a8e42d)
Requires macOS or a variant of Linux with the Swift 5.3.x toolchain installed.
In your Package.swift
file, add the repository as a dependency as such:
import PackageDescription
let package = Package(
name: "swift-abci-app",
products: [
.executable(name: "swift-abci-app", targets: ["swift-abci-app"]),
],
dependencies: [
.package(url: "https://github.com/cosmosswift/swift-abci.git", .upToNextMajor(from: "1.0.0")),
],
targets: [
.target(
name: "swift-abci-app",
dependencies: [
.product(name: "ABCI", package: "ABCI"),
.product(name: "ABCINIO", package: "ABCI"),
]
),
]
)
- Import ABCI and ABCINIO
import ABCI
import ABCINIO
- Define a class complying to the
ABCIApplication
protocol:
final class Application : ABCIApplication {
func info(request: RequestInfo) -> ResponseInfo {
.init()
}
func initChain(request: RequestInitChain) -> ResponseInitChain {
.init()
}
func query(request: RequestQuery) -> ResponseQuery {
.init()
}
func beginBlock(request: RequestBeginBlock) -> ResponseBeginBlock {
.init()
}
func checkTx(request: RequestCheckTx) -> ResponseCheckTx {
.init()
}
func deliverTx(request: RequestDeliverTx) -> ResponseDeliverTx {
.init()
}
func endBlock(request: RequestEndBlock) -> ResponseEndBlock {
.init()
}
func commit() -> ResponseCommit {
.init()
}
}
- Implement the relevant Tendermint ABCI callbacks
See the example app ABCICounter
. Check the abci spec for more details.
- Inititialize
NIOABCIServer
, with the application:
let server = NIOABCIServer(application: Application())
- Start the server
try server.start()
- Compile and run
swift run swift-abci-app
- Run Tendermint
Initialise and run Tendermint (for instance in Docker):
# initialise tendermint
docker run -it --rm -v "/tmp:/tendermint" tendermint/tendermint:v0.33.8 init
# update the default config to allow tendermint to listen on 26657 from the localhost
sed 's/127.0.0.1:26657/0.0.0.0:26657/' /tmp/config/config.toml > /tmp/delme
rm /tmp/config/config.toml
mv /tmp/delme /tmp/config/config.toml
# run a single tendermint node
docker run -it --rm -v "/tmp:/tendermint" -p "26656-26657:26656-26657" tendermint/tendermint:v0.33.8 node --proxy_app="tcp://host.docker.internal:26658"
Pre requisites: protoc
with the swift generation plugin is installed on your system (https://github.com/apple/swift-protobuf
).
For protoc swift plugin information: https://github.com/apple/swift-protobuf/blob/master/Documentation/PLUGIN.md
Update the types.pb.swift
file:
-
update the proto file (and possibly its import dependencies) from
https://github.com/tendermint/tendermint/abci
and put it in./protobuf/...
-
From the protobuf directory:
protoc --swift_opt=FileNaming=PathToUnderscores --swift_out=./../Sources/ABCI/Protobuf -I=./ $(find . -iname "*.proto")
Compile:
- run
swift build
The docs for the latest tagged release are always available at the wiki.
For bugs or feature requests, file a new issue.
For all other support requests, please email opensource@katalysis.io.
SemVer changes are documented for each release on the releases page.
Check out CONTRIBUTING.md for more information on how to help with swift-abci.
Check out CONTRIBUTORS.txt to see the full list. This list is updated for each release.