@@ -70,15 +70,6 @@ impl Value {
7070 Value::Confidential(comm)
7171 }
7272
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-
8273 /// Create from commitment.
8374 pub fn from_commitment(bytes: &[u8]) -> Result<Self, encode::Error> {
8475 Ok(Value::Confidential(PedersenCommitment::from_slice(bytes)?))
@@ -145,13 +136,23 @@ impl Encodable for Value {
145136 Value::Confidential(commitment) => commitment.consensus_encode(&mut s),
146137 }
147138 }
139+
140+ fn encoded_length(&self) -> usize {
141+ match *self {
142+ Self::Null => 1,
143+ Self::Explicit(..) => 9,
144+ Self::Confidential(..) => 33,
145+ }
146+ }
148147}
149148
150149impl Encodable for PedersenCommitment {
151150 fn consensus_encode<W: io::Write>(&self, mut e: W) -> Result<usize, encode::Error> {
152151 e.write_all(&self.serialize())?;
153152 Ok(33)
154153 }
154+
155+ fn encoded_length(&self) -> usize { 33 }
155156}
156157
157158impl Decodable for Value {
@@ -272,15 +273,6 @@ impl Asset {
272273 ))
273274 }
274275
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-
284276 /// Create from commitment.
285277 pub fn from_commitment(bytes: &[u8]) -> Result<Self, encode::Error> {
286278 Ok(Asset::Confidential(Generator::from_slice(bytes)?))
@@ -367,13 +359,23 @@ impl Encodable for Asset {
367359 Asset::Confidential(generator) => generator.consensus_encode(&mut s)
368360 }
369361 }
362+
363+ fn encoded_length(&self) -> usize {
364+ match *self {
365+ Self::Null => 1,
366+ Self::Explicit(..) => 33,
367+ Self::Confidential(..) => 33,
368+ }
369+ }
370370}
371371
372372impl Encodable for Generator {
373373 fn consensus_encode<W: io::Write>(&self, mut e: W) -> Result<usize, encode::Error> {
374374 e.write_all(&self.serialize())?;
375375 Ok(33)
376376 }
377+
378+ fn encoded_length(&self) -> usize { 33 }
377379}
378380
379381impl Decodable for Asset {
@@ -537,15 +539,6 @@ impl Nonce {
537539 SecretKey::from_slice(&shared_secret[..32]).expect("always has exactly 32 bytes")
538540 }
539541
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-
549542 /// Create from commitment.
550543 pub fn from_commitment(bytes: &[u8]) -> Result<Self, encode::Error> {
551544 Ok(Nonce::Confidential(
@@ -619,13 +612,23 @@ impl Encodable for Nonce {
619612 Nonce::Confidential(commitment) => commitment.consensus_encode(&mut s),
620613 }
621614 }
615+
616+ fn encoded_length(&self) -> usize {
617+ match *self {
618+ Self::Null => 1,
619+ Self::Explicit(..) => 33,
620+ Self::Confidential(..) => 33,
621+ }
622+ }
622623}
623624
624625impl Encodable for PublicKey {
625626 fn consensus_encode<W: io::Write>(&self, mut e: W) -> Result<usize, encode::Error> {
626627 e.write_all(&self.serialize())?;
627628 Ok(33)
628629 }
630+
631+ fn encoded_length(&self) -> usize { 33 }
629632}
630633
631634impl Decodable for Nonce {
0 commit comments