Documentation
¶
Overview ¶
Package payment contains a simplified API of go-perun.
Index ¶
- func DeployContracts(ctx context.Context, wallet *Wallet, chainURL string) (common.Address, common.Address, error)
- func SetLogLevel(level logrus.Level, formatter logrus.Formatter)
- type Balance
- type Channel
- type ChannelProposal
- type Client
- func (c *Client) Close(ctx context.Context) error
- func (c *Client) HandleProposal(_prop client.ChannelProposal, responder *client.ProposalResponder)
- func (c *Client) HandleUpdate(update client.ChannelUpdate, responder *client.UpdateResponder)
- func (c *Client) Init(ctx context.Context, adj, ah common.Address) error
- func (c *Client) OnChainBalance(ctx context.Context, addrs ...wallet.Address) ([]*big.Int, error)
- func (c *Client) Proposals() <-chan *ChannelProposal
- func (c *Client) ProposeChannel(ctx context.Context, peer Peer, bals Balance) (*Channel, error)
- func (c *Client) RegisterPeer(addr wire.Address, host, alias string) (Peer, error)
- type ClientOption
- type Config
- type Dialer
- type ETHAmount
- type Peer
- type Wallet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeployContracts ¶
func DeployContracts(ctx context.Context, wallet *Wallet, chainURL string) (common.Address, common.Address, error)
DeployContracts deploys the Adjudicator and Assetholder contract and returns their addresses. The context timeout must be at least twice the block time to allow for the transactions to be mined. To be safe, put it higher.
func SetLogLevel ¶
SetLogLevel can be used to define how verbose the log output should be. The default value is `WarnLevel` with disabled console colors. Set it to `Debug` or even `Trace` if you are debugging an error. Example: `SetLogLevel(logrus.DebugLevel, &logrus.TextFormatter{})`.
Types ¶
type Balance ¶
type Balance struct {
My, Other ETHAmount
}
Balance represents the balance of funds in a channel.
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
Channel is a payment channel. Can send and receive funds from a single peer. The current balance is available via `Balance()`. Payments on a channel cannot happen in both directions at once. The same applies to channel closing; one of the participants has to go first.
func (*Channel) Close ¶
Close gracefully closes the channel. All funds will be distributed on-chain.
func (*Channel) HandleAdjudicatorEvent ¶
func (c *Channel) HandleAdjudicatorEvent(_e channel.AdjudicatorEvent)
HandleAdjudicatorEvent DO NOT CALL. It is called by the framework for adjudicator events.
type ChannelProposal ¶
type ChannelProposal struct { From Peer // Peer that sent it. Balance Balance // Initial balance of the channel. // contains filtered or unexported fields }
ChannelProposal models a proposal for a channel that was received by the Client from a known Peer. Can be accepted or rejected. Fully thread-safe. Should not be copied.
func (*ChannelProposal) Accept ¶
func (p *ChannelProposal) Accept(ctx context.Context) (*Channel, error)
Accept accepts the channel proposal. Errors if the proposal was already accepted or rejected.
It is important that the passed context does not cancel before twice the block time has passed (at least for real blockchain backends with wall time), or the channel cannot be settled if a peer times out funding.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
The Client is the central object for opening payment channels.
It is completely thread safe and should not be copied. Always `Close()` a client when your application shuts down to avoid losing funds.
func NewClient ¶
func NewClient(wallet *Wallet, cfg Config, opts ...ClientOption) (*Client, error)
NewClient creates a new client. The account from `wallet` will be used to send on-chain transactions. Pass one or more `ClientOption`s to modify the default behaviour.
func (*Client) HandleProposal ¶
func (c *Client) HandleProposal(_prop client.ChannelProposal, responder *client.ProposalResponder)
HandleProposal DO NOT CALL. It is called by the framework for incoming channel proposals.
func (*Client) HandleUpdate ¶
func (c *Client) HandleUpdate(update client.ChannelUpdate, responder *client.UpdateResponder)
HandleUpdate DO NOT CALL. It is called by the framework for incoming channel updates.
func (*Client) Init ¶
Init sets and verifies the addresses of the Adjudicator and Assetholder contracts.
func (*Client) OnChainBalance ¶
OnChainBalance returns the on-chain balances for the passed addresses in WEI.
func (*Client) Proposals ¶
func (c *Client) Proposals() <-chan *ChannelProposal
Proposals returns a channel that all incoming channel proposals can be read from. The buffer size can be configured via the config `ProposalBufferSize`. It is advised to always read from this channel to avoid blocking client operation.
func (*Client) ProposeChannel ¶
ProposeChannel proposes a channel to `peer`. `bals` is the initial balance of the channel. It must be lower than the on-chain balance since both participants will use their on-chain balance to fund the channel.
func (*Client) RegisterPeer ¶
RegisterPeer registers a peer in the client. This is necessary to be able to send or receive a channel proposal from a peer. `addr` is the peers address. `host` is the ip:port that the peer listens on. `alias` a nickname for the peer. Does not need to be unique.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption is an option that can be passed to `NewClient` to change the default behaviour of a client.
func WithDialer ¶
func WithDialer(dialer Dialer) ClientOption
WithDialer can be used to pass a custom dialer into the Client. The configuration option `DialTimeout` will be unused in this case.
func WithListener ¶
func WithListener(listener net.Listener) ClientOption
WithListener can be used to pass a custom listener into the Client. The configuration option `Host` will be unused in this case.
type Config ¶
type Config struct {
Host, ChainURL string
ChallengeDuration time.Duration
DialTimeout time.Duration
ProposalBufferSize uint
UpdateBufferSize uint
}
Config contains all configuration options that are needed to create a Client. Should be created with `MakeConfig`.
func MakeConfig ¶
MakeConfig returns a new Config. All options that are not passed as arguments are set to default values. You can still modify them manually. `host` is the ip:port that the client should listen on for connections. `chainURL` is the URL of your Ethereum node. In the local ganache-cli case this would be: ws://0.0.0.0:8545 `challengeDuration` is the time in seconds that an on-chain challenge will last. This should be at least 3 times the average block time.
type Dialer ¶
type Dialer interface { net.Dialer // Register will be called by the Payment client's `RegisterPeer` // function. Register(wire.Address, string) }
Dialer wraps a go-perun wire/net.Dialer and adds a `Register` function to it.
type ETHAmount ¶
type ETHAmount struct {
// contains filtered or unexported fields
}
ETHAmount represents an amount of Ethereum.
func MakeAmountFromETH ¶
MakeAmountFromETH creates an `ETHAmount` with the given amount of ethereum set. Floating-point imprecision may apply.
func MakeAmountFromWEI ¶
MakeAmountFromWEI creates an `ETHAmount` with the given amount of WEI set.
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer identifies a known peer. Can only be created with Client.RegisterPeer.
type Wallet ¶
Wallet contains a single account that will be used to send on-chain transactions. Its address is public.
func NewWalletHD ¶
NewWalletHD creates a new single-account HD-wallet with the given mnemonic. `index` is the index of the account that will be used.