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.9.0 #1263

Merged
merged 35 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5852886
update to v0.9.0 tag
haerdib Mar 28, 2023
8610d5f
fix api-types
haerdib Mar 29, 2023
9d9e0f1
some more changes
haerdib Mar 29, 2023
613a711
fix metadata
haerdib Mar 29, 2023
563e525
fix it all
haerdib Mar 29, 2023
9bd6a96
fix submit extrinsic
haerdib Mar 29, 2023
51de119
fix palletteerex api
haerdib Mar 29, 2023
0724b43
one step further
haerdib Mar 29, 2023
0329f1b
some more uptadates
haerdib Mar 30, 2023
d531a65
seems to work
haerdib Mar 30, 2023
f9fee43
oh yes
haerdib Mar 30, 2023
d4e3627
and compiled
haerdib Mar 30, 2023
61b25d4
readd comment
haerdib Mar 30, 2023
9783efe
add comment
haerdib Mar 30, 2023
024aa45
Merge branch 'master' into bh/update-api-client
haerdib Mar 30, 2023
4b83866
cargo fmt
haerdib Mar 30, 2023
0897e00
taplo fmt
haerdib Mar 30, 2023
0baf347
fix rpc-client mock
haerdib Mar 30, 2023
f34d37c
fix tests
haerdib Mar 30, 2023
924c99e
fix clippy
haerdib Mar 30, 2023
e7bca27
fix clippy
haerdib Mar 30, 2023
d9b068d
fix teeracle
haerdib Mar 30, 2023
8e05322
fix teeracel
haerdib Mar 30, 2023
20d7b6e
fix clippy
haerdib Mar 30, 2023
d38eed0
lets try
haerdib Mar 30, 2023
b28f1ae
lets try that
haerdib Mar 30, 2023
9939687
simplify account.rs
haerdib Apr 3, 2023
e4fab74
simplfy pallet teerex
haerdib Apr 3, 2023
dc9727c
simplify signedblock
haerdib Apr 3, 2023
62683cd
remove clone
haerdib Apr 3, 2023
67c621e
fmt
haerdib Apr 3, 2023
001f90d
fix clippy
haerdib Apr 3, 2023
668a60d
Merge branch 'master' into bh/update-api-client
haerdib Apr 3, 2023
f47bb1a
clean SignedBlock
haerdib Apr 3, 2023
668159d
Merge branch 'master' into bh/update-api-client
haerdib Apr 3, 2023
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
501 changes: 443 additions & 58 deletions Cargo.lock
haerdib marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ ws = { version = "0.9.1", features = ["ssl"] }
# scs / integritee
my-node-runtime = { package = "integritee-node-runtime", git = "https://github.com/integritee-network/integritee-node.git", branch = "polkadot-v0.9.39" }
pallet-evm = { optional = true, git = "https://github.com/integritee-network/frontier.git", branch = "polkadot-v0.9.39" }
substrate-api-client = { features = ["ws-client"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" }
substrate-client-keystore = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" }
substrate-api-client = { features = ["ws-client"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" }
substrate-client-keystore = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" }
teerex-primitives = { git = "https://github.com/integritee-network/pallets.git", branch = "polkadot-v0.9.39" }

# substrate dependencies
Expand Down
1 change: 1 addition & 0 deletions cli/src/base_cli/commands/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::{
command_utils::{get_accountid_from_str, get_chain_api},
Cli,
};
use substrate_api_client::GetAccountInformation;

#[derive(Parser)]
pub struct BalanceCommand {
Expand Down
10 changes: 6 additions & 4 deletions cli/src/base_cli/commands/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ use crate::{
command_utils::{get_accountid_from_str, get_chain_api},
Cli,
};
use codec::Encode;
use my_node_runtime::{BalancesCall, RuntimeCall};
use sp_keyring::AccountKeyring;
use sp_runtime::MultiAddress;
use std::vec::Vec;
use substrate_api_client::{compose_extrinsic_offline, UncheckedExtrinsicV4, XtStatus};
use substrate_api_client::{compose_extrinsic_offline, SubmitExtrinsic, UncheckedExtrinsicV4};

const PREFUNDING_AMOUNT: u128 = 1_000_000_000;

Expand All @@ -36,13 +37,14 @@ pub struct FaucetCommand {

impl FaucetCommand {
pub(crate) fn run(&self, cli: &Cli) {
let api = get_chain_api(cli).set_signer(AccountKeyring::Alice.pair());
let mut api = get_chain_api(cli);
api.set_signer(AccountKeyring::Alice.pair());
let mut nonce = api.get_nonce().unwrap();
for account in &self.accounts {
let to = get_accountid_from_str(account);
#[allow(clippy::redundant_clone)]
let xt: UncheckedExtrinsicV4<_, _> = compose_extrinsic_offline!(
api.clone().signer.unwrap(),
api.signer().unwrap(),
RuntimeCall::Balances(BalancesCall::transfer {
dest: MultiAddress::Id(to.clone()),
value: PREFUNDING_AMOUNT
Expand All @@ -51,7 +53,7 @@ impl FaucetCommand {
);
// send and watch extrinsic until finalized
println!("Faucet drips to {} (Alice's nonce={})", to, nonce);
let _blockh = api.send_extrinsic(xt.hex_encode(), XtStatus::Ready).unwrap();
let _blockh = api.submit_extrinsic(xt.encode()).unwrap();
nonce += 1;
}
}
Expand Down
19 changes: 9 additions & 10 deletions cli/src/base_cli/commands/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use base58::ToBase58;
use codec::{Decode, Encode};
use log::*;
use my_node_runtime::{Hash, RuntimeEvent};
use std::{sync::mpsc::channel, vec::Vec};
use substrate_api_client::utils::FromHexString;
use std::vec::Vec;
use substrate_api_client::{rpc::HandleSubscription, SubscribeFrameSystem};

#[derive(Parser)]
pub struct ListenCommand {
Expand All @@ -39,10 +39,9 @@ impl ListenCommand {
println!("{:?} {:?}", self.events, self.blocks);
let api = get_chain_api(cli);
info!("Subscribing to events");
let (events_in, events_out) = channel();
let mut count = 0u32;
let mut blocks = 0u32;
api.subscribe_events(events_in).unwrap();
let mut subscription = api.subscribe_system_events().unwrap();
loop {
if let Some(e) = self.events {
if count >= e {
Expand All @@ -54,13 +53,13 @@ impl ListenCommand {
return
}
};
let event_str = events_out.recv().unwrap();
let _unhex = Vec::from_hex(event_str).unwrap();
let mut _er_enc = _unhex.as_slice();
let _events =
Vec::<frame_system::EventRecord<RuntimeEvent, Hash>>::decode(&mut _er_enc);

let event_bytes = subscription.next().unwrap().unwrap().changes[0].1.clone().unwrap().0;
clangenb marked this conversation as resolved.
Show resolved Hide resolved
let events_result = Vec::<frame_system::EventRecord<RuntimeEvent, Hash>>::decode(
&mut event_bytes.as_slice(),
);
blocks += 1;
match _events {
match events_result {
Ok(evts) =>
for evr in &evts {
println!("decoded: phase {:?} event {:?}", evr.phase, evr.event);
Expand Down
10 changes: 6 additions & 4 deletions cli/src/base_cli/commands/shield_funds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use itp_stf_primitives::types::ShardIdentifier;
use log::*;
use my_node_runtime::Balance;
use sp_core::sr25519 as sr25519_core;
use substrate_api_client::{compose_extrinsic, UncheckedExtrinsicV4, XtStatus};
use substrate_api_client::{compose_extrinsic, SubmitAndWatch, UncheckedExtrinsicV4, XtStatus};

#[derive(Parser)]
pub struct ShieldFundsCommand {
Expand All @@ -46,7 +46,7 @@ pub struct ShieldFundsCommand {

impl ShieldFundsCommand {
pub(crate) fn run(&self, cli: &Cli) {
let chain_api = get_chain_api(cli);
let mut chain_api = get_chain_api(cli);

let shard_opt = match self.shard.from_base58() {
Ok(s) => ShardIdentifier::decode(&mut &s[..]),
Expand All @@ -60,7 +60,7 @@ impl ShieldFundsCommand {

// get the sender
let from = get_pair_from_str(&self.from);
let chain_api = chain_api.set_signer(sr25519_core::Pair::from(from));
chain_api.set_signer(sr25519_core::Pair::from(from));

// get the recipient
let to = get_accountid_from_str(&self.to);
Expand All @@ -78,7 +78,9 @@ impl ShieldFundsCommand {
shard
);

let tx_hash = chain_api.send_extrinsic(xt.hex_encode(), XtStatus::Finalized).unwrap();
let tx_hash = chain_api
.submit_and_watch_extrinsic_until(xt.encode(), XtStatus::Finalized)
.unwrap();
println!("[+] TrustedOperation got finalized. Hash: {:?}\n", tx_hash);
}
}
8 changes: 5 additions & 3 deletions cli/src/base_cli/commands/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ use crate::{
command_utils::{get_accountid_from_str, get_chain_api, *},
Cli,
};
use codec::Encode;
use log::*;
use my_node_runtime::Balance;
use sp_core::{crypto::Ss58Codec, sr25519 as sr25519_core, Pair};
use substrate_api_client::{GenericAddress, XtStatus};
use substrate_api_client::{GenericAddress, GetAccountInformation, SubmitAndWatch, XtStatus};

#[derive(Parser)]
pub struct TransferCommand {
Expand All @@ -42,9 +43,10 @@ impl TransferCommand {
let to_account = get_accountid_from_str(&self.to);
info!("from ss58 is {}", from_account.public().to_ss58check());
info!("to ss58 is {}", to_account.to_ss58check());
let api = get_chain_api(cli).set_signer(sr25519_core::Pair::from(from_account));
let mut api = get_chain_api(cli);
api.set_signer(sr25519_core::Pair::from(from_account));
let xt = api.balance_transfer(GenericAddress::Id(to_account.clone()), self.amount);
let tx_hash = api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock).unwrap();
let tx_hash = api.submit_and_watch_extrinsic_until(xt.encode(), XtStatus::InBlock).unwrap();
println!("[+] TrustedOperation got finalized. Hash: {:?}\n", tx_hash);
let result = api.get_account_data(&to_account).unwrap().unwrap();
println!("balance for {} is now {}", to_account, result.free);
Expand Down
7 changes: 4 additions & 3 deletions cli/src/base_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ fn list_accounts() {
}

fn print_metadata(cli: &Cli) {
let meta = get_chain_api(cli).get_metadata().unwrap();
println!("Metadata:\n {}", Metadata::pretty_format(&meta).unwrap());
let api = get_chain_api(cli);
let meta = api.metadata();
println!("Metadata:\n {}", Metadata::pretty_format(&meta.runtime_metadata()).unwrap());
}

fn print_sgx_metadata(cli: &Cli) {
let worker_api_direct = get_worker_api_direct(cli);
let metadata = worker_api_direct.get_state_metadata().unwrap();
println!("Metadata:\n {}", Metadata::pretty_format(&metadata).unwrap());
println!("Metadata:\n {}", Metadata::pretty_format(metadata.runtime_metadata()).unwrap());
}

fn list_workers(cli: &Cli) {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/command_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(crate) fn get_shielding_key(cli: &Cli) -> Result<Rsa3072PubKey, String> {
pub(crate) fn get_chain_api(cli: &Cli) -> ParentchainApi {
let url = format!("{}:{}", cli.node_url, cli.node_port);
info!("connecting to {}", url);
ParentchainApi::new(WsRpcClient::new(&url)).unwrap()
ParentchainApi::new(WsRpcClient::new(&url).unwrap()).unwrap()
}

pub(crate) fn get_accountid_from_str(account: &str) -> AccountId {
Expand Down
23 changes: 16 additions & 7 deletions cli/src/oracle/commands/add_to_whitelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ use crate::{
command_utils::{get_chain_api, get_pair_from_str, mrenclave_from_base58},
Cli,
};
use codec::Encode;
use itp_node_api::api_client::{ADD_TO_WHITELIST, TEERACLE};
use substrate_api_client::{compose_call, compose_extrinsic, UncheckedExtrinsicV4, XtStatus};
use substrate_api_client::{
compose_call, compose_extrinsic, SubmitAndWatch, UncheckedExtrinsicV4, XtStatus,
};

/// Add a trusted market data source to the on-chain whitelist.
#[derive(Debug, Clone, Parser)]
Expand All @@ -39,21 +42,27 @@ pub struct AddToWhitelistCmd {

impl AddToWhitelistCmd {
pub fn run(&self, cli: &Cli) {
let api = get_chain_api(cli);
let mut api = get_chain_api(cli);
let mrenclave = mrenclave_from_base58(&self.mrenclave);
let from = get_pair_from_str(&self.from);

let market_data_source = self.source.clone();

let api = api.set_signer(from.into());
api.set_signer(from.into());

let call =
compose_call!(api.metadata, TEERACLE, ADD_TO_WHITELIST, market_data_source, mrenclave);
let call = compose_call!(
api.metadata(),
TEERACLE,
ADD_TO_WHITELIST,
market_data_source,
mrenclave
);

// compose the extrinsic
let xt: UncheckedExtrinsicV4<_, _> = compose_extrinsic!(api, "Sudo", "sudo", call);

let tx_hash = api.send_extrinsic(xt.hex_encode(), XtStatus::Finalized).unwrap();
println!("[+] Add to whitelist got finalized. Hash: {:?}\n", tx_hash);
let report =
api.submit_and_watch_extrinsic_until(xt.encode(), XtStatus::Finalized).unwrap();
println!("[+] Add to whitelist got finalized. Hash: {:?}\n", report.extrinsic_hash);
}
}
13 changes: 5 additions & 8 deletions cli/src/oracle/commands/listen_to_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use itp_node_api::api_client::ParentchainApi;
use itp_time_utils::{duration_now, remaining_time};
use log::{debug, info, trace};
use my_node_runtime::{Hash, RuntimeEvent};
use std::{sync::mpsc::channel, time::Duration};
use substrate_api_client::FromHexString;
use std::time::Duration;
use substrate_api_client::{rpc::HandleSubscription, SubscribeFrameSystem};

/// Listen to exchange rate events.
#[derive(Debug, Clone, Parser)]
Expand All @@ -47,16 +47,13 @@ pub fn count_exchange_rate_update_events(api: &ParentchainApi, duration: Duratio
let stop = duration_now() + duration;

//subscribe to events
let (events_in, events_out) = channel();
api.subscribe_events(events_in).unwrap();
let mut subscription = api.subscribe_system_events().unwrap();
let mut count = 0;

while remaining_time(stop).unwrap_or_default() > Duration::ZERO {
let event_str = events_out.recv().unwrap();
let unhex = Vec::from_hex(event_str).unwrap();
let mut event_records_encoded = unhex.as_slice();
let event_bytes = subscription.next().unwrap().unwrap().changes[0].1.clone().unwrap().0;
let events_result = Vec::<frame_system::EventRecord<RuntimeEvent, Hash>>::decode(
&mut event_records_encoded,
&mut event_bytes.as_slice(),
);
if let Ok(events) = events_result {
for event_record in &events {
Expand Down
12 changes: 5 additions & 7 deletions cli/src/oracle/commands/listen_to_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use itp_node_api::api_client::ParentchainApi;
use itp_time_utils::{duration_now, remaining_time};
use log::{debug, info};
use my_node_runtime::{Hash, RuntimeEvent};
use std::{sync::mpsc::channel, time::Duration};
use substrate_api_client::FromHexString;
use std::time::Duration;
use substrate_api_client::{rpc::HandleSubscription, SubscribeFrameSystem};

/// Listen to exchange rate events.
#[derive(Debug, Clone, Parser)]
Expand All @@ -47,14 +47,12 @@ fn count_oracle_update_events(api: &ParentchainApi, duration: Duration) -> Event
let stop = duration_now() + duration;

//subscribe to events
let (events_in, events_out) = channel();
api.subscribe_events(events_in).unwrap();
let mut subscription = api.subscribe_system_events().unwrap();
let mut count = 0;

while remaining_time(stop).unwrap_or_default() > Duration::ZERO {
let events_str = events_out.recv().unwrap();
let events_vec_bytes = Vec::from_hex(events_str).unwrap();
count += report_event_count(&events_vec_bytes);
let event_bytes = subscription.next().unwrap().unwrap().changes[0].1.clone().unwrap().0;
clangenb marked this conversation as resolved.
Show resolved Hide resolved
count += report_event_count(&event_bytes);
}
debug!("Received {} ExchangeRateUpdated event(s) in total", count);
count
Expand Down
27 changes: 16 additions & 11 deletions cli/src/trusted_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use itp_node_api::api_client::TEEREX;
use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue};
use itp_sgx_crypto::ShieldingCryptoEncrypt;
use itp_stf_primitives::types::ShardIdentifier;
use itp_types::{BlockNumber, DirectRequestStatus, Header, TrustedOperationStatus};
use itp_types::{BlockNumber, DirectRequestStatus, TrustedOperationStatus};
use itp_utils::{FromHexPrefixed, ToHexPrefixed};
use log::*;
use my_node_runtime::{AccountId, Hash};
Expand All @@ -38,7 +38,10 @@ use std::{
sync::mpsc::{channel, Receiver},
time::Instant,
};
use substrate_api_client::{compose_extrinsic, StaticEvent, XtStatus};
use substrate_api_client::{
compose_extrinsic, GetHeader, StaticEvent, SubmitAndWatch, SubscribeEvents,
SubscribeFrameSystem, XtStatus,
};
use teerex_primitives::Request;

pub(crate) fn perform_trusted_operation(
Expand Down Expand Up @@ -107,38 +110,40 @@ fn send_request(
trusted_args: &TrustedCli,
trusted_operation: &TrustedOperation,
) -> Option<Vec<u8>> {
let chain_api = get_chain_api(cli);
let mut chain_api = get_chain_api(cli);
let encryption_key = get_shielding_key(cli).unwrap();
let call_encrypted = encryption_key.encrypt(&trusted_operation.encode()).unwrap();

let shard = read_shard(trusted_args).unwrap();

let arg_signer = &trusted_args.xt_signer;
let signer = get_pair_from_str(arg_signer);
let _chain_api = chain_api.set_signer(sr25519_core::Pair::from(signer));
chain_api.set_signer(sr25519_core::Pair::from(signer));

let request = Request { shard, cyphertext: call_encrypted };
let xt = compose_extrinsic!(_chain_api, TEEREX, "call_worker", request);
let xt = compose_extrinsic!(&chain_api, TEEREX, "call_worker", request);

// send and watch extrinsic until block is executed
let block_hash =
_chain_api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock).unwrap().unwrap();
let block_hash = chain_api
.submit_and_watch_extrinsic_until(xt.encode(), XtStatus::InBlock)
.unwrap()
.block_hash
.unwrap();

info!(
"Trusted call extrinsic sent and successfully included in parentchain block with hash {:?}.",
block_hash
);
info!("Waiting for execution confirmation from enclave...");
let (events_in, events_out) = channel();
_chain_api.subscribe_events(events_in).unwrap();
let mut subscription = chain_api.subscribe_system_events().unwrap();

loop {
let ret: ProcessedParentchainBlockArgs =
_chain_api.wait_for_event::<ProcessedParentchainBlockArgs>(&events_out).unwrap();
chain_api.wait_for_event(&mut subscription).unwrap();
haerdib marked this conversation as resolved.
Show resolved Hide resolved
info!("Confirmation of ProcessedParentchainBlock received");
debug!("Expected block Hash: {:?}", block_hash);
debug!("Confirmed stf block Hash: {:?}", ret.block_hash);
match _chain_api.get_header::<Header>(Some(block_hash)) {
match chain_api.get_header(Some(block_hash)) {
Ok(option) => {
match option {
None => {
Expand Down
2 changes: 1 addition & 1 deletion core-primitives/extrinsics-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
# sgx dependencies
sgx_tstd = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true }
sgx_types = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git" }
substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" }
substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" }

# local dependencies
itp-node-api = { path = "../node-api", default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion core-primitives/node-api/api-client-extensions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ sp-finality-grandpa = { git = "https://github.com/paritytech/substrate.git", bra
sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.39" }

# scs
substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.7.0" }
substrate-api-client = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.39-tag-v0.9.0" }

# local deps
itp-api-client-types = { path = "../api-client-types" }
itp-types = { path = "../../types" }

[features]
Expand Down
Loading