rewrites encode methods for readability (#2084)

This commit is contained in:
Jennifer Li Johnson 2019-05-30 15:01:55 -04:00 committed by GitHub
parent 4b75752d6b
commit 24c8132975
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,26 +9,29 @@ import (
"storj.io/storj/pkg/pb"
)
// EncodeOrderLimit encodes order limit into bytes for signing.
// EncodeOrderLimit encodes order limit into bytes for signing. Removes signature from serialized limit.
func EncodeOrderLimit(limit *pb.OrderLimit2) ([]byte, error) {
signature := limit.SatelliteSignature
limit.SatelliteSignature = nil
defer func() { limit.SatelliteSignature = signature }()
return proto.Marshal(limit)
out, err := proto.Marshal(limit)
limit.SatelliteSignature = signature
return out, err
}
// EncodeOrder encodes order into bytes for signing.
// EncodeOrder encodes order into bytes for signing. Removes signature from serialized order.
func EncodeOrder(order *pb.Order2) ([]byte, error) {
signature := order.UplinkSignature
order.UplinkSignature = nil
defer func() { order.UplinkSignature = signature }()
return proto.Marshal(order)
out, err := proto.Marshal(order)
order.UplinkSignature = signature
return out, err
}
// EncodePieceHash encodes piece hash into bytes for signing.
// EncodePieceHash encodes piece hash into bytes for signing. Removes signature from serialized hash.
func EncodePieceHash(hash *pb.PieceHash) ([]byte, error) {
signature := hash.Signature
hash.Signature = nil
defer func() { hash.Signature = signature }()
return proto.Marshal(hash)
out, err := proto.Marshal(hash)
hash.Signature = signature
return out, err
}