1919// or implied. See the License for the specific language governing permissions and limitations under
2020// the License.
2121
22- use std:: io:: { Read , Write } ;
22+ use std:: io:: { ErrorKind , Read , Write } ;
2323
2424use amplify:: confinement:: { SmallBlob , TinyBlob } ;
2525use bpstd:: { DescrId , Network } ;
@@ -30,7 +30,6 @@ use sonicapi::{CodexId, ContractId};
3030use crate :: CiboriumError ;
3131
3232#[ derive( Clone , Debug , Display ) ]
33- #[ display( UPPERCASE ) ]
3433#[ derive( Serialize , Deserialize ) ]
3534pub enum RgbRpcReq {
3635 #[ display( "HELLO({0})" ) ]
@@ -39,8 +38,10 @@ pub enum RgbRpcReq {
3938 #[ display( "PING" ) ]
4039 Ping ( TinyBlob ) ,
4140
41+ #[ display( "STATUS" ) ]
4242 Status ,
4343
44+ #[ display( "WALLETS" ) ]
4445 Wallets ,
4546
4647 #[ display( "WALLET({0})" ) ]
@@ -52,8 +53,10 @@ pub enum RgbRpcReq {
5253 #[ display( "DELETE({0})" ) ]
5354 Delete ( DescrId ) ,
5455
56+ #[ display( "ISSUERS" ) ]
5557 Issuers ,
5658
59+ #[ display( "CONTRACTS" ) ]
5760 Contracts ,
5861
5962 #[ display( "ISSUER({0})" ) ]
@@ -83,11 +86,43 @@ impl Frame for RgbRpcReq {
8386 type Error = CiboriumError ;
8487
8588 fn unmarshall ( reader : impl Read ) -> Result < Option < Self > , Self :: Error > {
86- ciborium:: from_reader ( reader) . map_err ( CiboriumError :: from)
89+ match ciborium:: from_reader ( reader) {
90+ Ok ( msg) => Ok ( Some ( msg) ) ,
91+ Err ( ciborium:: de:: Error :: Io ( e) ) if e. kind ( ) == ErrorKind :: UnexpectedEof => Ok ( None ) ,
92+ Err ( e) => Err ( CiboriumError :: from ( e) ) ,
93+ }
8794 }
8895
8996 fn marshall ( & self , writer : impl Write ) -> Result < ( ) , Self :: Error > {
9097 ciborium:: into_writer ( self , writer) ?;
9198 Ok ( ( ) )
9299 }
93100}
101+
102+ #[ cfg( test) ]
103+ mod tests {
104+ use std:: io:: Cursor ;
105+
106+ use super :: * ;
107+
108+ #[ test]
109+ fn serialization ( ) {
110+ let mut buf = Vec :: new ( ) ;
111+ RgbRpcReq :: Wallets . marshall ( & mut buf) . unwrap ( ) ;
112+ assert_eq ! ( buf, * b"\x67 Wallets" ) ;
113+ let deser = RgbRpcReq :: unmarshall ( & mut buf. as_slice ( ) ) . unwrap ( ) . unwrap ( ) ;
114+ assert ! ( matches!( deser, RgbRpcReq :: Wallets ) ) ;
115+ }
116+
117+ #[ test]
118+ fn stream_serialization ( ) {
119+ let mut buf = Vec :: new ( ) ;
120+ RgbRpcReq :: Wallets . marshall ( & mut buf) . unwrap ( ) ;
121+ assert_eq ! ( buf, * b"\x67 Wallets" ) ;
122+ let mut cursor = Cursor :: new ( & mut buf) ;
123+ let deser = RgbRpcReq :: unmarshall ( & mut cursor) . unwrap ( ) . unwrap ( ) ;
124+ assert ! ( matches!( deser, RgbRpcReq :: Wallets ) ) ;
125+ let nothing = RgbRpcReq :: unmarshall ( & mut cursor) . unwrap ( ) ;
126+ assert ! ( matches!( nothing, None ) ) ;
127+ }
128+ }
0 commit comments