-
Notifications
You must be signed in to change notification settings - Fork 132
[group key addrs 3/5]: misc refactor #1611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Pull Request Test Coverage Report for Build 15844222703Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Easy to review 👍
fn/memory.go
Outdated
// Serializer is an interface that defines a method to serialize data | ||
// into an io.Writer. | ||
type Serializer interface { | ||
Serialize(w io.Writer) error | ||
} | ||
|
||
// Serialize encodes the given Serializer into a byte slice. | ||
func Serialize(s Serializer) ([]byte, error) { | ||
if s == nil { | ||
return nil, nil | ||
} | ||
|
||
var buf bytes.Buffer | ||
err := s.Serialize(&buf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return buf.Bytes(), nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop these in favour of the encode style above? I think that having both in a core package like fn
just leads to unnecessary confusion. Fundamental packages like fn
provide future dev guidance.
Or perhaps there is some fundamental meaning difference between the terms "encode" and "serialize" that I don't know about? If there is please add to doc comments so that I know what one to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add a new file called encoding.go
to fn
to accommodate these changes. From my pov, I don't think they're related to memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean by "in favor of the encoding style above"? These are helper functions to easily convert existing types to bytes. And some types (e.g. wire.MsgTx
, psbt.Packet
) define a Serialize()
method while other types have an Encode()
method. And we want to support both.
Moved the definitions to encoding.go
.
ec4345c
to
81fbf58
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm 🦫
This commit adds a helper for serializing/encoding structs that otherwise require the use of a buffer. In most situations this makes the code a bit shorter and less repetitive.
We'll need to be able to derive a shared key using ECDH against a wallet key (while supporting remote signing) for the ECIES encryption in part 4 of the on-chain group key address support PR series. We can prepare for that by adding the already exising RPC method to the lnd key ring.
This allows us to use an asset specifier when creating a new address, which means we also have to be able to look up the asset group info using a group key. We can't test this on the RPC layer yet, because we don't actually allow addresses to be created for group keys only (this will com in part 4 of the group key address PR series).
Extracts some refactor commits out from #1587, which are mostly independent of the functionality in that PR and can be reviewed and merged individually.