mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-13 17:46:39 +00:00

* [NOD-1191] Convert wire protocol to 100% protobuf * [NOD-1191] Simplify wire interface and remove redundant messages * [NOD-1191] Map all proto to wire conversions * [NOD-1203] Create netadapter outside of protocol manager * [NOD-1191] Fix nil errors * [NOD-1191] Fix comments * [NOD-1191] Add converter interface * [NOD-1191] Add missing GetBlockLocator message * [NOD-1191] Change message names that starts with 'get' to 'request' * [NOD-1191] Change message commands values * [NOD-1191] Remove redundant methods * [NOD-1191] Rename message constructors * [NOD-1191] Change message commands to use iota * [NOD-1191] Add missing outputs to protobuf conversion * [NOD-1191] Make block header a required field * [NOD-1191] Rename variables * [NOD-1212] Fix test names * [NOD-1191] Rename flow names * [NOD-1191] Fix infinite loop
30 lines
1016 B
Go
30 lines
1016 B
Go
package protowire
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/wire"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func (x *KaspadMessage_BlockLocator) toWireMessage() (wire.Message, error) {
|
|
if len(x.BlockLocator.Hashes) > wire.MaxBlockLocatorsPerMsg {
|
|
return nil, errors.Errorf("too many block locator hashes for message "+
|
|
"[count %d, max %d]", len(x.BlockLocator.Hashes), wire.MaxBlockLocatorsPerMsg)
|
|
}
|
|
hashes, err := protoHashesToWire(x.BlockLocator.Hashes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &wire.MsgBlockLocator{BlockLocatorHashes: hashes}, nil
|
|
}
|
|
|
|
func (x *KaspadMessage_BlockLocator) fromWireMessage(msgBlockLocator *wire.MsgBlockLocator) error {
|
|
if len(msgBlockLocator.BlockLocatorHashes) > wire.MaxBlockLocatorsPerMsg {
|
|
return errors.Errorf("too many block locator hashes for message "+
|
|
"[count %d, max %d]", len(msgBlockLocator.BlockLocatorHashes), wire.MaxBlockLocatorsPerMsg)
|
|
}
|
|
x.BlockLocator = &BlockLocatorMessage{
|
|
Hashes: wireHashesToProto(msgBlockLocator.BlockLocatorHashes),
|
|
}
|
|
return nil
|
|
}
|