Skip to content

perun-network/channel-service

Repository files navigation


Perun

Perun-Channel-Service

License: Apache 2.0

This repository contains contains an implementation of the Channel Service, which is standardized to allow implementing Perun channels into any CKB wallet ready to conform with the standard.

The specification can be found in the repository perun-wallet-spec.

Table of Contents

Introduction

The Perun-Channel-Service is a core component designed to facilitate the integration of Perun payment channels into CKB wallets. By adhering to the standardized implementation, developers can seamlessly integrate this service into their wallet applications, ensuring compatibility and enhanced functionality.

Features

  • Perun Payment Channels interactions (Open, Update, Close, Restore)
  • Built-in persistence
  • Compatible with any CKB wallet
  • Follows the perun-wallet-spec
  • Open-source under the Apache 2.0 license

Installation

Import the Perun-Channel-Service module:

go get github.com/perun-network/channel-service

You might need to replace the github path with the actual module name in your go.mod:

require (
    github.com/perun-network/perun-channel-service v0.0.0
)

replace perun.network/channel-service v0.0.0 => github.com/perun-network/channel-service v0.1.0

Usage

Start a Channel-Service instance in a GRPC Server:

// Create a channel service instance.
cs, err := service.NewChannelService(wsc, network, rpcNodeUrl, d, nil, db)
if  err != nil { /* error handling */ }

// Deploy the channel service on a GRPC Server.
lis := bufconn.Listen(bufSize)
baseServer := grpc.NewServer()

proto.RegisterChannelServiceServer(baseServer, cs)
go func() {
		err := baseServer.Serve(lis)
		if err != nil { /* error handling */ }
}()

/*
// ...
*/

// Clean up after use.
defer func() {
  	err := lis.Close()
		if err != nil { /* error handling */ }
		baseServer.Stop()
}()

Wallet User can create a Channel Service Client by connecting to the GRPC Server:

// Dial connection with channel service server.
conn, err := grpc.DialContext(context.Background(), "bufnet", grpc.WithContextDialer(func(context.Context, string) (defaultnet.Conn, error) {
	return lis.Dial()
}), grpc.WithTransportCredentials(insecure.NewCredentials()))
  
if  err != nil { /* error handling */ }
  
// Create the channel service client.
channelServiceClient := proto.NewChannelServiceClient(conn)

Test

Test Chain Dependencies

We use various tools to enable a convenient setup for the local development testnet. If you want to use our setup-devnet.sh script, make sure the following commandline tools are installed:

  • jq:
    • Used to parse and edit some configuration files.
  • sed and awk:
    • We modify some fields of the files generated by the ckb init --chain dev command using sed and awk.
  • tmux and tmuxp:
    • tmuxp is a session manager for tmux that allows to easily create descriptive .yaml configuration files to create and attach to tmux sessions.
  • expect:
    • We completely automize the process for test-wallet creation, deploying of contracts etc. To make this work reliably, we use expect which allows to describe how a commandline application is fed input.
  • make:
    • Not strictly necessary, but it should be available on most systems by default. In case you do not want to install make check out the Makefile content and issue the command on your own.
  • ckb with version 0.109.0 or higher.
  • ckb-cli with version 1.4.0 or higher.
  • capsule with version 0.9.2.
  • docker and a running dockerd instance!

Setup

Start a test chain on a terminal.

cd ./test/devnet
make dev

Test the channel-service on another terminal.

go test -v channel_service_test.go 

Demo

The Perun-Nervos-Demo demonstrates the use of how a Wallet User can interact with the Channel-Service through RPC Messages and manage Perun Payment Channels on Nervos Network.

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5