@@ -8,17 +8,9 @@ use ureq::{Agent, AgentBuilder, Error, Response};
8
8
9
9
use crate :: {
10
10
rpc_abi:: {
11
- RpcBroadcastTxRequest , RpcBroadcastTxResponse , RpcCreateTxRequest , RpcCreateTxResponse ,
12
- RpcExportAccountResponse , RpcGetAccountStatusRequest , RpcGetAccountStatusResponse ,
13
- RpcGetAccountTransactionRequest , RpcGetAccountTransactionResponse , RpcGetBalancesRequest ,
14
- RpcGetBalancesResponse , RpcGetBlockRequest , RpcGetBlockResponse , RpcGetBlocksRequest ,
15
- RpcGetBlocksResponse , RpcGetLatestBlockResponse , RpcGetTransactionsRequest ,
16
- RpcGetTransactionsResponse , RpcImportAccountRequest , RpcImportAccountResponse ,
17
- RpcRemoveAccountRequest , RpcRemoveAccountResponse , RpcResetAccountRequest , RpcResponse ,
18
- RpcSetAccountHeadRequest , RpcSetScanningRequest , SendTransactionRequest ,
19
- SendTransactionResponse ,
11
+ RpcBroadcastTxRequest , RpcBroadcastTxResponse , RpcCreateTxRequest , RpcCreateTxResponse , RpcExportAccountResponse , RpcGetAccountStatusRequest , RpcGetAccountStatusResponse , RpcGetAccountTransactionRequest , RpcGetAccountTransactionResponse , RpcGetBalancesRequest , RpcGetBalancesResponse , RpcGetBlockRequest , RpcGetBlockResponse , RpcGetBlocksRequest , RpcGetBlocksResponse , RpcGetLatestBlockResponse , RpcGetTransactionsRequest , RpcGetTransactionsResponse , RpcImportAccountRequest , RpcImportAccountResponse , RpcRemoveAccountRequest , RpcRemoveAccountResponse , RpcResetAccountRequest , RpcResponse , RpcSetAccountHeadRequest , RpcSetScanningRequest , SendTransactionRequest , SendTransactionResponse
20
12
} ,
21
- rpc_handler:: RpcError ,
13
+ rpc_handler:: RpcError , stream :: RequestExt ,
22
14
} ;
23
15
24
16
#[ derive( Debug , Clone ) ]
@@ -137,32 +129,24 @@ impl RpcHandler {
137
129
let resp = self . agent . clone ( ) . post ( & path) . send_json ( & request) ;
138
130
handle_response ( resp)
139
131
}
140
-
132
+
141
133
pub fn get_transactions (
142
134
& self ,
143
135
request : RpcGetTransactionsRequest ,
144
136
) -> Result < RpcResponse < RpcGetTransactionsResponse > , OreoError > {
145
137
let path = format ! ( "http://{}/wallet/getAccountTransactions" , self . endpoint) ;
146
138
let resp = self . agent . clone ( ) . post ( & path) . send_json ( & request) ;
147
-
148
139
match resp {
149
140
Ok ( response) => {
150
- let mut buffer = Vec :: new ( ) ;
151
- response. into_reader ( ) . read_to_end ( & mut buffer) . map_err ( |e| OreoError :: InternalRpcError ( e. to_string ( ) ) ) ?;
152
- let transactions_response: RpcResponse < RpcGetTransactionsResponse > = if buffer. is_empty ( ) {
153
- RpcResponse {
154
- data : RpcGetTransactionsResponse {
155
- transactions : Vec :: new ( ) ,
156
- } ,
157
- status : 200 ,
158
- }
159
- } else {
160
- serde_json:: from_slice ( & buffer)
161
- . map_err ( |e| OreoError :: InternalRpcError ( e. to_string ( ) ) ) ?
162
- } ;
163
- Ok ( transactions_response)
164
- }
165
- Err ( e) => handle_response ( Err ( e) ) ,
141
+ let transactions = response. collect_stream ( ) ;
142
+ Ok ( RpcResponse {
143
+ status : 200 ,
144
+ data : RpcGetTransactionsResponse {
145
+ transactions : transactions?,
146
+ } ,
147
+ } )
148
+ } ,
149
+ Err ( e) => Err ( OreoError :: InternalRpcError ( e. to_string ( ) ) ) ,
166
150
}
167
151
}
168
152
0 commit comments