-
Notifications
You must be signed in to change notification settings - Fork 262
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 constructing and submitting V5 transactions #1931
base: master
Are you sure you want to change the base?
Conversation
/// `None` means the tx will be immortal. | ||
mortality: Option<Mortality<T::Hash>>, | ||
/// `None` means the tx will be immortal, else it's mortal for N blocks (if possible). | ||
mortality: Option<u64>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is related to changes of RefineParams stuff, I like that the API is much easier to use block number instead of both block hash and block number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I messed with everything a bunch and then realised I had to undo a load of stuff, but wanted to keep not needing the block hash too :)
/// Set the signature. This happens after we have constructed the extrinsic params, | ||
/// and so is defined here rather than on the params, below. We need to use `&dyn Any` | ||
/// to keep this trait object safe, but can downcast in the impls. | ||
fn inject_signature(&mut self, _account_id: &dyn Any, _signature: &dyn Any) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aye, I see the downcast/upcast annoyance now
IIRC, these needs to be downcasted to T::AccountId and T::Signature in the impl maybe add a big
warning if account_id and signature doesn't have the correct types it will panic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup exactly; the impl has access to T: Config
and the types come from a client with the same config, so all should work, but yeah let's make the warnings way clearer here!
) -> Result<Transaction<T>, Error> { | ||
// 1. Validate this call against the current node metadata if the call comes | ||
// with a hash allowing us to do so. | ||
validate(call, metadata)?; | ||
|
||
// 2. Encode extrinsic | ||
// 3. Encode extrinsic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 3. Encode extrinsic | |
// 2. Encode extrinsic |
revert, looks like it was correct before
// | ||
// Either could make sense, but we keep the oldest to prioritize backward compat with | ||
// older tooling. | ||
version: *e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this mean in practice that we will probably just use transaction v4 if we assume both formats are supported by the node we connected to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup; we pick the lowest version for now because we know it'll work!
(for instance, right now you can submit v5 extrinsics but the VerifySignature
extension doesn't appear to be used yet anywhere (at least on Substrate dev nodes and iirc polkadot), which means you couldn't sign them, so they would fail anyways)
/// | ||
/// Note: if not provided, the default account nonce will be set to 0 and the default mortality will be _immortal_. | ||
/// This is because this method runs offline, and so is unable to fetch the data needed for more appropriate values. | ||
pub fn create_partial_signed_offline<Call>( | ||
pub fn create_partial_offline<Call>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create_partial_signed_offline removed?
I guess one needs to call sign explicitly on it now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just calleed create_partial_offline
now :)
The "signed" bit felt confusing because the thing being created is partial but it's definitely not signed yet!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, looks way cleaner than I had mind.
Perhaps just some extra clarification on the method that exposes the dyn Any stuff.
This PR adds support for constructing v5 bare and general extrinsics, and updates some of the surrounding terminology to match that of polkadot-sdk More concretely:
VerifySignature
transaction extension (this is how a signature is passed in a V5 general extrinsic)VerifySignature
when constructing the payload, and we inject signature into this payload just prior to submitting).RefineParams
intoParams
and change interface toinject_*
to align with how we now inject signature.create_v4_partial
,create_v5_partial
,create_v4_partial_offline
,create_v5_partial_offline
,create_v4_unsigned
,create_v5_bare
. Add similar to subxt_core (only having versioned methods at that level).T::AccountId
rather thanT::Address
now because this is what V5 requires, and only AccountId was ever useful in v4 anyway.SignerT::address
is thus not needed and removed. (See https://github.com/paritytech/polkadot-sdk/blob/cf52a0d960a17b4d023bb7c9351e159c60227c85/docs/sdk/src/reference_docs/extrinsic_encoding.rs#L100)create_partial_signed
=>create_partial
,SignedExtension
=>TransactionExtension
,extra
=>value
,additional
=>implicit
,PartialExtrinsic
=>PartialTransaction
,SubmittableExtrinsic
=>SubmittableTransaction
Todo: