@@ -4,10 +4,7 @@ use anyhow::Result;
44use async_trait:: async_trait;
55use bhwi_async:: {
66 HttpClient , Jade , Transport ,
7- transport:: jade:: {
8- JADE_DEVICE_IDS ,
9- tcp:: { TcpClient as TcpClientTrait , TcpTransport } ,
10- } ,
7+ transport:: jade:: { CborStream , JADE_DEVICE_IDS , tcp:: TcpTransport } ,
118} ;
129use bitcoin:: Network ;
1310use futures:: { TryStreamExt , stream:: iter} ;
@@ -51,11 +48,20 @@ impl SerialTransport {
5148impl Transport for SerialTransport {
5249 type Error = std:: io:: Error ;
5350 async fn exchange ( & mut self , command : & [ u8 ] , _encrypted : bool ) -> Result < Vec < u8 > , Self :: Error > {
51+ self . write_all ( command) . await ?;
52+ self . read_cbor_message ( ) . await
53+ }
54+ }
55+
56+ #[ async_trait( ?Send ) ]
57+ impl CborStream for SerialTransport {
58+ async fn write_all ( & mut self , command : & [ u8 ] ) -> Result < ( ) , std:: io:: Error > {
59+ let mut stream = self . stream . lock ( ) . await ;
60+ Ok ( stream. write_all ( command) . await ?)
61+ }
62+ async fn read ( & mut self , buf : & mut [ u8 ] ) -> Result < usize , std:: io:: Error > {
5463 let mut stream = self . stream . lock ( ) . await ;
55- stream. write_all ( command) . await ?;
56- let mut buf = vec ! [ ] ;
57- stream. read_to_end ( & mut buf) . await ?;
58- Ok ( buf)
64+ Ok ( stream. read ( buf) . await ?)
5965 }
6066}
6167
@@ -153,7 +159,7 @@ impl HttpClient for PinServerClient {
153159 Ok ( self
154160 . inner
155161 . post ( url)
156- . header ( "Content-Type" , "application/octet-stream " )
162+ . header ( "Content-Type" , "application/json " )
157163 . body ( request. to_vec ( ) )
158164 . send ( )
159165 . await ?
@@ -174,7 +180,7 @@ impl TcpClient {
174180}
175181
176182#[ async_trait( ?Send ) ]
177- impl TcpClientTrait for TcpClient {
183+ impl CborStream for TcpClient {
178184 async fn write_all ( & mut self , command : & [ u8 ] ) -> Result < ( ) , std:: io:: Error > {
179185 Ok ( self . stream . write_all ( command) . await ?)
180186 }
0 commit comments