Skip to content

Commit a3ea126

Browse files
authored
Update version, tweak docs, and write up changelog (paritytech#616)
1 parent 7e51b3e commit a3ea126

File tree

11 files changed

+241
-24
lines changed

11 files changed

+241
-24
lines changed

CHANGELOG.md

+204
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,210 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.23.0] - 2022-08-11
8+
9+
This is one of the most significant releases to date in Subxt, and carries with it a number of significant breaking changes, but in exchange, a number of significant improvements. The most significant PR is [#593](https://github.com/paritytech/subxt/pull/593); the fundamental change that this makes is to separate creating a query/transaction/address from submitting it. This gives us flexibility when creating queries; they can be either dynamically or statically generated, but also flexibility in our client, enabling methods to be exposed for online or offline use.
10+
11+
The best place to look to get a feel for what's changed, aside from the documentation itself, is the `examples` folder. What follows are some examples of the changes you'll need to make, which all follow a similar pattern:
12+
13+
### Submitting a transaction
14+
15+
Previously, we'd build a client which is tied to the static codegen, and then use the client to build and submit a transaction like so:
16+
17+
```rust
18+
let api = ClientBuilder::new()
19+
.build()
20+
.await?
21+
.to_runtime_api::<polkadot::RuntimeApi<DefaultConfig, PolkadotExtrinsicParams<_>>>();
22+
23+
let balance_transfer = api
24+
.tx()
25+
.balances()
26+
.transfer(dest, 10_000)?
27+
.sign_and_submit_then_watch_default(&signer)
28+
.await?
29+
.wait_for_finalized_success()
30+
.await?;
31+
```
32+
33+
Now, we build a transaction separately (in this case, using static codegen to guide us as before) and then submit it to a client like so:
34+
35+
``` rust
36+
let api = OnlineClient::<PolkadotConfig>::new().await?;
37+
38+
let balance_transfer_tx = polkadot::tx().balances().transfer(dest, 10_000);
39+
40+
let balance_transfer = api
41+
.tx()
42+
.sign_and_submit_then_watch_default(&balance_transfer_tx, &signer)
43+
.await?
44+
.wait_for_finalized_success()
45+
.await?;
46+
```
47+
48+
See the `examples/examples/submit_and_watch.rs` example for more.
49+
50+
### Fetching a storage entry
51+
52+
Previously, we build and submit a storage query in one step:
53+
54+
```rust
55+
let api = ClientBuilder::new()
56+
.build()
57+
.await?
58+
.to_runtime_api::<polkadot::RuntimeApi<DefaultConfig, PolkadotExtrinsicParams<DefaultConfig>>>();
59+
60+
let entry = api.storage().staking().bonded(&addr, None).await;
61+
```
62+
63+
Now, we build the storage query separately and submit it to the client:
64+
65+
```rust
66+
let api = OnlineClient::<PolkadotConfig>::new().await?;
67+
68+
let staking_bonded = polkadot::storage().staking().bonded(&addr);
69+
70+
let entry = api.storage().fetch(&staking_bonded, None).await;
71+
```
72+
73+
Note that previously, the generated code would do the equivalent of `fetch_or_default` if possible, or `fetch` if no default existed. You must now decide whether to:
74+
- fetch an entry, returning `None` if it's not found (`api.storage().fetch(..)`), or
75+
- fetch an entry, returning the default if it's not found (`api.storage().fetch_or_default(..)`).
76+
77+
The static types will protect you against using `fetch_or_default` when no such default exists, and so the recommendation is to try changing all storage requests to use `fetch_or_default`, falling back to using `fetch` where doing so leads to compile errors.
78+
79+
See `examples/examples/concurrent_storage_requests.rs` for an example of fetching entries.
80+
81+
### Iterating over storage entries
82+
83+
Previously:
84+
85+
```rust
86+
let api = ClientBuilder::new()
87+
.build()
88+
.await?
89+
.to_runtime_api::<polkadot::RuntimeApi<DefaultConfig, PolkadotExtrinsicParams<DefaultConfig>>>();
90+
91+
let mut iter = api
92+
.storage()
93+
.xcm_pallet()
94+
.version_notifiers_iter(None)
95+
.await?;
96+
97+
while let Some((key, value)) = iter.next().await? {
98+
// ...
99+
}
100+
```
101+
102+
Now, as before, building the storage query to iterate over is separate from using it:
103+
104+
```rust
105+
let api = OnlineClient::<PolkadotConfig>::new().await?;
106+
107+
let key_addr = polkadot::storage()
108+
.xcm_pallet()
109+
.version_notifiers_root();
110+
111+
let mut iter = api
112+
.storage()
113+
.iter(key_addr, 10, None).await?;
114+
115+
while let Some((key, value)) = iter.next().await? {
116+
// ...
117+
}
118+
```
119+
120+
Note that the `_root()` suffix on generated storage queries accesses the root entry at that address,
121+
and is available when the address is a map that can be iterated over. By not appending `_root()`, you'll
122+
be asked to provide the values needed to access a specific entry in the map.
123+
124+
See the `examples/examples/storage_iterating.rs` example for more.
125+
126+
### Accessing constants
127+
128+
Before, we'd build a client and use the client to select and query a constant:
129+
130+
```rust
131+
let api = ClientBuilder::new()
132+
.build()
133+
.await?
134+
.to_runtime_api::<polkadot::RuntimeApi<DefaultConfig, PolkadotExtrinsicParams<DefaultConfig>>>();
135+
136+
let existential_deposit = api
137+
.constants()
138+
.balances()
139+
.existential_deposit()?;
140+
```
141+
142+
Now, similar to the other examples, we separately build a constant _address_ and provide that address to the client to look it up:
143+
144+
```rust
145+
let api = OnlineClient::<PolkadotConfig>::new().await?;
146+
147+
let address = polkadot::constants()
148+
.balances()
149+
.existential_deposit();
150+
151+
let existential_deposit = api.constants().at(&address)?;
152+
```
153+
154+
See the `examples/examples/fetch_constants.rs` example for more.
155+
156+
### Subscribing to events
157+
158+
Event subscriptions themselves are relatively unchanged (although the data you can access/get back has changed a little). Before:
159+
160+
```rust
161+
let api = ClientBuilder::new()
162+
.build()
163+
.await?
164+
.to_runtime_api::<polkadot::RuntimeApi<DefaultConfig, PolkadotExtrinsicParams<DefaultConfig>>>();
165+
166+
let mut event_sub = api.events().subscribe().await?;
167+
168+
while let Some(events) = event_sub.next().await {
169+
// ...
170+
}
171+
```
172+
173+
Now, we simply swap the client out for our new one, and the rest is similar:
174+
175+
```rust
176+
let api = OnlineClient::<PolkadotConfig>::new().await?;
177+
178+
let mut event_sub = api.events().subscribe().await?;
179+
180+
while let Some(events) = event_sub.next().await {
181+
// ...
182+
}
183+
```
184+
185+
See the `examples/examples/subscribe_all_events.rs` example for more.
186+
187+
The general pattern, as seen above, is that we break apart constructing a query/address and using it. You can now construct queries dynamically instead and forego all static codegen by using the functionality exposed in the `subxt::dynamic` module instead.
188+
189+
Other smaller breaking changes have happened, but they should be easier to address by following compile errors.
190+
191+
For more details about all of the changes, the full commit history since the last release is as follows:
192+
193+
### Added
194+
195+
- Expose the extrinsic hash from TxProgress ([#614](https://github.com/paritytech/subxt/pull/614))
196+
- Add support for `ws` in `subxt-cli` ([#579](https://github.com/paritytech/subxt/pull/579))
197+
- Expose the SCALE encoded call data of an extrinsic ([#573](https://github.com/paritytech/subxt/pull/573))
198+
- Validate absolute path for `substitute_type` ([#577](https://github.com/paritytech/subxt/pull/577))
199+
200+
### Changed
201+
202+
- Rework Subxt API to support offline and dynamic transactions ([#593](https://github.com/paritytech/subxt/pull/593))
203+
- Use scale-decode to help optimise event decoding ([#607](https://github.com/paritytech/subxt/pull/607))
204+
- Decode raw events using scale_value and return the decoded Values, too ([#576](https://github.com/paritytech/subxt/pull/576))
205+
- dual license ([#590](https://github.com/paritytech/subxt/pull/590))
206+
- Don't hash constant values; only their types ([#587](https://github.com/paritytech/subxt/pull/587))
207+
- metadata: Exclude `field::type_name` from metadata validation ([#595](https://github.com/paritytech/subxt/pull/595))
208+
- Bump Swatinem/rust-cache from 1.4.0 to 2.0.0 ([#597](https://github.com/paritytech/subxt/pull/597))
209+
- Update jsonrpsee requirement from 0.14.0 to 0.15.1 ([#603](https://github.com/paritytech/subxt/pull/603))
210+
7211
## [0.22.0] - 2022-06-20
8212

9213
With this release, subxt can subscribe to the node's runtime upgrades to ensure that the metadata is updated and

cli/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "subxt-cli"
3-
version = "0.22.0"
3+
version = "0.23.0"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
edition = "2021"
66

@@ -16,9 +16,9 @@ path = "src/main.rs"
1616

1717
[dependencies]
1818
# perform subxt codegen
19-
subxt-codegen = { version = "0.22.0", path = "../codegen" }
19+
subxt-codegen = { version = "0.23.0", path = "../codegen" }
2020
# perform node compatibility
21-
subxt-metadata = { version = "0.22.0", path = "../metadata" }
21+
subxt-metadata = { version = "0.23.0", path = "../metadata" }
2222
# parse command line args
2323
structopt = "0.3.25"
2424
# colourful error reports

codegen/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "subxt-codegen"
3-
version = "0.22.0"
3+
version = "0.23.0"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
edition = "2021"
66

@@ -20,7 +20,7 @@ proc-macro-error = "1.0.4"
2020
quote = "1.0.8"
2121
syn = "1.0.58"
2222
scale-info = { version = "2.0.0", features = ["bit-vec"] }
23-
subxt-metadata = { version = "0.22.0", path = "../metadata" }
23+
subxt-metadata = { version = "0.23.0", path = "../metadata" }
2424

2525
[dev-dependencies]
2626
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }

examples/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "subxt-examples"
3-
version = "0.22.0"
3+
version = "0.23.0"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
edition = "2021"
66
publish = false

macro/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "subxt-macro"
3-
version = "0.22.0"
3+
version = "0.23.0"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
edition = "2021"
66
autotests = false
@@ -19,4 +19,4 @@ darling = "0.14.0"
1919
proc-macro-error = "1.0.4"
2020
syn = "1.0.58"
2121

22-
subxt-codegen = { path = "../codegen", version = "0.22.0" }
22+
subxt-codegen = { path = "../codegen", version = "0.23.0" }

metadata/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "subxt-metadata"
3-
version = "0.22.0"
3+
version = "0.23.0"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
edition = "2021"
66
autotests = false

subxt/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "subxt"
3-
version = "0.22.0"
3+
version = "0.23.0"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
edition = "2021"
66

@@ -33,8 +33,8 @@ thiserror = "1.0.24"
3333
tracing = "0.1.34"
3434
parking_lot = "0.12.0"
3535

36-
subxt-macro = { version = "0.22.0", path = "../macro" }
37-
subxt-metadata = { version = "0.22.0", path = "../metadata" }
36+
subxt-macro = { version = "0.23.0", path = "../macro" }
37+
subxt-metadata = { version = "0.23.0", path = "../metadata" }
3838

3939
sp-core = { version = "6.0.0", default-features = false }
4040
sp-runtime = "6.0.0"

subxt/src/lib.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@
3434
//!
3535
//! # Generating runtime types
3636
//!
37-
//! Subxt can generate types at compile time to help you interact with a node. The metadata can be downloaded using the
38-
//! [subxt-cli](https://crates.io/crates/subxt-cli) tool.
37+
//! Subxt can optionally generate types at compile time to help you interact with a node. These types are
38+
//! generated using metadata which can be downloaded from a node using the [subxt-cli](https://crates.io/crates/subxt-cli)
39+
//! tool. These generated types provide a degree of type safety when interacting with a node that is compatible with
40+
//! the metadata that they were generated using. We also do runtime checks in case the node you're talking to has
41+
//! deviated from the types you're using to communicate with it (see below).
3942
//!
40-
//! To generate the types, use the `subxt` attribute which points at downloaded static metadata.
43+
//! To generate the types, use the `subxt` macro and point it at the metadata you've downloaded, like so:
4144
//!
4245
//! ```ignore
4346
//! #[subxt::subxt(runtime_metadata_path = "metadata.scale")]
@@ -47,9 +50,12 @@
4750
//! For more information, please visit the [subxt-codegen](https://docs.rs/subxt-codegen/latest/subxt_codegen/)
4851
//! documentation.
4952
//!
53+
//! You can opt to skip this step and use dynamic queries to talk to nodes instead, which can be useful in some cases,
54+
//! but doesn't provide any type safety.
55+
//!
5056
//! # Interacting with the API
5157
//!
52-
//! Once instantiated, a client, exposes four functions:
58+
//! Once instantiated, a client exposes four core functions:
5359
//! - `.tx()` for submitting extrinsics/transactions. See [`crate::tx::TxClient`] for more details, or see
5460
//! the [balance_transfer](../examples/examples/balance_transfer.rs) example.
5561
//! - `.storage()` for fetching and iterating over storage entries. See [`crate::storage::StorageClient`] for more details, or see
@@ -86,13 +92,20 @@
8692
//! }
8793
//! # }
8894
//! ```
95+
//! ## Opting out of static validation
96+
//!
97+
//! The static types that are used to query/access information are validated by default, to make sure that they are
98+
//! compatible with the node being queried. You can generally call `.unvalidated()` on these static types to
99+
//! disable this validation.
89100
//!
90101
//! # Runtime Updates
91102
//!
92-
//! There are cases when the node would perform a runtime update, and the runtime node's metadata would be
93-
//! out of sync with the subxt's metadata.
103+
//! The node you're connected to may occasionally perform runtime updates while you're connected, which would ordinarily
104+
//! leave the runtime state of the node out of sync with the information Subxt requires to do things like submit
105+
//! transactions.
94106
//!
95-
//! The `UpdateClient` API keeps the `RuntimeVersion` and `Metadata` of the client synced with the target node.
107+
//! If this is a concern, you can use the `UpdateClient` API to keep the `RuntimeVersion` and `Metadata` of the client
108+
//! synced with the target node.
96109
//!
97110
//! Please visit the [subscribe_runtime_updates](../examples/examples/subscribe_runtime_updates.rs) example for more details.
98111

testing/integration-tests/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "integration-tests"
3-
version = "0.22.0"
3+
version = "0.23.0"
44
authors = ["Parity Technologies <admin@parity.io>"]
55
edition = "2021"
66

@@ -26,8 +26,8 @@ sp-core = { version = "6.0.0", default-features = false }
2626
sp-keyring = "6.0.0"
2727
sp-runtime = "6.0.0"
2828
syn = "1.0.0"
29-
subxt = { version = "0.22.0", path = "../../subxt" }
30-
subxt-codegen = { version = "0.22.0", path = "../../codegen" }
29+
subxt = { version = "0.23.0", path = "../../subxt" }
30+
subxt-codegen = { version = "0.23.0", path = "../../codegen" }
3131
test-runtime = { path = "../test-runtime" }
3232
tokio = { version = "1.8", features = ["macros", "time"] }
3333
tracing = "0.1.34"

testing/test-runtime/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "test-runtime"
3-
version = "0.22.0"
3+
version = "0.23.0"
44
edition = "2021"
55

66
[dependencies]

testing/ui-tests/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ui-tests"
3-
version = "0.22.0"
3+
version = "0.23.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

0 commit comments

Comments
 (0)