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

[WIP]: jsonrpsee proc macros #431

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
489650c
introduce jsonrpsee proc macros API
niklasad1 Feb 3, 2022
5f692ac
add remaining RPCs
niklasad1 Feb 10, 2022
43062cb
Merge remote-tracking branch 'origin/master' into na-jsonrpsee-macros
niklasad1 Feb 10, 2022
5ee0bb5
test alex's PR
niklasad1 Jun 28, 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
16 changes: 11 additions & 5 deletions examples/examples/fetch_remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
// along with subxt. If not, see <http://www.gnu.org/licenses/>.

use subxt::{
rpc::SubxtRpcApiClient,
ClientBuilder,
Config,
DefaultConfig,
DefaultExtra,
};

type Hash = <DefaultConfig as Config>::Hash;
type Header = <DefaultConfig as Config>::Header;
type Extrinsic = <DefaultConfig as Config>::Header;

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
pub mod polkadot {}

Expand All @@ -35,11 +41,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let block_number = 1;

let block_hash = api
.client
.rpc()
.block_hash(Some(block_number.into()))
.await?;
let block_hash = SubxtRpcApiClient::<Hash, Header, Extrinsic>::block_hash(
api.client.rpc().inner(),
Some(block_number.into()),
)
.await?;

if let Some(hash) = block_hash {
println!("Block hash for block number {}: {}", block_number, hash);
Expand Down
14 changes: 13 additions & 1 deletion examples/examples/transfer_subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@

use sp_keyring::AccountKeyring;
use subxt::{
rpc::SubxtRpcApiClient,
ClientBuilder,
Config,
DefaultConfig,
DefaultExtra,
EventStorageSubscription,
EventSubscription,
PairSigner,
};

type Hash = <DefaultConfig as Config>::Hash;
type Header = <DefaultConfig as Config>::Header;
type Extrinsic = <DefaultConfig as Config>::Header;

#[subxt::subxt(runtime_metadata_path = "examples/polkadot_metadata.scale")]
pub mod polkadot {}

Expand All @@ -46,7 +53,12 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await?
.to_runtime_api::<polkadot::RuntimeApi<DefaultConfig, DefaultExtra<DefaultConfig>>>();

let sub = api.client.rpc().subscribe_events().await?;
let sub = SubxtRpcApiClient::<Hash, Header, Extrinsic>::subscribe_events(
api.client.rpc().inner(),
)
.await?;

let sub = EventStorageSubscription::Imported(sub);
let decoder = api.client.events_decoder();
let mut sub = EventSubscription::<DefaultConfig>::new(sub, decoder);
sub.filter_event::<polkadot::balances::events::Transfer>();
Expand Down
2 changes: 1 addition & 1 deletion subxt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ chameleon = "0.1.0"
scale-info = { version = "1.0.0", features = ["bit-vec"] }
futures = "0.3.13"
hex = "0.4.3"
jsonrpsee = { version = "0.8.0", features = ["async-client", "client-ws-transport"] }
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee", branch = "696_trait_bounds", 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"] }
Expand Down
38 changes: 28 additions & 10 deletions subxt/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::{
Rpc,
RpcClient,
RuntimeVersion,
SubxtRpcApiClient,
SystemProperties,
},
storage::StorageClient,
Expand All @@ -40,7 +41,10 @@ use crate::{
Config,
Metadata,
};
use codec::Decode;
use codec::{
Decode,
Encode,
};
use derivative::Derivative;
use std::sync::Arc;

Expand Down Expand Up @@ -89,14 +93,17 @@ impl ClientBuilder {
crate::rpc::ws_client(url).await?
};
let rpc = Rpc::new(client);
let (metadata, genesis_hash, runtime_version, properties) = future::join4(
rpc.metadata(),
rpc.genesis_hash(),
rpc.runtime_version(None),
rpc.system_properties(),
let (metadata_bytes, genesis_hash, runtime_version, properties) = future::join4(
SubxtRpcApiClient::<T>::metadata(rpc.inner()),
SubxtRpcApiClient::<T>::genesis_hash(rpc.inner()),
SubxtRpcApiClient::<T>::runtime_version(rpc.inner(), None),
SubxtRpcApiClient::<T>::system_properties(rpc.inner()),
)
.await;
let metadata = metadata?;
let metadata_bytes = metadata_bytes?;
let meta: frame_metadata::RuntimeMetadataPrefixed =
Decode::decode(&mut &metadata_bytes[..])?;
let metadata: Metadata = meta.try_into()?;

let events_decoder = EventsDecoder::new(metadata.clone());

Expand Down Expand Up @@ -230,8 +237,12 @@ where
// Get a hash of the extrinsic (we'll need this later).
let ext_hash = T::Hashing::hash_of(&extrinsic);

let bytes = extrinsic.encode().into();

// Submit and watch for transaction progress.
let sub = self.client.rpc().watch_extrinsic(extrinsic).await?;
let sub =
SubxtRpcApiClient::<T>::watch_extrinsic(self.client.rpc().inner(), bytes)
.await?;

Ok(TransactionProgress::new(sub, self.client, ext_hash))
}
Expand All @@ -254,8 +265,15 @@ where
<A as AccountData>::AccountId: From<<T as Config>::AccountId>,
<A as AccountData>::Index: Into<<T as Config>::Index>,
{
let extrinsic = self.create_signed(signer, Default::default()).await?;
self.client.rpc().submit_extrinsic(extrinsic).await
let bytes = self
.create_signed(signer, Default::default())
.await?
.encode()
.into();

SubxtRpcApiClient::<T>::submit_extrinsic(self.client.rpc().inner(), bytes)
.await
.map_err(Into::into)
}

/// Creates a signed extrinsic.
Expand Down
Loading