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 ¶
- func PeerEqual(p1, p2 perun.Peer) bool
- type Provider
- func (c Provider) Delete(alias string) error
- func (c Provider) ReadByAlias(alias string) (_ perun.Peer, isPresent bool)
- func (c Provider) ReadByOffChainAddr(offChainAddr pwire.Address) (_ perun.Peer, isPresent bool)
- func (c *Provider) UpdateStorage() error
- func (c Provider) Write(alias string, p perun.Peer) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
Delete deletes the peer from contacts cache. Returns an error if peer corresponding to given alias is not found.
func (Provider) ReadByAlias ¶
ReadByAlias returns the peer corresponding to given alias from the cache.
func (Provider) ReadByOffChainAddr ¶
ReadByOffChainAddr returns the peer corresponding to given off-chain address from the cache.
func (*Provider) UpdateStorage ¶
UpdateStorage writes the latest state of contacts cache to the yaml file.