Swiftpack.co - Package - CosmosSwift/swift-abci

swift-abci

Swift5.3+ platforms

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)

Installation

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"),
            ]
        ),
    ]
)

Getting Started

  1. Import ABCI and ABCINIO
import ABCI
import ABCINIO
  1. 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()
    }
}
  1. Implement the relevant Tendermint ABCI callbacks

See the example app ABCICounter. Check the abci spec for more details.

  1. Inititialize NIOABCIServer, with the application:
let server = NIOABCIServer(application: Application())
  1. Start the server
try server.start()
  1. Compile and run
swift run swift-abci-app
  1. 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"

Development

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:

  1. update the proto file (and possibly its import dependencies) from https://github.com/tendermint/tendermint/abci and put it in ./protobuf/...

  2. From the project root: protoc --swift_opt=FileNaming=PathToUnderscores --swift_out=./Sources/ABCI/ -I=./protobuf/ $(find protobuf/tendermint/ -iname "*.proto")

Compile:

  1. run swift build

Documentation

The docs for the latest tagged release are always available at the wiki.

Questions

For bugs or feature requests, file a new issue.

For all other support requests, please email opensource@katalysis.io.

Changelog

SemVer changes are documented for each release on the releases page.

Contributing

Check out CONTRIBUTING.md for more information on how to help with swift-abci.

Contributors

Check out CONTRIBUTORS.txt to see the full list. This list is updated for each release.

Github

link
Stars: 5

Used By

Total: 0

Releases

0.33.8 - Ventura - 2020-10-20 17:54:28