mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-12 00:56:42 +00:00

* [NOD-1225] Rename wire to domainmessage * [NOD-1225] Get rid of references to package wire in the code, and get rid of InvType
30 lines
1.1 KiB
Go
30 lines
1.1 KiB
Go
package protowire
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/domainmessage"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func (x *KaspadMessage_BlockLocator) toDomainMessage() (domainmessage.Message, error) {
|
|
if len(x.BlockLocator.Hashes) > domainmessage.MaxBlockLocatorsPerMsg {
|
|
return nil, errors.Errorf("too many block locator hashes for message "+
|
|
"[count %d, max %d]", len(x.BlockLocator.Hashes), domainmessage.MaxBlockLocatorsPerMsg)
|
|
}
|
|
hashes, err := protoHashesToWire(x.BlockLocator.Hashes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &domainmessage.MsgBlockLocator{BlockLocatorHashes: hashes}, nil
|
|
}
|
|
|
|
func (x *KaspadMessage_BlockLocator) fromDomainMessage(msgBlockLocator *domainmessage.MsgBlockLocator) error {
|
|
if len(msgBlockLocator.BlockLocatorHashes) > domainmessage.MaxBlockLocatorsPerMsg {
|
|
return errors.Errorf("too many block locator hashes for message "+
|
|
"[count %d, max %d]", len(msgBlockLocator.BlockLocatorHashes), domainmessage.MaxBlockLocatorsPerMsg)
|
|
}
|
|
x.BlockLocator = &BlockLocatorMessage{
|
|
Hashes: wireHashesToProto(msgBlockLocator.BlockLocatorHashes),
|
|
}
|
|
return nil
|
|
}
|