connections

package
v0.0.0-...-0854145 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Lister
	Leaver
	Joiner
}

Client allows for list, leave and join operations for a Raiden node.

func NewClient

func NewClient(config *config.Config, httpClient *http.Client) *Client

NewClient creates a new Connections client that will be able to List all Open connections, Join and Leave connections for a Raiden node.

type Connection

type Connection struct {
	Funds       int64 `json:"funds"`
	SumDeposits int64 `json:"sum_deposits"`
	Channels    int64 `json:"channels"`
}

Connection represents a high level information about the Funds, Total deposits and numbers of channels for a given network.

type Connections

type Connections map[common.Address]*Connection

Connections represent a map of token network address to a Connection pointer.

type Joiner

type Joiner interface {
	Join(ctx context.Context, tokenAddress common.Address, funds int64) error
}

Joiner is an interface to allow for a Raiden node to join a new token network with a given number of funds.

Example
var (
	connClient *Client
	config     = &config.Config{
		Host:       "http://localhost:5001",
		APIVersion: "v1",
	}
	tokenAddress = common.HexToAddress("0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359") // DAI Stablecoin
	funds        = int64(1000)
	err          error
)

connClient = NewClient(config, http.DefaultClient)

if err = connClient.Join(context.Background(), tokenAddress, funds); err != nil {
	panic(fmt.Sprintf("unable to join connection: %s", err.Error()))
}

fmt.Printf("succuessfully join connection")
Output:

func NewJoiner

func NewJoiner(config *config.Config, httpClient *http.Client) Joiner

NewJoiner will create a default joiner that will allow access to join a new token network for a Raiden node.

type Leaver

type Leaver interface {
	Leave(ctx context.Context, tokenAddress common.Address) ([]common.Address, error)
}

Leaver is an interface to leave a token network.

Example
var (
	connClient *Client
	config     = &config.Config{
		Host:       "http://localhost:5001",
		APIVersion: "v1",
	}
	tokenAddress = common.HexToAddress("0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359") // DAI Stablecoin
	addresses    []common.Address
	err          error
)

connClient = NewClient(config, http.DefaultClient)

if addresses, err = connClient.Leave(context.Background(), tokenAddress); err != nil {
	panic(fmt.Sprintf("unable to leave connection: %s", err.Error()))
}

for _, a := range addresses {
	fmt.Println("address:", a.String())
}
Output:

func NewLeaver

func NewLeaver(config *config.Config, httpClient *http.Client) Leaver

NewLeaver will create a default leaver that will allow one to Leave a token network.

type Lister

type Lister interface {
	List(ctx context.Context) (Connections, error)
}

Lister is an interface to list all token network connections on a given Raiden node.

Example
var (
	connClient *Client
	config     = &config.Config{
		Host:       "http://localhost:5001",
		APIVersion: "v1",
	}
	connections Connections
	err         error
)

connClient = NewClient(config, http.DefaultClient)

if connections, err = connClient.List(context.Background()); err != nil {
	panic(fmt.Sprintf("unable to leave connection: %s", err.Error()))
}

for address, conn := range connections {
	fmt.Printf("%s: %+v\n", address.String(), conn)
}
Output:

func NewLister

func NewLister(config *config.Config, httpClient *http.Client) Lister

NewLister will create a default lister that will list out all the token network connections for a given Raiden node configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL