-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client: first draft of system.multicall support
- Loading branch information
1 parent
5b12eb9
commit 24af6db
Showing
5 changed files
with
163 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,9 @@ pub use fault::*; | |
|
||
mod impls; | ||
|
||
mod multicall; | ||
pub use multicall::*; | ||
|
||
mod traits; | ||
pub use traits::*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::{DxrError, Member, Struct, TryToParams, TryToValue, Value}; | ||
|
||
/// Convenience method for constructing arguments for "system.multicall" calls. | ||
/// | ||
/// This method is more efficient than manually constructing the array of XML-RPC | ||
/// calls as structs (either by using a [`HashMap`] or by deriving [`TryToValue`] | ||
/// on a custom struct) because this method can rely on crate internals. | ||
pub fn multicall<P>(calls: Vec<(String, P)>) -> Result<Value, DxrError> | ||
where | ||
P: TryToParams, | ||
{ | ||
let params: Vec<Value> = calls | ||
.into_iter() | ||
.map(|(n, p)| { | ||
let members = vec![ | ||
Member::new(String::from("methodName"), Value::string(n)), | ||
Member::new(String::from("params"), p.try_to_params()?.try_to_value()?), | ||
]; | ||
Ok(Value::structure(Struct::new(members))) | ||
}) | ||
.collect::<Result<Vec<Value>, DxrError>>()?; | ||
|
||
params.try_to_value() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use quick_xml::{de::from_str, se::to_string}; | ||
|
||
use crate::values::{MethodCall, Value}; | ||
|
||
#[test] | ||
fn to_multicall() { | ||
let value = MethodCall::new(String::from("hello"), vec![]); | ||
let expected = "<methodCall><methodName>system.multicall</methodName></methodCall>"; | ||
|
||
assert_eq!(to_string(&value).unwrap(), expected); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters