Skip to content

Commit 4ee7fb1

Browse files
authored
Support unsigned extrinsics. (#130)
1 parent 5fd83f8 commit 4ee7fb1

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

src/lib.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,10 @@ impl<T: Runtime> Client<T> {
308308
.and_then(|module| module.call(C::FUNCTION, call))?)
309309
}
310310

311-
/// Creates an unsigned extrinsic.
311+
/// Creates an payload for an extrinsic.
312312
///
313313
/// If `nonce` is `None` the nonce will be fetched from the chain.
314-
pub async fn create_unsigned<C: Call<T>>(
314+
pub async fn create_payload<C: Call<T>>(
315315
&self,
316316
call: C,
317317
account_id: &<T as System>::AccountId,
@@ -336,6 +336,23 @@ impl<T: Runtime> Client<T> {
336336
Ok(raw_payload)
337337
}
338338

339+
/// Creates an unsigned extrinsic.
340+
pub async fn create_unsigned<C: Call<T> + Send + Sync>(
341+
&self,
342+
call: C,
343+
account_id: &<T as System>::AccountId,
344+
nonce: Option<T::Index>,
345+
) -> Result<UncheckedExtrinsic<T>, Error>
346+
where
347+
<<T::Extra as SignedExtra<T>>::Extra as SignedExtension>::AdditionalSigned:
348+
Send + Sync,
349+
{
350+
let payload = self.create_payload(call, account_id, nonce).await?;
351+
let (call, _, _) = payload.deconstruct();
352+
let unsigned = UncheckedExtrinsic::<T>::new_unsigned(call);
353+
Ok(unsigned)
354+
}
355+
339356
/// Creates a signed extrinsic.
340357
pub async fn create_signed<C: Call<T> + Send + Sync>(
341358
&self,
@@ -346,10 +363,10 @@ impl<T: Runtime> Client<T> {
346363
<<T::Extra as SignedExtra<T>>::Extra as SignedExtension>::AdditionalSigned:
347364
Send + Sync,
348365
{
349-
let unsigned = self
350-
.create_unsigned(call, signer.account_id(), signer.nonce())
366+
let payload = self
367+
.create_payload(call, signer.account_id(), signer.nonce())
351368
.await?;
352-
let signed = signer.sign(unsigned).await?;
369+
let signed = signer.sign(payload).await?;
353370
Ok(signed)
354371
}
355372

0 commit comments

Comments
 (0)