hacky update jsonrpsee

This commit is contained in:
Niklas
2021-12-22 13:19:54 +01:00
parent 2bfc3898b7
commit bca14735ab
8 changed files with 95 additions and 81 deletions
+1 -2
View File
@@ -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" }
+1 -1
View File
@@ -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"
+6 -8
View File
@@ -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;
+4 -2
View File
@@ -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>()?;
@@ -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
+4 -1
View File
@@ -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,
+75 -63
View File
@@ -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)
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,
})
}
}
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
@@ -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))
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,
}
// Error scenarios; return the error.
TransactionStatus::FinalityTimeout(_) => {
return Some(Err(TransactionError::FinalitySubscriptionTimeout.into()))
}
// Ignore anything else and wait for next status event:
_ => continue,
}
Err(err) => return Some(Err(err)),
}
@@ -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)),
}
@@ -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)),
+1 -1
View File
@@ -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"
+3 -3
View File
@@ -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,