Rework Subxt API to support offline and dynamic transactions (#593)

* WIP API changes

* debug impls

* Get main crate compiling with first round of changes

* Some tidy up

* Add WithExtrinsicParams, and have SubstrateConfig + PolkadotConfig, not DefaultConfig

* move transaction into extrinsic folder

* Add runtime updates back to OnlineClient

* rework to be 'client first' to fit better with storage + events

* add support for events to Client

* tidy dupe trait bound

* Wire storage into client, but need to remove static reliance

* various tidy up and start stripping codegen to remove bits we dont need now

* First pass updating calls and constants codegen

* WIP storage client updates

* First pass migrated runtime storage over to new format

* pass over codegen to generate StorageAddresses and throw other stuff out

* don't need a Call trait any more

* shuffle things around a bit

* Various proc_macro fixes to get 'cargo check' working

* organise what's exposed from subxt

* Get first example working; balance_transfer_with_params

* get balance_transfer example compiling

* get concurrent_storage_requests.rs example compiling

* get fetch_all_accounts example compiling

* get a bunch more of the examples compiling

* almost get final example working; type mismatch to look into

* wee tweaks

* move StorageAddress to separate file

* pass Defaultable/Iterable info to StorageAddress in codegen

* fix storage validation ne, and partial run through example code

* Remove static iteration and strip a generic param from everything

* fix doc tests in subxt crate

* update test utils and start fixing frame tests

* fix frame staking tests

* fix the rest of the test compile issues, Borrow on storage values

* cargo fmt

* remove extra logging during tests

* Appease clippy and no more need for into_iter on events

* cargo fmt

* fix dryRun tests by waiting for blocks

* wait for blocks instead of sleeping or other test hacks

* cargo fmt

* Fix doc links

* Traitify StorageAddress

* remove out-of-date doc comments

* optimise decoding storage a little

* cleanup tx stuff, trait for TxPayload, remove Err type param and decode at runtime

* clippy fixes

* fix doc links

* fix doc example

* constant address trait for consistency

* fix a typo and remove EncodeWithMetadata stuff

* Put EventDetails behind a proper interface and allow decoding into top level event, too

* fix docs

* tweak StorageAddress docs

* re-export StorageAddress at root for consistency

* fix clippy things

* Add support for dynamic values

* fix double encoding of storage map key after refactor

* clippy fix

* Fixes and add a dynamic usage example (needs new scale_value release)

* bump scale_value version

* cargo fmt

* Tweak event bits

* cargo fmt

* Add a test and bump scale-value to 0.4.0 to support this

* remove unnecessary vec from dynamic example

* Various typo/grammar fixes

Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>

* Address PR nits

* Undo accidental rename in changelog

* Small PR nits/tidyups

* fix tests; codegen change against latest substrate

* tweak storage address util names

* move error decoding to DecodeError and expose

* impl some basic traits on the extrinsic param builder

Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
This commit is contained in:
James Wilson
2022-08-08 11:55:20 +01:00
committed by GitHub
parent 7a09ac6cd7
commit e48f0e3b1d
84 changed files with 23097 additions and 35863 deletions
+4 -4
View File
@@ -69,9 +69,9 @@ impl FromIterator<syn::Path> for Derives {
}
impl Derives {
/// Add `::subxt::codec::CompactAs` to the derives.
/// Add `::subxt::ext::codec::CompactAs` to the derives.
pub fn insert_codec_compact_as(&mut self) {
self.insert(parse_quote!(::subxt::codec::CompactAs));
self.insert(parse_quote!(::subxt::ext::codec::CompactAs));
}
pub fn append(&mut self, derives: impl Iterator<Item = syn::Path>) {
@@ -88,8 +88,8 @@ impl Derives {
impl Default for Derives {
fn default() -> Self {
let mut derives = HashSet::new();
derives.insert(syn::parse_quote!(::subxt::codec::Encode));
derives.insert(syn::parse_quote!(::subxt::codec::Decode));
derives.insert(syn::parse_quote!(::subxt::ext::codec::Encode));
derives.insert(syn::parse_quote!(::subxt::ext::codec::Decode));
derives.insert(syn::parse_quote!(Debug));
Self { derives }
}
+42 -42
View File
@@ -53,7 +53,7 @@ fn generate_struct_with_primitives() {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct S {
pub a: ::core::primitive::bool,
pub b: ::core::primitive::u32,
@@ -99,12 +99,12 @@ fn generate_struct_with_a_struct_field() {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Child {
pub a: ::core::primitive::i32,
}
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Parent {
pub a: ::core::primitive::bool,
pub b: root::subxt_codegen::types::tests::Child,
@@ -144,10 +144,10 @@ fn generate_tuple_struct() {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Child(pub ::core::primitive::i32,);
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Parent(pub ::core::primitive::bool, pub root::subxt_codegen::types::tests::Child,);
}
}
@@ -226,34 +226,34 @@ fn derive_compact_as_for_uint_wrapper_structs() {
pub mod tests {
use super::root;
#[derive(::subxt::codec::CompactAs, ::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::CompactAs, ::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Su128 { pub a: ::core::primitive::u128, }
#[derive(::subxt::codec::CompactAs, ::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::CompactAs, ::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Su16 { pub a: ::core::primitive::u16, }
#[derive(::subxt::codec::CompactAs, ::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::CompactAs, ::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Su32 { pub a: ::core::primitive::u32, }
#[derive(::subxt::codec::CompactAs, ::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::CompactAs, ::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Su64 { pub a: ::core::primitive::u64, }
#[derive(::subxt::codec::CompactAs, ::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::CompactAs, ::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Su8 { pub a: ::core::primitive::u8, }
#[derive(::subxt::codec::CompactAs, ::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::CompactAs, ::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct TSu128(pub ::core::primitive::u128,);
#[derive(::subxt::codec::CompactAs, ::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::CompactAs, ::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct TSu16(pub ::core::primitive::u16,);
#[derive(::subxt::codec::CompactAs, ::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::CompactAs, ::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct TSu32(pub ::core::primitive::u32,);
#[derive(::subxt::codec::CompactAs, ::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::CompactAs, ::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct TSu64(pub ::core::primitive::u64,);
#[derive(::subxt::codec::CompactAs, ::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::CompactAs, ::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct TSu8(pub ::core::primitive::u8,);
}
}
@@ -289,7 +289,7 @@ fn generate_enum() {
quote! {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub enum E {
# [codec (index = 0)]
A,
@@ -347,7 +347,7 @@ fn compact_fields() {
quote! {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub enum E {
# [codec (index = 0)]
A {
@@ -358,12 +358,12 @@ fn compact_fields() {
B( #[codec(compact)] ::core::primitive::u32,),
}
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct S {
#[codec(compact)] pub a: ::core::primitive::u32,
}
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct TupleStruct(#[codec(compact)] pub ::core::primitive::u32,);
}
}
@@ -397,7 +397,7 @@ fn generate_array_field() {
quote! {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct S {
pub a: [::core::primitive::u8; 32usize],
}
@@ -434,7 +434,7 @@ fn option_fields() {
quote! {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct S {
pub a: ::core::option::Option<::core::primitive::bool>,
pub b: ::core::option::Option<::core::primitive::u32>,
@@ -474,7 +474,7 @@ fn box_fields_struct() {
quote! {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct S {
pub a: ::std::boxed::Box<::core::primitive::bool>,
pub b: ::std::boxed::Box<::core::primitive::u32>,
@@ -514,7 +514,7 @@ fn box_fields_enum() {
quote! {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub enum E {
# [codec (index = 0)]
A(::std::boxed::Box<::core::primitive::bool>,),
@@ -554,7 +554,7 @@ fn range_fields() {
quote! {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct S {
pub a: ::core::ops::Range<::core::primitive::u32>,
pub b: ::core::ops::RangeInclusive<::core::primitive::u32>,
@@ -598,12 +598,12 @@ fn generics() {
quote! {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Bar {
pub b: root::subxt_codegen::types::tests::Foo<::core::primitive::u32>,
pub c: root::subxt_codegen::types::tests::Foo<::core::primitive::u8>,
}
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Foo<_0> {
pub a: _0,
}
@@ -646,12 +646,12 @@ fn generics_nested() {
quote! {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Bar<_0> {
pub b: root::subxt_codegen::types::tests::Foo<_0, ::core::primitive::u32>,
}
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Foo<_0, _1> {
pub a: _0,
pub b: ::core::option::Option<(_0, _1,)>,
@@ -697,10 +697,10 @@ fn generate_bitvec() {
quote! {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct S {
pub lsb: ::subxt::bitvec::vec::BitVec<::core::primitive::u8, root::bitvec::order::Lsb0>,
pub msb: ::subxt::bitvec::vec::BitVec<::core::primitive::u16, root::bitvec::order::Msb0>,
pub lsb: ::subxt::ext::bitvec::vec::BitVec<::core::primitive::u8, root::bitvec::order::Lsb0>,
pub msb: ::subxt::ext::bitvec::vec::BitVec<::core::primitive::u16, root::bitvec::order::Msb0>,
}
}
}
@@ -750,12 +750,12 @@ fn generics_with_alias_adds_phantom_data_marker() {
quote! {
pub mod tests {
use super::root;
#[derive(::subxt::codec::CompactAs, ::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::CompactAs, ::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct NamedFields<_0> {
pub b: ::core::primitive::u32,
#[codec(skip)] pub __subxt_unused_type_params: ::core::marker::PhantomData<_0>
}
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct UnnamedFields<_0, _1> (
pub (::core::primitive::u32, ::core::primitive::u32,),
#[codec(skip)] pub ::core::marker::PhantomData<(_0, _1)>
@@ -818,20 +818,20 @@ fn modules() {
pub mod b {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Bar {
pub a: root::subxt_codegen::types::tests::m::a::Foo,
}
}
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Foo;
}
pub mod c {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct Foo {
pub a: root::subxt_codegen::types::tests::m::a::b::Bar,
}
@@ -868,7 +868,7 @@ fn dont_force_struct_names_camel_case() {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug)]
pub struct AB;
}
}
@@ -905,10 +905,10 @@ fn apply_user_defined_derives_for_all_types() {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Clone, Debug, Eq)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Clone, Debug, Eq)]
pub struct A(pub root :: subxt_codegen :: types :: tests :: B,);
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Clone, Debug, Eq)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Clone, Debug, Eq)]
pub struct B;
}
}
@@ -964,13 +964,13 @@ fn apply_user_defined_derives_for_specific_types() {
pub mod tests {
use super::root;
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug, Eq)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug, Eq)]
pub struct A(pub root :: subxt_codegen :: types :: tests :: B,);
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug, Eq, Hash)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug, Eq, Hash)]
pub struct B(pub root :: subxt_codegen :: types :: tests :: C,);
#[derive(::subxt::codec::Decode, ::subxt::codec::Encode, Debug, Eq, Ord, PartialOrd)]
#[derive(::subxt::ext::codec::Decode, ::subxt::ext::codec::Encode, Debug, Eq, Ord, PartialOrd)]
pub struct C;
}
}
+1 -1
View File
@@ -182,7 +182,7 @@ impl TypePathType {
let bit_order_type = &self.params[0];
let bit_store_type = &self.params[1];
let type_path = parse_quote! { ::subxt::bitvec::vec::BitVec<#bit_store_type, #bit_order_type> };
let type_path = parse_quote! { ::subxt::ext::bitvec::vec::BitVec<#bit_store_type, #bit_order_type> };
syn::Type::Path(type_path)
}