@@ -7,23 +7,23 @@ use jsonrpc_core::{BoxFuture, Error, Params, Value};
77use jsonrpc_pubsub:: { Subscriber , SubscriptionId } ;
88use serde:: { Deserialize , Serialize } ;
99use std:: {
10- collections:: { hash_map :: Entry , HashMap , HashSet } ,
10+ collections:: { HashMap , HashSet , hash_map :: Entry } ,
1111 convert:: TryFrom ,
1212 fmt:: Debug ,
1313 net:: SocketAddr ,
1414 path:: PathBuf ,
1515 str:: FromStr ,
1616 sync:: {
17- atomic:: { AtomicUsize , Ordering } ,
1817 Arc ,
18+ atomic:: { AtomicUsize , Ordering } ,
1919 } ,
2020} ;
2121
2222#[ cfg( test) ]
2323use self :: mock_actix:: SystemService ;
2424use crate :: {
2525 actors:: {
26- chain_manager:: { run_dr_locally , ChainManager , ChainManagerError } ,
26+ chain_manager:: { ChainManager , ChainManagerError , run_dr_locally } ,
2727 epoch_manager:: { EpochManager , EpochManagerError } ,
2828 inventory_manager:: { InventoryManager , InventoryManagerError } ,
2929 json_rpc:: Subscriptions ,
@@ -48,14 +48,14 @@ use crate::{
4848use witnet_crypto:: { hash:: calculate_sha256, key:: KeyPath } ;
4949use witnet_data_structures:: {
5050 chain:: {
51- tapi :: ActiveWips , Block , DataRequestInfo , DataRequestOutput , DataRequestStage , Epoch , EpochConstants ,
52- Hash , Hashable , KeyedSignature , PublicKeyHash , RADType , StakeOutput , StateMachine ,
53- SyncStatus , ValueTransferOutput ,
51+ Block , DataRequestInfo , DataRequestOutput , DataRequestStage , Epoch , EpochConstants , Hash ,
52+ Hashable , KeyedSignature , PublicKeyHash , RADType , StakeOutput , StateMachine , SyncStatus ,
53+ ValueTransferOutput , tapi :: ActiveWips ,
5454 } ,
5555 get_environment, get_protocol_version,
5656 proto:: {
57- versioning:: { ProtocolVersion , VersionedHashable } ,
5857 ProtobufConvert ,
58+ versioning:: { ProtocolVersion , VersionedHashable } ,
5959 } ,
6060 serialization_helpers:: number_from_string,
6161 staking:: prelude:: * ,
@@ -1579,18 +1579,15 @@ pub struct UtxoFilter {
15791579/// Get utxos
15801580pub async fn get_utxo_info ( params : Result < Params , Error > ) -> JsonRpcResult {
15811581 if let Params :: Array ( values) = params? {
1582- let mut values_iter = values. into_iter ( ) ;
15831582 // Try to read a first param that must be a String representing a bech32 address
1584- let pkh = values_iter . next ( ) . ok_or ( Error :: invalid_params (
1583+ let pkh = values . first ( ) . ok_or ( Error :: invalid_params (
15851584 "First argument must refer to a valid Bech32 address" ,
15861585 ) ) ?;
1587- let pkh: PublicKeyHash = Deserialize :: deserialize ( pkh) . map_err ( internal_error) ?;
1588- let filter: Option < UtxoFilter > = if values_iter. len ( ) > 0 {
1589- let filter = values_iter. next ( ) . ok_or ( Error :: invalid_params (
1590- "Cannot read the optional filter expected as second argument" ,
1591- ) ) ?;
1586+ let pkh = PublicKeyHash :: deserialize ( pkh) . map_err ( internal_error) ?;
15921587
1593- Deserialize :: deserialize ( filter) . ok ( )
1588+ // Try to read a second param. If present, we try to deserialize it as a UtxoFilter
1589+ let filter = if let Some ( value) = values. get ( 1 ) {
1590+ Some ( UtxoFilter :: deserialize ( value) . map_err ( internal_error) ?)
15941591 } else {
15951592 None
15961593 } ;
0 commit comments