I read Rob Pike's post but it only works for repetitive loops. I, on the other hand, have this. Notice how I added the err
field, accessible via the Error()
method, in a futile attempt to reduce the if errs.
The code above is simpler, but the ReadRLP() function is no different from just returning a err. Is there some pattern that can help with this?
type namePreclaimRLP struct {
ObjectTag uint
RlpMessageVersion uint
AccountID []uint8
AccountNonce uint64
CommitmentID []uint8
Fee big.Int
TTL uint64
err error
}
func (n *namePreclaimRLP) ReadRLP(s *rlp.Stream) (aID, cID string) {
blob, err := s.Raw()
if err != nil {
n.err = err
}
err = rlp.DecodeBytes(blob, n)
if err != nil {
n.err = err
}
_, aID, err = readIDTag(n.AccountID)
if err != nil {
n.err = err
}
_, cID, err = readIDTag(n.CommitmentID)
if err != nil {
n.err = err
}
return aID, cID
}
func (n *namePreclaimRLP) Error() (err error) {
return n.err
}