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

Modify examples to work with latest substrate changes #440

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ USAGE:
subxt <SUBCOMMAND>

FLAGS:
-h, --help
-h, --help
Prints help information

-V, --version
-V, --version
Prints version information


Expand All @@ -37,9 +37,9 @@ OPTIONS:

## Codegen

Use to invoke the `subxt-codegen` crate which is used by `subxt-macro` to generate the the runtime API and types. Useful
for troubleshooting codegen as an alternative to `cargo expand`, and also provides the possibility of customizing the
generated code if the macro does not produce the desired API. e.g.
Use to invoke the `subxt-codegen` crate which is used by `subxt-macro` to generate the runtime API and types. Useful
for troubleshooting codegen as an alternative to `cargo expand`, and also provides the possibility of customizing the
generated code if the macro does not produce the desired API. e.g.
Comment on lines +41 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for troubleshooting codegen as an alternative to `cargo expand`, and also provides the possibility of customizing the
generated code if the macro does not produce the desired API. e.g.
for troubleshooting codegen as an alternative to `cargo expand`, and also provides the possibility to customize the
generated code if the macro does not produce the desired API. e.g.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Will open a new PR, examples are working on master


`subxt codegen | rustfmt --edition=2018 --emit=stdout`

Expand All @@ -48,10 +48,10 @@ USAGE:
subxt codegen [OPTIONS]

OPTIONS:
-f, --file <file>
-f, --file <file>
the path to the encoded metadata file

--url <url>
--url <url>
the url of the substrate node to query for metadata for codegen

```
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/custom_type_derives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
runtime_metadata_path = "examples/polkadot_metadata.scale",
// We can add (certain) custom derives to the generated types by providing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious: do you happen to know what this "(certain)" means? Do we know which ones work and which don't?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't actually dug into this; I suspect we are limited by the derives on various types that are pointed at by the codegen types (eg sp_core::AccountId32 to use one example), so I think to find out we'd have to look through such types and find the common derives across them all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subxt::Encode, subxt::Decode and Debug are already generated in polkadot.rs file.

Also std::Hash is problematic due to subxt::WrapperKeepOpaque<polkadot_runtime::Call> and PhantomDataSendSync. I guess I could address the Hash in a different PR.

// a comma separated list to the below attribute. Most useful for adding `Clone`:
generated_type_derives = "Clone, Hash"
generated_type_derives = "Clone"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting; did Hash not work? (I think I'd have more than one if possible just so that people can see how to add multiple derives (and adding just one is fairly obvious from that :))

)]
pub mod polkadot {}

Expand Down
Binary file modified examples/examples/polkadot_metadata.scale
Binary file not shown.
8 changes: 4 additions & 4 deletions examples/examples/submit_and_watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn simple_transfer() -> Result<(), Box<dyn std::error::Error>> {
balance_transfer.find_first_event::<polkadot::balances::events::Transfer>()?;

if let Some(event) = transfer_event {
println!("Balance transfer success: value: {:?}", event.2);
println!("Balance transfer success: value: {:?}", event);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
println!("Balance transfer success: value: {:?}", event);
println!("Balance transfer success. Value: {:?}", event);

…but is it a "value" or an "event"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmm, it was a value but if we are printing out the entire event now by the looks of it, it's now just the Transfer event.

} else {
println!("Failed to find Balances::Transfer Event");
}
Expand Down Expand Up @@ -119,7 +119,7 @@ async fn simple_transfer_separate_events() -> Result<(), Box<dyn std::error::Err
let transfer_event =
events.find_first_event::<polkadot::balances::events::Transfer>()?;
if let Some(event) = transfer_event {
println!("Balance transfer success: value: {:?}", event.2);
println!("Balance transfer success: value: {:?}", event);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

} else {
println!("Failed to find Balances::Transfer Event");
}
Expand Down Expand Up @@ -166,7 +166,7 @@ async fn handle_transfer_events() -> Result<(), Box<dyn std::error::Error>> {
if let Some(event) = transfer_event {
println!(
"Balance transfer is now in block (but not finalized): value: {:?}",
event.2
event
);
} else {
println!("Failed to find Balances::Transfer Event");
Expand All @@ -185,7 +185,7 @@ async fn handle_transfer_events() -> Result<(), Box<dyn std::error::Error>> {
events.find_first_event::<polkadot::balances::events::Transfer>()?;

if let Some(event) = transfer_event {
println!("Balance transfer success: value: {:?}", event.2);
println!("Balance transfer success: value: {:?}", event);
} else {
println!("Failed to find Balances::Transfer Event");
}
Expand Down
2 changes: 1 addition & 1 deletion examples/examples/transfer_subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
&mut &raw.data[..],
);
if let Ok(e) = event {
println!("Balance transfer success: value: {:?}", e.2);
println!("Balance transfer success: value: {:?}", e);
} else {
println!("Failed to subscribe to Balances::Transfer Event");
}
Expand Down
2 changes: 1 addition & 1 deletion subxt/tests/integration/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/// Generate by:
///
/// - run `polkadot --dev --tmp` node locally
/// - `cargo run --release -p subxt-cli -- codegen | rustfmt --edition=2018 --emit=stdout > tests/integration/codegen/polkadot.rs`
/// - `cargo run --release -p subxt-cli -- codegen | rustfmt --edition=2018 --emit=stdout > subxt/tests/integration/codegen/polkadot.rs`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're on edition 2021 I think. But also: do we really need that? I suspect just | rustfmt > subxt/…/… works too?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree; I don't think either of the flags are needed actually (I always just rustfmt > outfile)

#[rustfmt::skip]
#[allow(clippy::all)]
mod polkadot;