@@ -70,15 +70,6 @@ impl Value {
70
70
Value :: Confidential ( comm)
71
71
}
72
72
73
- /// Serialized length, in bytes
74
- pub fn encoded_length ( & self ) -> usize {
75
- match * self {
76
- Value :: Null => 1 ,
77
- Value :: Explicit ( ..) => 9 ,
78
- Value :: Confidential ( ..) => 33 ,
79
- }
80
- }
81
-
82
73
/// Create from commitment.
83
74
pub fn from_commitment ( bytes : & [ u8 ] ) -> Result < Self , encode:: Error > {
84
75
Ok ( Value :: Confidential ( PedersenCommitment :: from_slice ( bytes) ?) )
@@ -145,13 +136,23 @@ impl Encodable for Value {
145
136
Value :: Confidential ( commitment) => commitment. consensus_encode ( & mut s) ,
146
137
}
147
138
}
139
+
140
+ fn encoded_length ( & self ) -> usize {
141
+ match * self {
142
+ Self :: Null => 1 ,
143
+ Self :: Explicit ( ..) => 9 ,
144
+ Self :: Confidential ( ..) => 33 ,
145
+ }
146
+ }
148
147
}
149
148
150
149
impl Encodable for PedersenCommitment {
151
150
fn consensus_encode < W : io:: Write > ( & self , mut e : W ) -> Result < usize , encode:: Error > {
152
151
e. write_all ( & self . serialize ( ) ) ?;
153
152
Ok ( 33 )
154
153
}
154
+
155
+ fn encoded_length ( & self ) -> usize { 33 }
155
156
}
156
157
157
158
impl Decodable for Value {
@@ -272,15 +273,6 @@ impl Asset {
272
273
) )
273
274
}
274
275
275
- /// Serialized length, in bytes
276
- pub fn encoded_length ( & self ) -> usize {
277
- match * self {
278
- Asset :: Null => 1 ,
279
- Asset :: Explicit ( ..) => 33 ,
280
- Asset :: Confidential ( ..) => 33 ,
281
- }
282
- }
283
-
284
276
/// Create from commitment.
285
277
pub fn from_commitment ( bytes : & [ u8 ] ) -> Result < Self , encode:: Error > {
286
278
Ok ( Asset :: Confidential ( Generator :: from_slice ( bytes) ?) )
@@ -367,13 +359,23 @@ impl Encodable for Asset {
367
359
Asset :: Confidential ( generator) => generator. consensus_encode ( & mut s)
368
360
}
369
361
}
362
+
363
+ fn encoded_length ( & self ) -> usize {
364
+ match * self {
365
+ Self :: Null => 1 ,
366
+ Self :: Explicit ( ..) => 33 ,
367
+ Self :: Confidential ( ..) => 33 ,
368
+ }
369
+ }
370
370
}
371
371
372
372
impl Encodable for Generator {
373
373
fn consensus_encode < W : io:: Write > ( & self , mut e : W ) -> Result < usize , encode:: Error > {
374
374
e. write_all ( & self . serialize ( ) ) ?;
375
375
Ok ( 33 )
376
376
}
377
+
378
+ fn encoded_length ( & self ) -> usize { 33 }
377
379
}
378
380
379
381
impl Decodable for Asset {
@@ -537,15 +539,6 @@ impl Nonce {
537
539
SecretKey :: from_slice ( & shared_secret[ ..32 ] ) . expect ( "always has exactly 32 bytes" )
538
540
}
539
541
540
- /// Serialized length, in bytes
541
- pub fn encoded_length ( & self ) -> usize {
542
- match * self {
543
- Nonce :: Null => 1 ,
544
- Nonce :: Explicit ( ..) => 33 ,
545
- Nonce :: Confidential ( ..) => 33 ,
546
- }
547
- }
548
-
549
542
/// Create from commitment.
550
543
pub fn from_commitment ( bytes : & [ u8 ] ) -> Result < Self , encode:: Error > {
551
544
Ok ( Nonce :: Confidential (
@@ -619,13 +612,23 @@ impl Encodable for Nonce {
619
612
Nonce :: Confidential ( commitment) => commitment. consensus_encode ( & mut s) ,
620
613
}
621
614
}
615
+
616
+ fn encoded_length ( & self ) -> usize {
617
+ match * self {
618
+ Self :: Null => 1 ,
619
+ Self :: Explicit ( ..) => 33 ,
620
+ Self :: Confidential ( ..) => 33 ,
621
+ }
622
+ }
622
623
}
623
624
624
625
impl Encodable for PublicKey {
625
626
fn consensus_encode < W : io:: Write > ( & self , mut e : W ) -> Result < usize , encode:: Error > {
626
627
e. write_all ( & self . serialize ( ) ) ?;
627
628
Ok ( 33 )
628
629
}
630
+
631
+ fn encoded_length ( & self ) -> usize { 33 }
629
632
}
630
633
631
634
impl Decodable for Nonce {
0 commit comments