Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hyperledger-labs/go-perun
π Perun's Blockchain-Agnostic State Channels Framework in Go.
https://github.com/hyperledger-labs/go-perun
blockchain go state-channels
Last synced: about 1 month ago
JSON representation
π Perun's Blockchain-Agnostic State Channels Framework in Go.
- Host: GitHub
- URL: https://github.com/hyperledger-labs/go-perun
- Owner: hyperledger-labs
- License: apache-2.0
- Created: 2020-07-29T10:41:40.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-09T09:15:36.000Z (6 months ago)
- Last Synced: 2024-11-09T20:28:55.740Z (about 1 month ago)
- Topics: blockchain, go, state-channels
- Language: Go
- Homepage: https://perun.network/
- Size: 3.43 MB
- Stars: 55
- Watchers: 7
- Forks: 18
- Open Issues: 48
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Perun Blockchain-Agnostic State Channels Framework
_go-perun_ is a Go implementation of the [Perun state channel protocols](https://perun.network/) ([introduction paper](https://perun.network/wp-content/uploads/Perun2.0.pdf)).
The perun protocols provide payment and general state channel functionality to all existing blockchains that feature smart contracts.
As a blockchain scalability solution, payment and state channels reduce transaction costs and increase the system throughput by executing incremental transactions off-chain.
The Perun protocols have been proven cryptographically secure in the UC-framework.
They are blockchain-agnostic and only rely on a blockchain's capability to execute smart contracts.## Security Disclaimer
This software is still under development.
The authors take no responsibility for any loss of digital assets or other damage caused by the use of it.## Getting Started
Running _go-perun_ requires a working [Go distribution](https://golang.org), see `go.mod` for the required version.
```sh
# Clone the repository into a directory of your choice
git clone https://github.com/hyperledger-labs/go-perun.git
# Or directly download it with go
# go get -d perun.network/go-perun
cd go-perun
# Run the unit tests
go test ./...
```You can import _go-perun_ in your project like this:
```go
import "perun.network/go-perun/client"
```_go-perun_ implements the core state channel protocol in a blockchain-agnostic fashion by following the dependency inversion principle.
For this reason, a blockchain backend has to be chosen and blockchain-specific initializations need to be executed at program startup.### Documentation
In-depth documentation can be found at [perun-doc](https://labs.hyperledger.org/perun-doc/)
and on [go-perun's pkg.go.dev site](https://pkg.go.dev/perun.network/go-perun).Our [walkthrough tutorial](http://tutorial.perun.network) describes how _go-perun_ is used to build a simple micro-payment application on top of Ethereum.
A bunch of examples can be found at [perun-examples](https://github.com/perun-network/perun-examples).
## Features
_go-perun_ currently provides two-party channels with the following features:
* Generalized state channels, including app/sub-channels
* Dispute watchtower
* Data persistence
* Virtual payment channels (direct dispute)
* Multi-ledger channelsThe following features are planned for future releases:
* Virtual payment channels (indirect dispute)
* Virtual state channels
* Multi-party channels
* Multi-ledger app/virtual channels### Backends
There are multiple **blockchain backends** available. A backend is automatically initialized when its top-level package `backend/` is imported.
- **Ethereum.** The Ethereum backend is available at [perun-eth-backend](https://github.com/perun-network/perun-eth-backend/).
- **Polkadot.** The Polkadot backend is available at [perun-polkadot-backend](https://github.com/perun-network/perun-polkadot-backend).
- **Cosmos.** The Cosmos backend is available at [perun-cosmwasm-backend](https://github.com/hyperledger-labs/perun-cosmwasm-backend).
- **Cardano.** The Cardano backend is available at [perun-cardano-backend](https://github.com/perun-network/perun-cardano-backend).
- **NERVOS.** The NERVOS backend is available at [perun-ckb-backend](https://github.com/perun-network/perun-ckb-backend).
- **Dfinity.** The Dfinity Internet Computer backend is available at [perun-icp-backend](https://github.com/perun-network/perun-icp-backend).
- **Fabric.** The Hyperledger Fabric backend is available at [perun-fabric](https://github.com/perun-network/perun-fabric).
- **SimBackend.** The SimBackend represents an ideal blockchain backend (`backend/sim`) implementation that can be used for testing.**Logging and networking** capabilities can also be injected by the user.
A default [logrus](https://github.com/sirupsen/logrus) implementation of the `log.Logger` interface can be set using `log/logrus.Set`.
The Perun framework relies on a user-injected `wire.Bus` for inter-peer communication.
_go-perun_ ships with the `wire/net.Bus` implementation for TCP and Unix sockets.**Data persistence** can be enabled to continuously persist new states and signatures.
There are currently three persistence backends provided, namely, a test backend for testing purposes, an in-memory key-value persister and a [LevelDB](https://github.com/syndtr/goleveldb) backend.## API Primer
In essence, _go-perun_ provides a state channel network client, akin to ethereum's `ethclient` package, to interact with a state channels network.
Once the client has been set up, it can be used to propose channels to other network peers, accept channel proposals, send updates on those channels and eventually settle them.A minimal, illustrative usage is as follows
```go
package mainimport (
"context"
"time""perun.network/go-perun/channel"
"perun.network/go-perun/client"
"perun.network/go-perun/log"
"perun.network/go-perun/peer"
"perun.network/go-perun/wallet"
"perun.network/go-perun/watcher"
"perun.network/go-perun/wire"
// other imports
)func main() {
// setup blockchain interaction
var funder channel.Funder
var adjudicator channel.Adjudicator
// setup perun network identity
var perunID wire.Address
// setup communication bus
var bus wire.Bus
// setup wallet for channel accounts
var wallet wallet.Wallet
// setup channel watcher
var watcher watcher.Watcher// create state channel network client
c := client.New(perunID, bus, funder, adjudicator, wallet, watcher)// choose how to react to incoming channel proposals
var proposalHandler client.ProposalHandler
// choose how to react to incoming channel update requests
var updateHandler client.UpdateHandler
// start incoming request handler
go c.Handle(proposalHandler, updateHandler)// propose a new channel
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
ch, err := c.ProposeChannel(ctx, client.NewLedgerChannelProposal(
// details of channel proposal, like peers, app, initial balances, challenge duration...
))
if err != nil { /* handle error */ }// start watchtower
go func() {
err := ch.Watch()
log.Info("Watcher returned with error ", err)
}()// send a channel update request to the other channel peer(s)
err = ch.Update(ctx, func(s *channel.State) {
// update state s, e.g., moving funds or changing app data
})
if err != nil { /* handle error */ }// send further updates and finally, settle/close the channel
if err := ch.Settle(ctx); err != nil { /* handle error */ }
}
```For a full-fledged example, have a look at our CLI Demo [perun-eth-demo](https://github.com/perun-network/perun-eth-demo).
Go mobile wrappers for and iOS App development can be found at [perun-eth-mobile](https://github.com/perun-network/perun-eth-mobile).## Funding
This project has been started at the Chair of Applied Cryptography at Technische UniversitΓ€t Darmstadt, Germany, and is currently developed and maintained by a group of dedicated hackers from PolyCrypt GmbH.
We thank the German Federal Ministry of Education and Research (BMBF) for their funding through the StartUpSecure grants program as well as the German Science Foundation (DFG), the Foundation for Polish Science (FNP) and the Ethereum Foundation for their support in the research that preceded this implementation.## Copyright
Copyright 2022 - See [NOTICE file](NOTICE) for copyright holders.
Use of the source code is governed by the Apache 2.0 license that can be found in the [LICENSE file](LICENSE).Contact us at [[email protected]](mailto:[email protected]).