Skip to content

Commit a4ba74e

Browse files
dvdplmascjones
andauthored
Document the Call derive macro (paritytech#137)
* Document the `Call` derive macro * Obey the fmt * Update proc-macro/src/lib.rs Co-authored-by: Andrew Jones <ascjones@gmail.com> * Review feedback Co-authored-by: Andrew Jones <ascjones@gmail.com>
1 parent 536c54c commit a4ba74e

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

examples/submit_and_watch.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
use sp_keyring::AccountKeyring;
1818
use substrate_subxt::{
19-
balances::*,
19+
balances::{
20+
TransferCallExt,
21+
TransferEventExt,
22+
},
2023
ClientBuilder,
2124
DefaultNodeRuntime,
2225
PairSigner,

proc-macro/src/lib.rs

+47-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,53 @@ pub fn module(args: TokenStream, input: TokenStream) -> TokenStream {
8888
module::module(args.into(), input.into()).into()
8989
}
9090

91-
decl_derive!([Call] => #[proc_macro_error] call);
91+
decl_derive!(
92+
[Call] =>
93+
/// Derive macro that implements [substrate_subxt::Call](../substrate_subxt/trait.Call.html) for your struct
94+
/// and defines&implements the calls as an extension trait.
95+
///
96+
/// Use the `Call` derive macro in tandem with the [#module](../substrate_subxt/attr.module.html) macro to extend
97+
/// your struct to enable calls to substrate and to decode events. The struct maps to the corresponding Substrate runtime call, e.g.:
98+
///
99+
/// ```ignore
100+
/// decl_module! {
101+
/// /* … */
102+
/// pub fn fun_stuff(origin, something: Vec<u8>) -> DispatchResult { /* … */ }
103+
/// /* … */
104+
/// }
105+
///```
106+
///
107+
/// Implements [substrate_subxt::Call](../substrate_subxt/trait.Call.html) and adds an extension trait that
108+
/// provides two methods named as your struct.
109+
///
110+
/// Example:
111+
/// ```rust,ignore
112+
/// pub struct MyRuntime;
113+
///
114+
/// impl System for MyRuntime { /* … */ }
115+
/// impl Balances for MyRuntime { /* … */ }
116+
///
117+
/// #[module]
118+
/// pub trait MyTrait: System + Balances {}
119+
///
120+
/// #[derive(Call)]
121+
/// pub struct FunStuffCall<T: MyTrait> {
122+
/// /// Runtime marker.
123+
/// pub _runtime: PhantomData<T>,
124+
/// /// The argument passed to the call..
125+
/// pub something: Vec<u8>,
126+
/// }
127+
/// ```
128+
///
129+
/// When building a [Client](../substrate_subxt/struct.Client.html) parameterised to `MyRuntime`, you have access to
130+
/// two new methods: `fun_stuff()` and `fun_stuff_and_watch()` by way of the derived `FunStuffExt`
131+
/// trait. The `_and_watch` variant makes the call and waits for the result. The fields of the
132+
/// input struct become arguments to the calls (ignoring the marker field).
133+
///
134+
/// Under the hood the implementation calls [submit()](../substrate_subxt/struct.Client.html#method.submit) and
135+
/// [watch()](../substrate_subxt/struct.Client.html#method.watch) respectively.
136+
#[proc_macro_error] call
137+
);
92138
fn call(s: Structure) -> TokenStream {
93139
call::call(s).into()
94140
}

0 commit comments

Comments
 (0)