55use core:: { fmt, str} ;
66use std:: io;
77
8- use secp256k1_zkp:: { self , Generator , Secp256k1 , Signing , Tweak , ZERO_TWEAK } ;
98use secp256k1_zkp:: rand:: Rng ;
9+ use secp256k1_zkp:: { self , Generator , Secp256k1 , Signing , Tweak , ZERO_TWEAK } ;
1010#[ cfg( feature = "serde" ) ]
1111use serde:: { Deserialize , Deserializer , Serialize , Serializer } ;
1212
@@ -32,11 +32,7 @@ impl Asset {
3232 asset : AssetId ,
3333 bf : AssetBlindingFactor ,
3434 ) -> Self {
35- Asset :: Confidential ( Generator :: new_blinded (
36- secp,
37- asset. into_tag ( ) ,
38- bf. into_inner ( ) ,
39- ) )
35+ Asset :: Confidential ( Generator :: new_blinded ( secp, asset. into_tag ( ) , bf. into_inner ( ) ) )
4036 }
4137
4238 /// Serialized length, in bytes
@@ -54,19 +50,13 @@ impl Asset {
5450 }
5551
5652 /// Check if the object is null.
57- pub fn is_null ( & self ) -> bool {
58- matches ! ( * self , Asset :: Null )
59- }
53+ pub fn is_null ( & self ) -> bool { matches ! ( * self , Asset :: Null ) }
6054
6155 /// Check if the object is explicit.
62- pub fn is_explicit ( & self ) -> bool {
63- matches ! ( * self , Asset :: Explicit ( _) )
64- }
56+ pub fn is_explicit ( & self ) -> bool { matches ! ( * self , Asset :: Explicit ( _) ) }
6557
6658 /// Check if the object is confidential.
67- pub fn is_confidential ( & self ) -> bool {
68- matches ! ( * self , Asset :: Confidential ( _) )
69- }
59+ pub fn is_confidential ( & self ) -> bool { matches ! ( * self , Asset :: Confidential ( _) ) }
7060
7161 /// Returns the explicit inner value.
7262 /// Returns [None] if [`Asset::is_explicit`] returns false.
@@ -91,26 +81,22 @@ impl Asset {
9181 /// Returns [`None`] is the asset is [`Asset::Null`]
9282 /// Converts a explicit asset into a generator and returns the confidential
9383 /// generator as is.
94- pub fn into_asset_gen < C : secp256k1_zkp:: Signing > (
84+ pub fn into_asset_gen < C : secp256k1_zkp:: Signing > (
9585 self ,
9686 secp : & Secp256k1 < C > ,
9787 ) -> Option < Generator > {
9888 match self {
9989 // Only error is Null error which is dealt with later
10090 // when we have more context information about it.
10191 Asset :: Null => None ,
102- Asset :: Explicit ( x) => {
103- Some ( Generator :: new_unblinded ( secp, x. into_tag ( ) ) )
104- }
92+ Asset :: Explicit ( x) => Some ( Generator :: new_unblinded ( secp, x. into_tag ( ) ) ) ,
10593 Asset :: Confidential ( gen) => Some ( gen) ,
10694 }
10795 }
10896}
10997
11098impl From < Generator > for Asset {
111- fn from ( from : Generator ) -> Self {
112- Asset :: Confidential ( from)
113- }
99+ fn from ( from : Generator ) -> Self { Asset :: Confidential ( from) }
114100}
115101
116102impl fmt:: Display for Asset {
@@ -167,7 +153,7 @@ impl Serialize for Asset {
167153
168154 let seq_len = match * self {
169155 Asset :: Null => 1 ,
170- Asset :: Explicit ( _) | Asset :: Confidential ( _) => 2
156+ Asset :: Explicit ( _) | Asset :: Confidential ( _) => 2 ,
171157 } ;
172158 let mut seq = s. serialize_seq ( Some ( seq_len) ) ?;
173159
@@ -203,18 +189,14 @@ impl<'de> Deserialize<'de> for Asset {
203189 let prefix = access. next_element :: < u8 > ( ) ?;
204190 match prefix {
205191 Some ( 0 ) => Ok ( Asset :: Null ) ,
206- Some ( 1 ) => {
207- match access. next_element ( ) ? {
208- Some ( x) => Ok ( Asset :: Explicit ( x) ) ,
209- None => Err ( A :: Error :: custom ( "missing explicit asset" ) ) ,
210- }
211- }
212- Some ( 2 ) => {
213- match access. next_element ( ) ? {
214- Some ( x) => Ok ( Asset :: Confidential ( x) ) ,
215- None => Err ( A :: Error :: custom ( "missing generator" ) ) ,
216- }
217- }
192+ Some ( 1 ) => match access. next_element ( ) ? {
193+ Some ( x) => Ok ( Asset :: Explicit ( x) ) ,
194+ None => Err ( A :: Error :: custom ( "missing explicit asset" ) ) ,
195+ } ,
196+ Some ( 2 ) => match access. next_element ( ) ? {
197+ Some ( x) => Ok ( Asset :: Confidential ( x) ) ,
198+ None => Err ( A :: Error :: custom ( "missing generator" ) ) ,
199+ } ,
218200 _ => Err ( A :: Error :: custom ( "wrong or missing prefix" ) ) ,
219201 }
220202 }
@@ -224,22 +206,17 @@ impl<'de> Deserialize<'de> for Asset {
224206 }
225207}
226208
227-
228209/// Blinding factor used for asset commitments.
229210#[ derive( Copy , Clone , Eq , PartialEq , PartialOrd , Ord , Hash ) ]
230211pub struct AssetBlindingFactor ( pub ( crate ) Tweak ) ;
231212
232213impl AssetBlindingFactor {
233214 /// Generate random asset blinding factor.
234- pub fn new < R : Rng > ( rng : & mut R ) -> Self {
235- AssetBlindingFactor ( Tweak :: new ( rng) )
236- }
215+ pub fn new < R : Rng > ( rng : & mut R ) -> Self { AssetBlindingFactor ( Tweak :: new ( rng) ) }
237216
238217 /// Parse a blinding factor from a 64-character hex string.
239218 #[ deprecated( since = "0.27.0" , note = "use s.parse() instead" ) ]
240- pub fn from_hex ( s : & str ) -> Result < Self , encode:: Error > {
241- s. parse ( )
242- }
219+ pub fn from_hex ( s : & str ) -> Result < Self , encode:: Error > { s. parse ( ) }
243220
244221 /// Create from bytes.
245222 pub fn from_byte_array ( bytes : [ u8 ; 32 ] ) -> Result < Self , secp256k1_zkp:: Error > {
@@ -252,14 +229,10 @@ impl AssetBlindingFactor {
252229 }
253230
254231 /// Returns the inner value.
255- pub fn into_inner ( self ) -> Tweak {
256- self . 0
257- }
232+ pub fn into_inner ( self ) -> Tweak { self . 0 }
258233
259234 /// Get a unblinded/zero `AssetBlinding` factor
260- pub fn zero ( ) -> Self {
261- AssetBlindingFactor ( ZERO_TWEAK )
262- }
235+ pub fn zero ( ) -> Self { AssetBlindingFactor ( ZERO_TWEAK ) }
263236}
264237
265238impl core:: borrow:: Borrow < [ u8 ] > for AssetBlindingFactor {
@@ -359,4 +332,3 @@ impl<'de> Deserialize<'de> for AssetBlindingFactor {
359332 }
360333 }
361334}
362-
0 commit comments