Convert MsgGetHeaders errors to MessageError type.

This commit is contained in:
Dave Collins 2013-05-10 23:58:10 -05:00
parent 95aa4a7da8
commit 9bd97a5972

View file

@ -34,9 +34,9 @@ type MsgGetHeaders struct {
// AddBlockLocatorHash adds a new block locator hash to the message. // AddBlockLocatorHash adds a new block locator hash to the message.
func (msg *MsgGetHeaders) AddBlockLocatorHash(hash *ShaHash) error { func (msg *MsgGetHeaders) AddBlockLocatorHash(hash *ShaHash) error {
if len(msg.BlockLocatorHashes)+1 > MaxBlockLocatorsPerMsg { if len(msg.BlockLocatorHashes)+1 > MaxBlockLocatorsPerMsg {
str := "MsgGetHeaders.AddBlockLocatorHash: too many block " + str := fmt.Sprintf("too many block locator hashes for message [max %v]",
"locator hashes for message [max %v]" MaxBlockLocatorsPerMsg)
return fmt.Errorf(str, MaxBlockLocatorsPerMsg) return messageError("MsgGetHeaders.AddBlockLocatorHash", str)
} }
msg.BlockLocatorHashes = append(msg.BlockLocatorHashes, hash) msg.BlockLocatorHashes = append(msg.BlockLocatorHashes, hash)
@ -57,8 +57,9 @@ func (msg *MsgGetHeaders) BtcDecode(r io.Reader, pver uint32) error {
return err return err
} }
if count > MaxBlockLocatorsPerMsg { if count > MaxBlockLocatorsPerMsg {
str := "%v: too many block locator hashes in message [%v]" str := fmt.Sprintf("too many block locator hashes for message "+
return fmt.Errorf(str, "MsgGetHeaders.BtcDecode", count) "[count %v, max %v]", count, MaxBlockLocatorsPerMsg)
return messageError("MsgGetHeaders.BtcDecode", str)
} }
for i := uint64(0); i < count; i++ { for i := uint64(0); i < count; i++ {
@ -84,9 +85,9 @@ func (msg *MsgGetHeaders) BtcEncode(w io.Writer, pver uint32) error {
// Limit to max block locator hashes per message. // Limit to max block locator hashes per message.
count := len(msg.BlockLocatorHashes) count := len(msg.BlockLocatorHashes)
if count > MaxBlockLocatorsPerMsg { if count > MaxBlockLocatorsPerMsg {
str := "MsgGetHeaders.BtcEncode: too many block locator " + str := fmt.Sprintf("too many block locator hashes for message "+
"hashes in message [%v]" "[count %v, max %v]", count, MaxBlockLocatorsPerMsg)
return fmt.Errorf(str, count) return messageError("MsgGetHeaders.BtcEncode", str)
} }
err := writeElement(w, msg.ProtocolVersion) err := writeElement(w, msg.ProtocolVersion)