@@ -27,32 +27,39 @@ impl ZcashDeserialize for AssetBase {
2727 }
2828}
2929
30- // FIXME: use NoteValue instead of Amount, remove both TryFrom<...> after that
31- /// Represents an OrchardZSA burn item.
32- #[ derive( Clone , Debug , PartialEq , Eq ) ]
33- pub struct BurnItem ( AssetBase , Amount ) ;
30+ // FIXME: Define BurnItem (or, even Burn/NoBurn) in Orchard and reuse it here?
31+ /// Orchard ZSA burn item.
32+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
33+ pub struct BurnItem ( AssetBase , NoteValue ) ;
34+
35+ impl BurnItem {
36+ /// Returns [`AssetBase`] being burned.
37+ pub fn asset ( & self ) -> AssetBase {
38+ self . 0
39+ }
3440
35- // Convert from burn item type used in `orchard` crate
36- impl TryFrom < ( AssetBase , NoteValue ) > for BurnItem {
37- type Error = crate :: amount:: Error ;
41+ /// Returns the amount being burned.
42+ pub fn amount ( & self ) -> NoteValue {
43+ self . 1
44+ }
3845
39- fn try_from ( item : ( AssetBase , NoteValue ) ) -> Result < Self , Self :: Error > {
40- Ok ( Self ( item. 0 , item. 1 . inner ( ) . try_into ( ) ?) )
46+ /// Returns the raw [`u64`] amount being burned.
47+ pub fn raw_amount ( & self ) -> u64 {
48+ self . 1 . inner ( )
4149 }
4250}
4351
44- impl TryFrom < BurnItem > for ( AssetBase , NoteValue ) {
45- type Error = std:: io:: Error ;
52+ // Convert from burn item type used in `orchard` crate
53+ impl From < ( AssetBase , NoteValue ) > for BurnItem {
54+ fn from ( item : ( AssetBase , NoteValue ) ) -> Self {
55+ Self ( item. 0 , item. 1 )
56+ }
57+ }
4658
47- fn try_from ( item : BurnItem ) -> Result < Self , Self :: Error > {
48- Ok ( (
49- item. 0 ,
50- NoteValue :: from_raw (
51- i64:: from ( item. 1 )
52- . try_into ( )
53- . map_err ( |_| std:: io:: Error :: from ( std:: io:: ErrorKind :: InvalidData ) ) ?,
54- ) ,
55- ) )
59+ // Convert to burn item type used in `orchard` crate
60+ impl From < BurnItem > for ( AssetBase , NoteValue ) {
61+ fn from ( item : BurnItem ) -> Self {
62+ ( item. 0 , item. 1 )
5663 }
5764}
5865
@@ -61,7 +68,7 @@ impl serde::Serialize for BurnItem {
6168 where
6269 S : serde:: Serializer ,
6370 {
64- ( self . 0 . to_bytes ( ) , & self . 1 ) . serialize ( serializer)
71+ ( self . 0 . to_bytes ( ) , & self . 1 . inner ( ) ) . serialize ( serializer)
6572 }
6673}
6774
@@ -70,11 +77,12 @@ impl<'de> serde::Deserialize<'de> for BurnItem {
7077 where
7178 D : serde:: Deserializer < ' de > ,
7279 {
73- let ( asset_base_bytes, amount) = <( [ u8 ; 32 ] , Amount ) >:: deserialize ( deserializer) ?;
80+ let ( asset_base_bytes, amount) = <( [ u8 ; 32 ] , u64 ) >:: deserialize ( deserializer) ?;
7481 Ok ( BurnItem (
82+ // FIXME: duplicates the body of AssetBase::zcash_deserialize?
7583 Option :: from ( AssetBase :: from_bytes ( & asset_base_bytes) )
7684 . ok_or_else ( || serde:: de:: Error :: custom ( "Invalid orchard_zsa AssetBase" ) ) ?,
77- amount,
85+ NoteValue :: from_raw ( amount) ,
7886 ) )
7987 }
8088}
@@ -142,11 +150,7 @@ impl ZcashSerialize for Burn {
142150 fn zcash_serialize < W : io:: Write > ( & self , mut writer : W ) -> Result < ( ) , io:: Error > {
143151 write_burn (
144152 & mut writer,
145- & self
146- . 0
147- . iter ( )
148- . map ( |item| item. clone ( ) . try_into ( ) )
149- . collect :: < Result < Vec < _ > , _ > > ( ) ?,
153+ & self . 0 . iter ( ) . map ( |item| ( * item) . into ( ) ) . collect :: < Vec < _ > > ( ) ,
150154 )
151155 }
152156}
@@ -156,8 +160,8 @@ impl ZcashDeserialize for Burn {
156160 Ok ( Burn (
157161 read_burn ( & mut reader) ?
158162 . into_iter ( )
159- . map ( |item| item. try_into ( ) )
160- . collect :: < Result < Vec < _ > , _ > > ( ) ? ,
163+ . map ( |item| item. into ( ) )
164+ . collect ( ) ,
161165 ) )
162166 }
163167}
0 commit comments