@@ -103,30 +103,41 @@ func BatchProofDeserialize(r io.Reader) (*utreexo.Proof, error) {
103
103
return nil , err
104
104
}
105
105
106
- targets := make ([]uint64 , targetCount )
107
- for i := range targets {
108
- target , err := ReadVarInt (r , 0 )
109
- if err != nil {
110
- return nil , err
111
- }
106
+ proof := new (utreexo.Proof )
112
107
113
- targets [i ] = target
108
+ if targetCount > 0 {
109
+ targets := make ([]uint64 , 0 , targetCount )
110
+ for i := 0 ; i < int (targetCount ); i ++ {
111
+ target , err := ReadVarInt (r , 0 )
112
+ if err != nil {
113
+ return nil , err
114
+ }
115
+
116
+ targets = append (targets , target )
117
+ }
118
+ proof .Targets = targets
114
119
}
115
120
116
121
proofCount , err := ReadVarInt (r , 0 )
117
122
if err != nil {
118
123
return nil , err
119
124
}
125
+ if proofCount == 0 {
126
+ return proof , nil
127
+ }
120
128
121
- proofs := make ([]utreexo.Hash , proofCount )
122
- for i := range proofs {
123
- _ , err = io .ReadFull (r , proofs [i ][:])
129
+ proofs := make ([]utreexo.Hash , 0 , proofCount )
130
+ for i := 0 ; i < int (proofCount ); i ++ {
131
+ var hash utreexo.Hash
132
+ _ , err = io .ReadFull (r , hash [:])
124
133
if err != nil {
125
134
return nil , err
126
135
}
136
+ proofs = append (proofs , hash )
127
137
}
138
+ proof .Proof = proofs
128
139
129
- return & utreexo. Proof { Targets : targets , Proof : proofs } , nil
140
+ return proof , nil
130
141
}
131
142
132
143
// BatchProofToString converts a batchproof into a human-readable string. Note
0 commit comments