@@ -104,22 +104,6 @@ macro_rules! impl_confidential_commitment {
104104 }
105105 }
106106
107- impl fmt:: Display for $name {
108- fn fmt( & self , f: & mut fmt:: Formatter ) -> fmt:: Result {
109- match * self {
110- $name:: Null => f. write_str( "null" ) ,
111- $name:: Explicit ( n) => write!( f, "{}" , n) ,
112- $name:: Confidential ( prefix, bytes) => {
113- write!( f, "{:02x}" , prefix) ?;
114- for b in bytes. iter( ) {
115- write!( f, "{:02x}" , b) ?;
116- }
117- Ok ( ( ) )
118- }
119- }
120- }
121- }
122-
123107 impl Encodable for $name {
124108 fn consensus_encode<S : io:: Write >( & self , mut s: S ) -> Result <usize , encode:: Error > {
125109 match * self {
@@ -253,6 +237,22 @@ impl Value {
253237 }
254238}
255239
240+ impl fmt:: Display for Value {
241+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
242+ match * self {
243+ Value :: Null => f. write_str ( "null" ) ,
244+ Value :: Explicit ( n) => write ! ( f, "{}" , n) ,
245+ Value :: Confidential ( prefix, bytes) => {
246+ write ! ( f, "{:02x}" , prefix) ?;
247+ for b in bytes. iter ( ) {
248+ write ! ( f, "{:02x}" , b) ?;
249+ }
250+ Ok ( ( ) )
251+ }
252+ }
253+ }
254+ }
255+
256256/// A CT commitment to an asset
257257#[ derive( Copy , Clone , Debug , Eq , Hash , PartialEq , PartialOrd , Ord ) ]
258258pub enum Asset {
@@ -276,6 +276,21 @@ impl Asset {
276276 }
277277}
278278
279+ impl fmt:: Display for Asset {
280+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
281+ match * self {
282+ Asset :: Null => f. write_str ( "null" ) ,
283+ Asset :: Explicit ( n) => write ! ( f, "{}" , n) ,
284+ Asset :: Confidential ( prefix, bytes) => {
285+ write ! ( f, "{:02x}" , prefix) ?;
286+ for b in bytes. iter ( ) {
287+ write ! ( f, "{:02x}" , b) ?;
288+ }
289+ Ok ( ( ) )
290+ }
291+ }
292+ }
293+ }
279294
280295/// A CT commitment to an output nonce (i.e. a public key)
281296#[ derive( Copy , Clone , Debug , Eq , Hash , PartialEq , PartialOrd , Ord ) ]
@@ -285,11 +300,11 @@ pub enum Nonce {
285300 /// There should be no such thing as an "explicit nonce", but Elements will deserialize
286301 /// such a thing (and insists that its size be 32 bytes). So we stick a 32-byte type here
287302 /// that implements all the traits we need.
288- Explicit ( sha256d :: Hash ) ,
303+ Explicit ( [ u8 ; 32 ] ) ,
289304 /// Nonce is committed
290305 Confidential ( u8 , [ u8 ; 32 ] ) ,
291306}
292- impl_confidential_commitment ! ( Nonce , sha256d :: Hash , 0x02 , 0x03 ) ;
307+ impl_confidential_commitment ! ( Nonce , [ u8 ; 32 ] , 0x02 , 0x03 ) ;
293308
294309impl Nonce {
295310 /// Serialized length, in bytes
@@ -302,9 +317,30 @@ impl Nonce {
302317 }
303318}
304319
320+ impl fmt:: Display for Nonce {
321+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
322+ match * self {
323+ Nonce :: Null => f. write_str ( "null" ) ,
324+ Nonce :: Explicit ( n) => {
325+ for b in n. iter ( ) {
326+ write ! ( f, "{:02x}" , b) ?;
327+ }
328+ Ok ( ( ) )
329+ } ,
330+ Nonce :: Confidential ( prefix, bytes) => {
331+ write ! ( f, "{:02x}" , prefix) ?;
332+ for b in bytes. iter ( ) {
333+ write ! ( f, "{:02x}" , b) ?;
334+ }
335+ Ok ( ( ) )
336+ }
337+ }
338+ }
339+ }
340+
305341#[ cfg( test) ]
306342mod tests {
307- use bitcoin:: hashes:: { Hash , sha256} ;
343+ use bitcoin:: hashes:: sha256;
308344 use super :: * ;
309345
310346 #[ test]
@@ -322,7 +358,7 @@ mod tests {
322358
323359 let nonces = [
324360 Nonce :: Null ,
325- Nonce :: Explicit ( sha256d :: Hash :: from_inner ( [ 0 ; 32 ] ) ) ,
361+ Nonce :: Explicit ( [ 0 ; 32 ] ) ,
326362 Nonce :: Confidential ( 0x02 , [ 1 ; 32 ] ) ,
327363 ] ;
328364 for v in & nonces[ ..] {
0 commit comments