Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c8b0907
PoC async rpc client
niklasad1 Nov 30, 2021
a45bf14
add client example should be removed from this repo
niklasad1 Nov 30, 2021
c2a9c75
fmt
niklasad1 Nov 30, 2021
1fb8c8d
cargo fmt
niklasad1 Nov 30, 2021
212d79f
subxt client tests
niklasad1 Nov 30, 2021
1a3b5a9
cargo fmt
niklasad1 Nov 30, 2021
f9860e7
fix some nits
niklasad1 Dec 1, 2021
f21ee1a
Merge remote-tracking branch 'origin/master' into na-jsonrpsee-core-c…
niklasad1 Dec 1, 2021
a59db8d
try nightly for all CI jobs
jsdw Dec 2, 2021
c5b3104
need wasm also for CI
jsdw Dec 2, 2021
de869e8
wasm for nightly run too
jsdw Dec 2, 2021
fedf6bf
Merge remote-tracking branch 'origin/master' into na-jsonrpsee-core-c…
niklasad1 Dec 3, 2021
8e6b277
client: add missing features
niklasad1 Dec 3, 2021
752c19e
update jsonrpsee
niklasad1 Dec 21, 2021
2bfc389
hacky
niklasad1 Dec 21, 2021
bca1473
hacky update jsonrpsee
niklasad1 Dec 22, 2021
e2a93e3
use jsonrpsee crates.io release
niklasad1 Dec 22, 2021
32555aa
ci: pin nightly 2021-12-15
niklasad1 Jan 4, 2022
8d449c3
pin nightly to 2021-12-15
niklasad1 Jan 4, 2022
bb10358
Merge remote-tracking branch 'origin/master' into na-jsonrpsee-core-c…
niklasad1 Jan 4, 2022
937e9a6
fix build
niklasad1 Jan 4, 2022
1551e70
fmt
niklasad1 Jan 4, 2022
65fb71a
compile please
niklasad1 Jan 4, 2022
c988c4a
rewrite me
niklasad1 Jan 20, 2022
8dc7dda
Merge remote-tracking branch 'origin/master' into na-jsonrpsee-core-c…
niklasad1 Feb 2, 2022
ae24d3b
fixes
niklasad1 Feb 2, 2022
fa3b905
fixes
niklasad1 Feb 2, 2022
f603d68
pre-generate metadata
niklasad1 Feb 3, 2022
d433828
Merge remote-tracking branch 'origin/na-jsonrpsee-core-client' into n…
niklasad1 Feb 3, 2022
a5df40a
fix nit
niklasad1 Feb 3, 2022
a09e8a8
get rid of needless deps
niklasad1 Feb 3, 2022
b53ae9f
remove embedded client
niklasad1 Feb 3, 2022
b9bc61f
Update Cargo.toml
niklasad1 Feb 3, 2022
b21fde8
Update subxt/Cargo.toml
niklasad1 Feb 3, 2022
4053e30
Update subxt/Cargo.toml
niklasad1 Feb 3, 2022
eed8238
Update subxt/src/client.rs
niklasad1 Feb 3, 2022
5182b95
Update subxt/src/rpc.rs
niklasad1 Feb 3, 2022
9887b39
Update test-runtime/build.rs
niklasad1 Feb 3, 2022
73623c1
cargo fmt
niklasad1 Feb 3, 2022
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
Prev Previous commit
Next Next commit
hacky update jsonrpsee
  • Loading branch information
niklasad1 committed Dec 22, 2021
commit bca14735ab82df2287e04ee6467965f19e1f6dec
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ chameleon = "0.1.0"
scale-info = { version = "1.0.0", features = ["bit-vec"] }
futures = "0.3.13"
hex = "0.4.3"
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee/", branch = "jsonrpsee-clients-expose-tls-feature", features = ["macros", "core-client", "client", "client-ws-transport"] }
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee/", branch = "na-fix-core-client-feature", features = ["macros", "async-client", "client-ws-transport"] }
log = "0.4.14"
num-traits = { version = "0.2.14", default-features = false }
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0.64"
thiserror = "1.0.24"
url = "2.2.1"

subxt-macro = { version = "0.1.0", path = "macro" }

Expand Down
2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ keywords = ["parity", "substrate", "blockchain"]
[dependencies]
async-std = { version = "1.8.0", features = ["tokio1"] }
futures = "0.3.9"
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee/", branch = "extract-async-client", features = ["client"] }
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee/", branch = "na-fix-core-client-feature", features = ["async-client"] }
log = "0.4.13"
thiserror = "1.0.23"
serde_json = "1"
Expand Down
14 changes: 6 additions & 8 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ use futures::{
sink::SinkExt,
stream::StreamExt,
};
use jsonrpsee::{
core_client::Client as JsonRpcClient,
types::{
async_trait,
traits::{
TransportReceiver,
TransportSender,
},
use jsonrpsee::core::{
async_trait,
client::Client as JsonRpcClient,
traits::{
TransportReceiver,
TransportSender,
},
};
use sc_network::config::TransportConfig;
Expand Down
6 changes: 4 additions & 2 deletions examples/submit_and_watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ async fn simple_transfer() -> Result<(), Box<dyn std::error::Error>> {
.sign_and_submit_then_watch(&signer)
.await?
.wait_for_finalized_success()
.await.unwrap()?;
.await
.unwrap()?;

let transfer_event =
balance_transfer.find_first_event::<polkadot::balances::events::Transfer>()?;
Expand Down Expand Up @@ -93,7 +94,8 @@ async fn simple_transfer_separate_events() -> Result<(), Box<dyn std::error::Err
.sign_and_submit_then_watch(&signer)
.await?
.wait_for_finalized()
.await.unwrap()?;
.await
.unwrap()?;

// Now we know it's been finalized, we can get hold of a couple of
// details, including events. Calling `wait_for_finalized_success` is
Expand Down
5 changes: 4 additions & 1 deletion src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with subxt. If not, see <http://www.gnu.org/licenses/>.

use jsonrpsee::core::{DeserializeOwned, client::Subscription};
use jsonrpsee::core::{
client::Subscription,
DeserializeOwned,
};
use sp_core::{
storage::{
StorageChangeSet,
Expand Down
138 changes: 75 additions & 63 deletions src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,51 +64,54 @@ impl<'client, T: Config> TransactionProgress<'client, T> {

// Return the next item otherwise:
let res = sub.next().await?;
Some(res.map(|status| {
match status {
SubstrateTransactionStatus::Future => TransactionStatus::Future,
SubstrateTransactionStatus::Ready => TransactionStatus::Ready,
SubstrateTransactionStatus::Broadcast(peers) => {
TransactionStatus::Broadcast(peers)
}
SubstrateTransactionStatus::InBlock(hash) => {
TransactionStatus::InBlock(TransactionInBlock {
block_hash: hash,
ext_hash: self.ext_hash,
client: self.client,
})
}
SubstrateTransactionStatus::Retracted(hash) => {
TransactionStatus::Retracted(hash)
}
SubstrateTransactionStatus::Usurped(hash) => {
TransactionStatus::Usurped(hash)
}
SubstrateTransactionStatus::Dropped => TransactionStatus::Dropped,
SubstrateTransactionStatus::Invalid => TransactionStatus::Invalid,
// Only the following statuses are actually considered "final" (see the substrate
// docs on `TransactionStatus`). Basically, either the transaction makes it into a
// block, or we eventually give up on waiting for it to make it into a block.
// Even `Dropped`/`Invalid`/`Usurped` transactions might make it into a block eventually.
//
// As an example, a transaction that is `Invalid` on one node due to having the wrong
// nonce might still be valid on some fork on another node which ends up being finalized.
// Equally, a transaction `Dropped` from one node may still be in the transaction pool,
// and make it into a block, on another node. Likewise with `Usurped`.
SubstrateTransactionStatus::FinalityTimeout(hash) => {
self.sub = None;
TransactionStatus::FinalityTimeout(hash)
}
SubstrateTransactionStatus::Finalized(hash) => {
self.sub = None;
TransactionStatus::Finalized(TransactionInBlock {
block_hash: hash,
ext_hash: self.ext_hash,
client: self.client,
})
Some(
res.map(|status| {
match status {
SubstrateTransactionStatus::Future => TransactionStatus::Future,
SubstrateTransactionStatus::Ready => TransactionStatus::Ready,
SubstrateTransactionStatus::Broadcast(peers) => {
TransactionStatus::Broadcast(peers)
}
SubstrateTransactionStatus::InBlock(hash) => {
TransactionStatus::InBlock(TransactionInBlock {
block_hash: hash,
ext_hash: self.ext_hash,
client: self.client,
})
}
SubstrateTransactionStatus::Retracted(hash) => {
TransactionStatus::Retracted(hash)
}
SubstrateTransactionStatus::Usurped(hash) => {
TransactionStatus::Usurped(hash)
}
SubstrateTransactionStatus::Dropped => TransactionStatus::Dropped,
SubstrateTransactionStatus::Invalid => TransactionStatus::Invalid,
// Only the following statuses are actually considered "final" (see the substrate
// docs on `TransactionStatus`). Basically, either the transaction makes it into a
// block, or we eventually give up on waiting for it to make it into a block.
// Even `Dropped`/`Invalid`/`Usurped` transactions might make it into a block eventually.
//
// As an example, a transaction that is `Invalid` on one node due to having the wrong
// nonce might still be valid on some fork on another node which ends up being finalized.
// Equally, a transaction `Dropped` from one node may still be in the transaction pool,
// and make it into a block, on another node. Likewise with `Usurped`.
SubstrateTransactionStatus::FinalityTimeout(hash) => {
self.sub = None;
TransactionStatus::FinalityTimeout(hash)
}
SubstrateTransactionStatus::Finalized(hash) => {
self.sub = None;
TransactionStatus::Finalized(TransactionInBlock {
block_hash: hash,
ext_hash: self.ext_hash,
client: self.client,
})
}
}
}
}).map_err(Into::into))
})
.map_err(Into::into),
)
}

/// Wait for the transaction to be in a block (but not necessarily finalized), and return
Expand All @@ -127,17 +130,20 @@ impl<'client, T: Config> TransactionProgress<'client, T> {
) -> Option<Result<TransactionInBlock<'client, T>, Error>> {
loop {
match self.next().await? {
Ok(status) => match status {
// Finalized or otherwise in a block! Return.
TransactionStatus::InBlock(s) | TransactionStatus::Finalized(s) => {
return Some(Ok(s))
}
// Error scenarios; return the error.
TransactionStatus::FinalityTimeout(_) => {
return Some(Err(TransactionError::FinalitySubscriptionTimeout.into()))
Ok(status) => {
match status {
// Finalized or otherwise in a block! Return.
TransactionStatus::InBlock(s)
| TransactionStatus::Finalized(s) => return Some(Ok(s)),
// Error scenarios; return the error.
TransactionStatus::FinalityTimeout(_) => {
return Some(Err(
TransactionError::FinalitySubscriptionTimeout.into(),
))
}
// Ignore anything else and wait for next status event:
_ => continue,
}
// Ignore anything else and wait for next status event:
_ => continue,
}
Err(err) => return Some(Err(err)),
}
Expand All @@ -159,15 +165,19 @@ impl<'client, T: Config> TransactionProgress<'client, T> {
) -> Option<Result<TransactionInBlock<'client, T>, Error>> {
loop {
match self.next().await? {
Ok(status) => match status {
// finalized! return.
TransactionStatus::Finalized(s) => return Some(Ok(s)),
// error scenarios; return the error.
TransactionStatus::FinalityTimeout(_) => {
return Some(Err(TransactionError::FinalitySubscriptionTimeout.into()))
Ok(status) => {
match status {
// finalized! return.
TransactionStatus::Finalized(s) => return Some(Ok(s)),
// error scenarios; return the error.
TransactionStatus::FinalityTimeout(_) => {
return Some(Err(
TransactionError::FinalitySubscriptionTimeout.into(),
))
}
// ignore and wait for next status event:
_ => continue,
}
// ignore and wait for next status event:
_ => continue,
}
Err(err) => return Some(Err(err)),
}
Expand All @@ -185,7 +195,9 @@ impl<'client, T: Config> TransactionProgress<'client, T> {
/// may well indicate with some probability that the transaction will not make it into a block,
/// there is no guarantee that this is true. Thus, we prefer to "play it safe" here. Use the lower
/// level [`TransactionProgress::next()`] API if you'd like to handle these statuses yourself.
pub async fn wait_for_finalized_success(self) -> Option<Result<TransactionEvents<T>, Error>> {
pub async fn wait_for_finalized_success(
self,
) -> Option<Result<TransactionEvents<T>, Error>> {
let finalized = match self.wait_for_finalized().await? {
Ok(f) => f,
Err(err) => return Some(Err(err)),
Expand Down
2 changes: 1 addition & 1 deletion test-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ codec = { package = "parity-scale-codec", version = "2", default-features = fals
[build-dependencies]
subxt = { path = ".." }
sp-core = { package = "sp-core", git = "https://github.com/paritytech/substrate/", branch = "master" }
jsonrpsee-http-client = { git = "https://github.com/paritytech/jsonrpsee/", branch = "extract-async-client" }
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee/", branch = "na-fix-core-client-feature", features = ["http-client"] }
async-std = { version = "1.9.0", features = ["attributes", "tokio1"] }
which = "4.2.2"
6 changes: 3 additions & 3 deletions test-runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with subxt. If not, see <http://www.gnu.org/licenses/>.

use jsonrpsee_http_client::{
types::traits::Client,
HttpClientBuilder,
use jsonrpsee::{
core::client::ClientT,
http_client::HttpClientBuilder,
};
use std::{
env,
Expand Down