go-perun icon indicating copy to clipboard operation
go-perun copied to clipboard

Naming of channel.Backend and wallet.Backend

Open matthiasgeihs opened this issue 4 years ago • 1 comments

Context: Package channel and wallet have an interface type Backend that provides a set of utility functions.

Problem: The name Backend suggests that the type provides all kinds of backend functionality while in fact it only provides a set of static utility functions. This is not evident and causes confusion when working with the code.

Suggestion: We could rename type Backend to Util or Static to clarify that it is a static utility object.

Caveat: This would affect all backend implementations. However, if we want to change it, it's better to do it sooner than later.

matthiasgeihs avatar Sep 01 '21 08:09 matthiasgeihs

Instead of choosing a general name, we could also try to be more specific.
To give an idea about what we are talking about:

wallet.Backend interface {
	DecodeAddress(io.Reader) (Address, error)
	DecodeSig(io.Reader) (Sig, error)
	VerifySignature(msg []byte, sign Sig, a Address) (bool, error)
}

Since we thought about removing DecodeSig, we could then rename the wallet Backend.
We could also split it in two interfaces if that makes it clearer, the SetBackend function would then accept multiple arguments.

channel.Backend interface {
	CalcID(*Params) ID
	Sign(wallet.Account, *Params, *State) (wallet.Sig, error)
	Verify(addr wallet.Address, params *Params, state *State, sig wallet.Sig) (bool, error)
	DecodeAsset(io.Reader) (Asset, error)
}

Maybe something similar is possible for the channel backend.

ggwpez avatar Sep 01 '21 09:09 ggwpez