Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support unsigned extrinsics. #130

Merged
merged 1 commit into from
Jun 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,10 @@ impl<T: Runtime> Client<T> {
.and_then(|module| module.call(C::FUNCTION, call))?)
}

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

/// Creates an unsigned extrinsic.
pub async fn create_unsigned<C: Call<T> + Send + Sync>(
&self,
call: C,
account_id: &<T as System>::AccountId,
nonce: Option<T::Index>,
) -> Result<UncheckedExtrinsic<T>, Error>
where
<<T::Extra as SignedExtra<T>>::Extra as SignedExtension>::AdditionalSigned:
Send + Sync,
{
let payload = self.create_payload(call, account_id, nonce).await?;
let (call, _, _) = payload.deconstruct();
let unsigned = UncheckedExtrinsic::<T>::new_unsigned(call);
Ok(unsigned)
}

/// Creates a signed extrinsic.
pub async fn create_signed<C: Call<T> + Send + Sync>(
&self,
Expand All @@ -346,10 +363,10 @@ impl<T: Runtime> Client<T> {
<<T::Extra as SignedExtra<T>>::Extra as SignedExtension>::AdditionalSigned:
Send + Sync,
{
let unsigned = self
.create_unsigned(call, signer.account_id(), signer.nonce())
let payload = self
.create_payload(call, signer.account_id(), signer.nonce())
.await?;
let signed = signer.sign(unsigned).await?;
let signed = signer.sign(payload).await?;
Ok(signed)
}

Expand Down