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

Update api-client to tag v0.12 #328

Merged
merged 3 commits into from
Jun 14, 2023
Merged
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
253 changes: 38 additions & 215 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pallet-encointer-communities = { git = "https://github.com/encointer/pallets", b
pallet-encointer-scheduler = { git = "https://github.com/encointer/pallets", branch = "polkadot-v0.9.42" }

# scs deps
substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.10.0" }
substrate-client-keystore = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.10.0" }
substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42" }
substrate-client-keystore = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42" }

# substrate deps
frame-support = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
Expand Down
4 changes: 2 additions & 2 deletions client/encointer-api-client-extension/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ encointer-ceremonies-assignment = { git = "https://github.com/encointer/pallets"
encointer-node-notee-runtime = { path = "../../runtime" }
encointer-primitives = { git = "https://github.com/encointer/pallets", branch = "polkadot-v0.9.42" }

substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.10.0", features = ["ws-client"] }
substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42", features = ["ws-client"] }
# scs deps
substrate-client-keystore = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.10.0" }
substrate-client-keystore = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42" }

# substrate deps
sp-core = { version = "7.0.0", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
Expand Down
2 changes: 1 addition & 1 deletion client/encointer-api-client-extension/src/ceremonies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl CeremoniesApi for Api {
}

fn get_meetup_time_offset(&self) -> Result<Option<MeetupTimeOffsetType>> {
self.get_storage_value(ENCOINTER_CEREMONIES, "MeetupTimeOffset", None)
self.get_storage(ENCOINTER_CEREMONIES, "MeetupTimeOffset", None)
}

fn get_meetup_time(&self, location: Location, one_day: Moment) -> Result<Moment> {
Expand Down
2 changes: 1 addition & 1 deletion client/encointer-api-client-extension/src/communities.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{Api, Result};
use encointer_primitives::communities::{CommunityIdentifier, Location};
use substrate_api_client::{rpc::Request, rpc_params};
use substrate_api_client::{ac_compose_macros::rpc_params, rpc::Request};

pub trait CommunitiesApi {
fn get_locations(&self, cid: CommunityIdentifier) -> Result<Vec<Location>>;
Expand Down
16 changes: 10 additions & 6 deletions client/encointer-api-client-extension/src/extrinsic_params.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
use crate::ExtrinsicAddress;
use codec::{Decode, Encode};
use encointer_node_notee_runtime::{Address, Hash, Index, Signature};
use encointer_node_notee_runtime::{Hash, Index, Signature};
use encointer_primitives::communities::CommunityIdentifier;
use substrate_api_client::{
use substrate_api_client::ac_primitives::{
GenericAdditionalParams, GenericExtrinsicParams, GenericSignedExtra, UncheckedExtrinsicV4,
};

/// A struct representing the signed extra and additional parameters required
/// to construct a transaction and pay in asset fees
pub type CommunityCurrencyTipExtrinsicParams =
GenericExtrinsicParams<CommunityCurrencyTip, Index, Hash>;
pub type CommunityCurrencyTipExtrinsicParams<T> = GenericExtrinsicParams<T, CommunityCurrencyTip>;
/// A builder which leads to [`CommunityCurrencyTipExtrinsicParams`] being constructed.
/// This is what you provide to methods like `sign_and_submit()`.
pub type CommunityCurrencyTipExtrinsicParamsBuilder =
GenericAdditionalParams<CommunityCurrencyTip, Hash>;

pub type EncointerXt<Call> =
UncheckedExtrinsicV4<Address, Call, Signature, GenericSignedExtra<CommunityCurrencyTip, Index>>;
pub type EncointerXt<Call> = UncheckedExtrinsicV4<
ExtrinsicAddress,
Call,
Signature,
GenericSignedExtra<CommunityCurrencyTip, Index>,
>;

/// A tip payment made in the form of a specific asset.
#[derive(Copy, Clone, Debug, Default, Decode, Encode, Eq, PartialEq)]
Expand Down
25 changes: 13 additions & 12 deletions client/encointer-api-client-extension/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
use sp_runtime::{AccountId32 as AccountId, MultiSignature};
use substrate_api_client::{rpc::WsRpcClient, SignExtrinsic, StaticExtrinsicSigner};
use extrinsic_params::CommunityCurrencyTipExtrinsicParams;
use substrate_api_client::{
ac_primitives::{Config, ExtrinsicSigner, SubstrateKitchensinkConfig, WithExtrinsicParams},
rpc::WsRpcClient,
};

pub use encointer_node_notee_runtime::Runtime;
pub use substrate_api_client::{api::error::Error as ApiClientError, Result};

pub use encointer_node_notee_runtime::Runtime;
pub type EncointerConfig = WithExtrinsicParams<
SubstrateKitchensinkConfig,
clangenb marked this conversation as resolved.
Show resolved Hide resolved
CommunityCurrencyTipExtrinsicParams<SubstrateKitchensinkConfig>,
>;

pub type ParentchainExtrinsicSigner = StaticExtrinsicSigner<sp_core::sr25519::Pair, MultiSignature>;
pub type ExtrinsicAddress =
<ParentchainExtrinsicSigner as SignExtrinsic<AccountId>>::ExtrinsicAddress;
pub type Api = substrate_api_client::Api<EncointerConfig, WsRpcClient>;

pub type Api = substrate_api_client::Api<
ParentchainExtrinsicSigner,
WsRpcClient,
extrinsic_params::CommunityCurrencyTipExtrinsicParams,
Runtime,
>;
pub type ParentchainExtrinsicSigner = ExtrinsicSigner<SubstrateKitchensinkConfig>;
pub type ExtrinsicAddress = <EncointerConfig as Config>::Address;

pub use ceremonies::*;
pub use communities::*;
Expand Down
4 changes: 2 additions & 2 deletions client/encointer-api-client-extension/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ pub trait SchedulerApi {

impl SchedulerApi for Api {
fn get_current_phase(&self) -> Result<CeremonyPhaseType> {
self.get_storage_value("EncointerScheduler", "CurrentPhase", None)?
self.get_storage("EncointerScheduler", "CurrentPhase", None)?
.ok_or_else(|| ApiClientError::Other("Couldn't get CurrentPhase".into()))
}

fn get_next_phase_timestamp(&self) -> Result<Moment> {
self.get_storage_value("EncointerScheduler", "NextPhaseTimestamp", None)?
self.get_storage("EncointerScheduler", "NextPhaseTimestamp", None)?
.ok_or_else(|| ApiClientError::Other("Couldn't get NextPhaseTimestamp".into()))
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/community_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use encointer_primitives::{
};
use geojson::GeoJson;
use log::{debug, info};
use substrate_api_client::{compose_call, Metadata};
use substrate_api_client::{ac_compose_macros::compose_call, ac_node_api::Metadata};

pub fn read_community_spec_from_file(path: &str) -> serde_json::Value {
let spec_str = std::fs::read_to_string(path).unwrap();
Expand Down
39 changes: 13 additions & 26 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ use encointer_api_client_extension::{
ParentchainExtrinsicSigner, SchedulerApi, ENCOINTER_CEREMONIES,
};
use encointer_node_notee_runtime::{
AccountId, BalanceEntry, BalanceType, BlockNumber, Hash, Header, Moment, RuntimeEvent,
Signature, ONE_DAY,
AccountId, BalanceEntry, BalanceType, BlockNumber, Hash, Moment, RuntimeEvent, Signature,
ONE_DAY,
};
use encointer_primitives::{
balances::Demurrage,
Expand All @@ -67,13 +67,13 @@ use sp_keystore::Keystore;
use sp_runtime::MultiSignature;
use std::{collections::HashMap, path::PathBuf, str::FromStr};
use substrate_api_client::{
ac_compose_macros::{compose_call, compose_extrinsic, compose_extrinsic_offline, rpc_params},
ac_primitives::{Bytes, SignExtrinsic},
api::error::Error as ApiClientError,
compose_call, compose_extrinsic, compose_extrinsic_offline,
extrinsic::BalancesExtrinsics,
rpc::{Request, WsRpcClient},
rpc_params, Bytes, Events, GetAccountInformation, GetBalance, GetHeader, GetStorage,
GetTransactionPayment, Metadata as ApiClientMetadata, Result as ApiResult, SignExtrinsic,
SubmitAndWatch, SubscribeEvents, XtStatus,
GetAccountInformation, GetBalance, GetChainInfo, GetStorage, GetTransactionPayment,
Result as ApiResult, SubmitAndWatch, SubscribeEvents, XtStatus,
};
use substrate_client_keystore::{KeystoreExt, LocalKeystore};

Expand Down Expand Up @@ -181,8 +181,7 @@ fn main() {
.description("query node metadata and print it as json to stdout")
.runner(|_args: &str, matches: &ArgMatches<'_>| {
let api = get_chain_api(matches);
let meta = api.metadata();
println!("Metadata:\n {}", ApiClientMetadata::pretty_format(&meta.metadata).unwrap());
println!("Metadata:\n {}", api.metadata().pretty_format().unwrap());
Ok(())
}),
)
Expand Down Expand Up @@ -1610,7 +1609,7 @@ fn listen(matches: &ArgMatches<'_>) {
{
return
};
let event_results = subscription.next_event::<RuntimeEvent, Hash>().unwrap();
let event_results = subscription.next_events::<RuntimeEvent, Hash>().unwrap();
blocks += 1;
match event_results {
Ok(evts) =>
Expand Down Expand Up @@ -1687,19 +1686,7 @@ fn listen(matches: &ArgMatches<'_>) {
dispatch_error: _,
dispatch_info: _,
} => {
let event_records = vec![evr];

let decoded_event = Events::new(
api.metadata().clone(),
Hash::default(),
event_records.encode(),
)
.iter()
.next()
.unwrap()
.unwrap();

error!("ExtrinsicFailed: {:?}", decoded_event);
error!("ExtrinsicFailed: {ee:?}");
clangenb marked this conversation as resolved.
Show resolved Hide resolved
},
frame_system::Event::ExtrinsicSuccess { dispatch_info } => {
println!("ExtrinsicSuccess: {dispatch_info:?}");
Expand Down Expand Up @@ -1734,7 +1721,7 @@ fn verify_cid(api: &Api, cid: &str, maybe_at: Option<Hash>) -> CommunityIdentifi
}

fn get_block_number(api: &Api, maybe_at: Option<Hash>) -> BlockNumber {
let hdr: Header = api.get_header(maybe_at).unwrap().unwrap();
let hdr = api.get_header(maybe_at).unwrap().unwrap();
debug!("decoded: {:?}", hdr);
//let hdr: Header= Decode::decode(&mut .as_bytes()).unwrap();
hdr.number
Expand Down Expand Up @@ -1794,7 +1781,7 @@ fn get_demurrage_per_block(api: &Api, cid: CommunityIdentifier) -> Demurrage {
}

fn get_ceremony_index(api: &Api) -> CeremonyIndexType {
api.get_storage_value("EncointerScheduler", "CurrentCeremonyIndex", None)
api.get_storage("EncointerScheduler", "CurrentCeremonyIndex", None)
.unwrap()
.unwrap()
}
Expand Down Expand Up @@ -1857,7 +1844,7 @@ fn get_community_identifiers(
api: &Api,
maybe_at: Option<Hash>,
) -> Option<Vec<CommunityIdentifier>> {
api.get_storage_value("EncointerCommunities", "CommunityIdentifiers", maybe_at)
api.get_storage("EncointerCommunities", "CommunityIdentifiers", maybe_at)
.unwrap()
}

Expand Down Expand Up @@ -2048,7 +2035,7 @@ fn get_bootstrappers_with_remaining_newbie_tickets(
cid: CommunityIdentifier,
) -> Result<Vec<BootstrapperWithTickets>, ApiClientError> {
let total_newbie_tickets: u8 = api
.get_storage_value("EncointerCeremonies", "EndorsementTicketsPerBootstrapper", None)
.get_storage("EncointerCeremonies", "EndorsementTicketsPerBootstrapper", None)
.unwrap()
.unwrap();

Expand Down
11 changes: 7 additions & 4 deletions client/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ use log::{debug, error, info};
use sp_core::H256;
use sp_runtime::traits::Convert;
use substrate_api_client::{
api::error::Error as ApiClientError, compose_call, compose_extrinsic_offline, Bytes,
GetAccountInformation, GetBalance, GetStorage, GetTransactionPayment, Metadata, Result,
SubmitAndWatch, XtStatus,
ac_compose_macros::{compose_call, compose_extrinsic_offline},
ac_node_api::Metadata,
ac_primitives::Bytes,
api::error::Error as ApiClientError,
GetAccountInformation, GetBalance, GetStorage, GetTransactionPayment, Result, SubmitAndWatch,
XtStatus,
};
/// Wrapper around the `compose_extrinsic_offline!` macro to be less verbose.
pub fn offline_xt<C: Encode + Clone>(api: &Api, call: C, nonce: u32) -> EncointerXt<C> {
Expand Down Expand Up @@ -57,7 +60,7 @@ pub fn collective_propose_call<Proposal: Encode>(
)
}
pub fn get_councillors(api: &Api) -> Result<Vec<AccountId>> {
api.get_storage_value("Membership", "Members", None)?
api.get_storage("Membership", "Members", None)?
.ok_or_else(|| ApiClientError::Other("Couldn't get councillors".into()))
}

Expand Down