Skip to content

Commit

Permalink
Merge branch 'master' into fix-retracted-extrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
paulormart committed Nov 3, 2021
2 parents 7c81fb5 + 793c945 commit 59f4677
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 19,761 deletions.
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@

A library to **sub**mit e**xt**rinsics to a [substrate](https://github.com/paritytech/substrate) node via RPC.

### :warning: Health Warning :warning: considered *alpha* after recent changes, API still subject to change

#### See https://github.com/paritytech/subxt/issues/309 for an overview of outstanding issues.

## Usage

See [examples](./examples).

## Integration Testing

Most tests require a running substrate node to communicate with. This is done by spawning an instance of the
substrate node per test. It requires an executable binary `substrate` at [`v3.0.0`](https://github.com/paritytech/substrate/releases/tag/v3.0.0) on your path.
substrate node per test. It requires an executable binary `substrate` at [`polkadot-v0.9.10`](https://github.com/paritytech/substrate/releases/tag/polkadot-v0.9.10) on your path.

This can be done by downloading the prebuilt binary:
This can be installed from source via cargo:

```bash
curl "https://releases.parity.io/substrate/x86_64-debian:stretch/v3.0.0/substrate/substrate" --output substrate --location
chmod +x ./substrate
mv substrate ~/.local/bin
cargo install --git https://github.com/paritytech/substrate node-cli --tag=polkadot-v0.9.10 --force
```

Or installed from source via cargo:

```bash
cargo install --git https://github.com/paritytech/substrate node-cli --tag=v3.0.0 --force
```




**Alternatives**

[substrate-api-client](https://github.com/scs/substrate-api-client) provides similar functionality.
Expand Down
13 changes: 0 additions & 13 deletions codegen/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,6 @@ impl RuntimeGenerator {
"sp_runtime::multiaddress::MultiAddress",
parse_quote!(::subxt::sp_runtime::MultiAddress),
),
// todo: [AJ] remove the requirement for these by implementing Compact handling properly
(
"sp_arithmetic::per_things::Perbill",
parse_quote!(::subxt::sp_arithmetic::per_things::Perbill),
),
(
"sp_arithmetic::per_things::Perquintill",
parse_quote!(::subxt::sp_arithmetic::per_things::Perquintill),
),
(
"frame_support::traits::misc::WrapperKeepOpaque",
parse_quote!(::subxt::WrapperKeepOpaque),
Expand Down Expand Up @@ -210,7 +201,6 @@ impl RuntimeGenerator {
}
};

// todo: [AJ] keep all other code items from decorated mod?
let mod_ident = item_mod_ir.ident;
let pallets_with_storage =
pallets_with_mod_names
Expand All @@ -233,7 +223,6 @@ impl RuntimeGenerator {
#types_mod

/// Default configuration of common types for a target Substrate runtime.
// todo: allow to define/override this as part of the annotated mod
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct DefaultConfig;

Expand All @@ -253,11 +242,9 @@ impl RuntimeGenerator {

impl ::subxt::ExtrinsicExtraData<DefaultConfig> for DefaultConfig {
type AccountData = AccountData;
// todo: [AJ] make this configurable or auto-generated from metadata
type Extra = ::subxt::DefaultExtra<DefaultConfig>;
}

// todo: [AJ] check for this type's existence or allow config
pub type AccountData = self::system::storage::Account;

impl ::subxt::AccountData<DefaultConfig> for AccountData {
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/api/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ fn generate_storage_entry_fns(

let key_args = fields
.iter()
.map(|(field_name, field_type)| quote!( #field_name: #field_type )); // todo: [AJ] borrow non build-inf types?
.map(|(field_name, field_type)| quote!( #field_name: #field_type ));
let client_fns = quote! {
pub async fn #fn_name(
&self,
Expand Down
4 changes: 1 addition & 3 deletions codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ use syn::{
token,
};

// todo: [AJ] implement ToTokens for this to generate the actual mod
// todo: [AJ] figure out how to incorporate the types and api codegen here...
#[derive(Debug, PartialEq, Eq)]
pub struct ItemMod {
// attrs: Vec<syn::Attribute>, // todo: [AJ] partition attributes between subxt and non-subxt
// attrs: Vec<syn::Attribute>,
vis: syn::Visibility,
mod_token: token::Mod,
pub ident: syn::Ident,
Expand Down
1 change: 0 additions & 1 deletion codegen/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ impl<'a> TypeGenerator<'a> {
path: substitute_type_path.clone(),
params,
})
// todo: add tests for this type substitution
} else {
TypePath::Type(TypePathType {
ty,
Expand Down
2 changes: 0 additions & 2 deletions codegen/src/types/type_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ impl<'a> TypeDefGen<'a> {

let ty_toks = |ty_name: &str, ty_path: &TypePath| {
if ty_name.contains("Box<") {
// todo [AJ] remove this hack once scale-info can represent Box somehow
quote! { ::std::boxed::Box<#ty_path> }
} else {
quote! { #ty_path }
Expand Down Expand Up @@ -240,7 +239,6 @@ impl<'a> TypeDefGen<'a> {
}
};
if ty.is_compact() {
// todo: [AJ] figure out way to ensure AsCompact generated for target type in scale_info.
quote!( #[codec(compact)] #field_type )
} else {
quote!( #field_type )
Expand Down
2 changes: 0 additions & 2 deletions codegen/src/types/type_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ impl TypePathType {
syn::Type::Path(path)
}
TypeDef::Compact(_) => {
// todo: change the return type of this method to include info that it is compact
// and should be annotated with #[compact] for fields
let compact_type = &self.params[0];
syn::Type::Path(parse_quote! ( #compact_type ))
}
Expand Down
27 changes: 19 additions & 8 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,25 +298,36 @@ where
TypeDef::Composite(composite) => {
match composite.fields() {
[field] => {
let field_ty = self
.metadata
.resolve_type(field.ty().id())
.ok_or(MetadataError::TypeNotFound(field.ty().id()))?;
if let TypeDef::Primitive(primitive) = field_ty.type_def() {
let field_ty =
self.metadata.resolve_type(field.ty().id()).ok_or(
MetadataError::TypeNotFound(field.ty().id()),
)?;
if let TypeDef::Primitive(primitive) = field_ty.type_def()
{
decode_compact_primitive(primitive)
} else {
Err(EventsDecodingError::InvalidCompactType("Composite type must have a single primitive field".into()).into())
}
}
_ => Err(EventsDecodingError::InvalidCompactType("Composite type must have a single field".into()).into())
_ => {
Err(EventsDecodingError::InvalidCompactType(
"Composite type must have a single field".into(),
)
.into())
}
}
}
_ => Err(EventsDecodingError::InvalidCompactType("Compact type must be a primitive or a composite type".into()).into()),
_ => {
Err(EventsDecodingError::InvalidCompactType(
"Compact type must be a primitive or a composite type".into(),
)
.into())
}
}
}
TypeDef::BitSequence(_bitseq) => {
// decode_raw::<bitvec::BitVec>
todo!("BitVec")
unimplemented!("BitVec decoding for events not implemented yet")
}
}
}
Expand Down
Loading

0 comments on commit 59f4677

Please sign in to comment.