contactsyaml

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package contactsyaml implements contacts provider to access contacts stored in a yaml file.

The complete list of contacts are loaded into an in-memory cache during initialization. The entries in the cache are indexed by both alias and off-chain address of the peer and can be using either of these as reference.

Read, Write and Delete operations act only on the cache and do not affect the contents of the file.

Latest state of cache can be updated to the file by explicitly calling UpdateStorage method. Normally this should be called before shutting down the node.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PeerEqual

func PeerEqual(p1, p2 perun.Peer) bool

PeerEqual returns true if all fields in the Peer except OffChainAddr are equal.

Types

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider represents a contacts provider that provides access to contacts stored in a yaml file.

It generates a cache of all contacts in the yaml file during initialization. Read, Write and Delete operations act only on the cached list of contacts and do not update the yaml file. The changes in cache can be updated to the yaml file by explicitly calling UpdateStorage method.

It also stores an instance of wallet backend that will be used or decoding address strings.

func New

func New(filePath string, backend perun.WalletBackend) (*Provider, error)

New returns an instance of contacts provider to access the contacts in the given yaml file.

All the contacts are cached in memory during initialization and Read, Write, Delete operations affect only the cache. The changes are updated to the yaml file only when UpdateStorage method is explicitly called. There is no mechanism to reload the cache if the yaml file is updated.

Backend is used for decoding the address strings during initialization.

func (Provider) Delete

func (c Provider) Delete(alias string) error

Delete deletes the peer from contacts cache. Returns an error if peer corresponding to given alias is not found.

func (Provider) ReadByAlias

func (c Provider) ReadByAlias(alias string) (_ perun.Peer, isPresent bool)

ReadByAlias returns the peer corresponding to given alias from the cache.

func (Provider) ReadByOffChainAddr

func (c Provider) ReadByOffChainAddr(offChainAddr pwire.Address) (_ perun.Peer, isPresent bool)

ReadByOffChainAddr returns the peer corresponding to given off-chain address from the cache.

func (*Provider) UpdateStorage

func (c *Provider) UpdateStorage() error

UpdateStorage writes the latest state of contacts cache to the yaml file.

func (Provider) Write

func (c Provider) Write(alias string, p perun.Peer) error

Write adds the peer to contacts cache. Returns an error if the alias is already used by same or different peer or, if the off-chain address string of the peer cannot be parsed using the wallet backend of this contacts provider.

Jump to

Keyboard shortcuts

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