diff --git a/reputation/convert.go b/reputation/convert.go index 67f3aafa..924b1edd 100644 --- a/reputation/convert.go +++ b/reputation/convert.go @@ -138,7 +138,7 @@ func (x *PeerToPeerTrust) FromGRPCMessage(m grpc.Message) error { // TrustsToGRPC converts slice of Trust structures // to slice of gRPC-generated Trust messages. -func TrustsToGRPC(xs []*Trust) (res []*reputation.Trust) { +func TrustsToGRPC(xs []Trust) (res []*reputation.Trust) { if xs != nil { res = make([]*reputation.Trust, 0, len(xs)) @@ -152,23 +152,17 @@ func TrustsToGRPC(xs []*Trust) (res []*reputation.Trust) { // TrustsFromGRPC tries to restore slice of Trust structures from // slice of gRPC-generated reputation.Trust messages. -func TrustsFromGRPC(xs []*reputation.Trust) (res []*Trust, err error) { +func TrustsFromGRPC(xs []*reputation.Trust) (res []Trust, err error) { if xs != nil { - res = make([]*Trust, 0, len(xs)) + res = make([]Trust, len(xs)) for i := range xs { - var x *Trust - if xs[i] != nil { - x = new(Trust) - - err = x.FromGRPCMessage(xs[i]) + err = res[i].FromGRPCMessage(xs[i]) if err != nil { return } } - - res = append(res, x) } } diff --git a/reputation/marshal.go b/reputation/marshal.go index 1af68c98..20d1fd77 100644 --- a/reputation/marshal.go +++ b/reputation/marshal.go @@ -238,7 +238,7 @@ func (x *AnnounceLocalTrustRequestBody) StableMarshal(buf []byte) ([]byte, error offset += n for i := range x.trusts { - n, err = protoutil.NestedStructureMarshal(announceLocalTrustBodyTrustsFNum, buf[offset:], x.trusts[i]) + n, err = protoutil.NestedStructureMarshal(announceLocalTrustBodyTrustsFNum, buf[offset:], &x.trusts[i]) if err != nil { return nil, err } @@ -253,7 +253,7 @@ func (x *AnnounceLocalTrustRequestBody) StableSize() (size int) { size += protoutil.UInt64Size(announceLocalTrustBodyEpochFNum, x.epoch) for i := range x.trusts { - size += protoutil.NestedStructureSize(announceLocalTrustBodyTrustsFNum, x.trusts[i]) + size += protoutil.NestedStructureSize(announceLocalTrustBodyTrustsFNum, &x.trusts[i]) } return diff --git a/reputation/test/generate.go b/reputation/test/generate.go index fb1239ab..00e6009d 100644 --- a/reputation/test/generate.go +++ b/reputation/test/generate.go @@ -61,13 +61,13 @@ func GenerateGlobalTrust(empty bool) *reputation.GlobalTrust { return m } -func GenerateTrusts(empty bool) []*reputation.Trust { - var res []*reputation.Trust +func GenerateTrusts(empty bool) []reputation.Trust { + var res []reputation.Trust if !empty { res = append(res, - GenerateTrust(false), - GenerateTrust(false), + *GenerateTrust(false), + *GenerateTrust(false), ) } diff --git a/reputation/types.go b/reputation/types.go index 4ce995dd..5ccb2030 100644 --- a/reputation/types.go +++ b/reputation/types.go @@ -209,7 +209,7 @@ func (x *GlobalTrust) SetSignature(v *refs.Signature) { type AnnounceLocalTrustRequestBody struct { epoch uint64 - trusts []*Trust + trusts []Trust } // GetEpoch returns epoch in which the trust was assessed. @@ -229,7 +229,7 @@ func (x *AnnounceLocalTrustRequestBody) SetEpoch(v uint64) { } // GetTrusts returns list of normalized trust values. -func (x *AnnounceLocalTrustRequestBody) GetTrusts() []*Trust { +func (x *AnnounceLocalTrustRequestBody) GetTrusts() []Trust { if x != nil { return x.trusts } @@ -238,7 +238,7 @@ func (x *AnnounceLocalTrustRequestBody) GetTrusts() []*Trust { } // SetTrusts sets list of normalized trust values. -func (x *AnnounceLocalTrustRequestBody) SetTrusts(v []*Trust) { +func (x *AnnounceLocalTrustRequestBody) SetTrusts(v []Trust) { if x != nil { x.trusts = v }