Skip to content

Commit

Permalink
Removed unnecessary rustfmt files. Copied fmt settings from PolkadotSDK
Browse files Browse the repository at this point in the history
  • Loading branch information
markopoloparadox committed Sep 11, 2023
1 parent 568a08f commit 7538a9b
Show file tree
Hide file tree
Showing 74 changed files with 2,482 additions and 2,848 deletions.
10 changes: 0 additions & 10 deletions .rustfmt.toml

This file was deleted.

10 changes: 0 additions & 10 deletions avail-subxt/.rustfmt.toml

This file was deleted.

5 changes: 2 additions & 3 deletions avail-subxt/examples/create_app_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ async fn main() -> Result<()> {
let signer_a = PairSigner::<AvailConfig, sr25519::Pair>::new(pair_a.0);

let app_id = b"my_app_name".to_vec();
let create_application_key = api::tx()
.data_availability()
.create_application_key(BoundedVec(app_id));
let create_application_key =
api::tx().data_availability().create_application_key(BoundedVec(app_id));

let params = AvailExtrinsicParams::default();

Expand Down
7 changes: 2 additions & 5 deletions avail-subxt/examples/da_bridge_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ async fn main() -> Result<()> {
.block_hash();

// Get block
let submitted_block = client
.rpc()
.block(Some(block_hash))
.await?
.expect("Block exists .qed");
let submitted_block =
client.rpc().block(Some(block_hash)).await?.expect("Block exists .qed");

let xts = submitted_block.block.extrinsics;
println!("Submitted block extrinsic: {xts:?}");
Expand Down
78 changes: 17 additions & 61 deletions avail-subxt/examples/democracy_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,12 @@ mod council {
log::info!("Inner call pre-image hash {}", noted_event.hash);

// 2. Push the coucil proposal: external propose on democracy.
let proposal = Bounded::Lookup {
hash: noted_event.hash,
len: inner_call_len,
};
let proposal = Bounded::Lookup { hash: noted_event.hash, len: inner_call_len };
let democracy_external_prop =
Call::Democracy(DemocracyCall::external_propose_majority { proposal });
let len_bound = democracy_external_prop.encode().len() as u32;
let council_proposal =
api::tx()
.council()
.propose(THREASHOLD, democracy_external_prop, len_bound);
api::tx().council().propose(THREASHOLD, democracy_external_prop, len_bound);

let event = tx_send!(client, &council_proposal, &signer)
.find_first::<CouncilEvent::Proposed>()?
Expand All @@ -107,9 +102,7 @@ mod council {
signer: &PairSigner,
proposal: &IndexedProposalContext,
) -> Result<TxProgress> {
let vote = api::tx()
.council()
.vote(proposal.hash, proposal.index, true);
let vote = api::tx().council().vote(proposal.hash, proposal.index, true);
tx_asend!(client, &vote, signer).map_err(Into::into)
}

Expand All @@ -119,10 +112,8 @@ mod council {
) -> Result<()> {
log::trace!("Council will vote proposal using 3/4 of council ...");

let super_majority = COUNCIL_SUPER_MAJORITY
.into_iter()
.map(signer_from_seed)
.collect::<Vec<_>>();
let super_majority =
COUNCIL_SUPER_MAJORITY.into_iter().map(signer_from_seed).collect::<Vec<_>>();

let pending_txs = stream::iter(super_majority.iter())
.map(|signer| vote_yes(client, signer, proposal))
Expand All @@ -131,10 +122,7 @@ mod council {
.await?;

for tx in pending_txs {
log::trace!(
"Waiting for `Ayes` voting finalization of {}",
tx.extrinsic_hash()
);
log::trace!("Waiting for `Ayes` voting finalization of {}", tx.extrinsic_hash());
let _ = tx.wait_for_in_block().await?;
}
Ok(())
Expand All @@ -143,24 +131,15 @@ mod council {
pub async fn close(client: &Client, proposal: &IndexedProposalContext) -> Result<()> {
log::trace!("Closing the council proposal ...");

let close_weight = Weight {
ref_time: 1_000_000_000,
proof_size: 0,
};
let close_weight = Weight { ref_time: 1_000_000_000, proof_size: 0 };
let close =
api::tx()
.council()
.close(proposal.hash, proposal.index, close_weight, proposal.len);
let events = tx_send!(client, &close, &PairSigner::new(Alice.pair()));

ensure!(
events.has::<CouncilEvent::Closed>()?,
"Proposal was not closed"
);
ensure!(
events.has::<CouncilEvent::Approved>()?,
"Proposal was not approved"
);
ensure!(events.has::<CouncilEvent::Closed>()?, "Proposal was not closed");
ensure!(events.has::<CouncilEvent::Approved>()?, "Proposal was not approved");

let executed = events
.find_first::<CouncilEvent::Executed>()?
Expand Down Expand Up @@ -192,29 +171,21 @@ mod techies {
});
let fast_track_len = fast_track.encode().len() as u32;

let call = api::tx()
.technical_committee()
.propose(5, fast_track, fast_track_len);
let call = api::tx().technical_committee().propose(5, fast_track, fast_track_len);

let event = tx_send!(client, &call, &signer)
.find_first::<TechComEvent::Proposed>()?
.expect("Techies proposed event is emitted .qed");

Ok(IndexedProposalContext::new(
event.proposal_index,
event.proposal_hash,
fast_track_len,
))
Ok(IndexedProposalContext::new(event.proposal_index, event.proposal_hash, fast_track_len))
}

async fn vote_yes(
client: &Client,
signer: &PairSigner,
proposal: &IndexedProposalContext,
) -> Result<TxProgress> {
let vote = api::tx()
.technical_committee()
.vote(proposal.hash, proposal.index, true);
let vote = api::tx().technical_committee().vote(proposal.hash, proposal.index, true);
tx_asend!(client, &vote, signer).map_err(Into::into)
}

Expand All @@ -237,10 +208,7 @@ mod techies {
}

pub async fn close(client: &Client, proposal: &IndexedProposalContext) -> Result<u32> {
let close_weight = Weight {
ref_time: 1_000_000_000,
proof_size: 0,
};
let close_weight = Weight { ref_time: 1_000_000_000, proof_size: 0 };
log::info!("Proposal to close {:?}", proposal);
let close = api::tx().technical_committee().close(
proposal.hash,
Expand All @@ -249,19 +217,10 @@ mod techies {
proposal.len,
);
let events = tx_send!(client, &close, &PairSigner::new(Alice.pair()));
ensure!(
events.has::<TechComEvent::Approved>()?,
"Fast-track proposal was not approved"
);
ensure!(
events.has::<TechComEvent::Executed>()?,
"Fast-track proposal was not executed"
);
ensure!(events.has::<TechComEvent::Approved>()?, "Fast-track proposal was not approved");
ensure!(events.has::<TechComEvent::Executed>()?, "Fast-track proposal was not executed");
let block_events = events.all_events_in_block();
ensure!(
block_events.has::<DemocracyEvent::Started>()?,
"Referendum was not started"
);
ensure!(block_events.has::<DemocracyEvent::Started>()?, "Referendum was not started");
let referendum_started = block_events
.find_first::<DemocracyEvent::Started>()?
.expect("Referendum was started .qed");
Expand Down Expand Up @@ -291,10 +250,7 @@ mod democracy {
let vote_call = api::tx().democracy().vote(referendum, vote);

let events = tx_send!(client, &vote_call, &signer);
ensure!(
events.has::<DemocracyEvent::Voted>()?,
"Referendum's Vote failed"
);
ensure!(events.has::<DemocracyEvent::Voted>()?, "Referendum's Vote failed");

Ok(())
}
Expand Down
12 changes: 2 additions & 10 deletions avail-subxt/examples/download_digest_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ async fn main() -> Result<()> {
let client = build_client(args.ws, args.validate_codegen).await?;

// Get best block
let best_block = client
.rpc()
.block(None)
.await?
.expect("Best block always exists .qed");
let best_block = client.rpc().block(None).await?.expect("Best block always exists .qed");

let best_block_num = best_block.block.header.number;

Expand All @@ -114,11 +110,7 @@ async fn main() -> Result<()> {

// Load all headers and decode each digest item.
for block_num in 1..=best_block_num {
let block_hash = client
.rpc()
.block_hash(Some(block_num.into()))
.await?
.unwrap();
let block_hash = client.rpc().block_hash(Some(block_num.into())).await?.unwrap();
let header = client.rpc().header(Some(block_hash)).await?.unwrap();

let digests = header
Expand Down
48 changes: 14 additions & 34 deletions avail-subxt/examples/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,25 @@ async fn main() -> Result<()> {
let args = Opts::from_args();
let client = build_client(args.ws, args.validate_codegen).await?;

let head_block = client
.rpc()
.block(None)
.await?
.expect("Best block always exists .qed");
let head_block = client.rpc().block(None).await?.expect("Best block always exists .qed");

let block_num = head_block.block.header.number;
println!("Current head: {block_num}");
println!(
"Current head block extrinsic: {block:?}",
block = head_block.block.extrinsics
);
println!(
"Current head block header: {header:?}",
header = head_block.block.header
);
println!("Current head block extrinsic: {block:?}", block = head_block.block.extrinsics);
println!("Current head block header: {header:?}", header = head_block.block.header);

let mut headers = vec![];

for batch in (1u32..=block_num)
.collect::<Vec<_>>()
.chunks(BATCH_NUM)
.map(|e| {
join_all(
e.iter()
.map(|n| {
let block_number = Some(BlockNumber::from(*n));
client
.rpc()
.block_hash(block_number)
.and_then(|h| client.rpc().header(h))
})
.collect::<Vec<_>>(),
)
}) {
for batch in (1u32..=block_num).collect::<Vec<_>>().chunks(BATCH_NUM).map(|e| {
join_all(
e.iter()
.map(|n| {
let block_number = Some(BlockNumber::from(*n));
client.rpc().block_hash(block_number).and_then(|h| client.rpc().header(h))
})
.collect::<Vec<_>>(),
)
}) {
headers.extend(batch.await);
}
println!("Headers: {num}", num = headers.len());
Expand All @@ -62,11 +46,7 @@ async fn main() -> Result<()> {
.collect::<Vec<_>>();
println!("Header hashes: {:?}", header_hashes);

assert_eq!(
headers.len(),
block_num as usize,
"Didn't get the same number of block headers."
);
assert_eq!(headers.len(), block_num as usize, "Didn't get the same number of block headers.");

Ok(())
}
4 changes: 1 addition & 3 deletions avail-subxt/examples/set_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ async fn main() -> Result<()> {
let signer = PairSigner::new(AccountKeyring::Alice.pair());

// crate a new transaction with new updater
let set_updater = api::tx()
.nomad_home()
.set_updater(new_updater.parse().unwrap());
let set_updater = api::tx().nomad_home().set_updater(new_updater.parse().unwrap());

println!("Updating updater...");

Expand Down
36 changes: 9 additions & 27 deletions avail-subxt/examples/submit_block_length_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ const BLOCK_DIM_VALUE: u32 = 32;
/// Sets the block dimensions to default
async fn reset(client: &Client, signer: &PairSigner) -> Result<()> {
log::info!("Resetting block dimensions for further tests");
let block_length_update = Call::DataAvailability(DaCall::submit_block_length_proposal {
rows: 256,
cols: 256,
});
let block_length_update =
Call::DataAvailability(DaCall::submit_block_length_proposal { rows: 256, cols: 256 });
let sudo_call = api::tx().sudo().sudo(block_length_update);
tx_send!(client, &sudo_call, signer);
Ok(())
Expand All @@ -32,9 +30,7 @@ async fn reset(client: &Client, signer: &PairSigner) -> Result<()> {
/// Make `n` data submission transaction
async fn submit_data(client: &Client, signer: &PairSigner, n: u8) -> Result<()> {
let example_data = b"X".repeat(1000).to_vec();
let data_submission = api::tx()
.data_availability()
.submit_data(BoundedVec(example_data));
let data_submission = api::tx().data_availability().submit_data(BoundedVec(example_data));
for _ in 0..n {
tx_asend!(client, &data_submission, signer)?;
}
Expand Down Expand Up @@ -88,9 +84,7 @@ pub async fn batch_tx(client: &Client, signer: &PairSigner) -> Result<()> {
rows: BLOCK_DIM_VALUE,
cols: BLOCK_DIM_VALUE,
});
let sudo_call = Call::Sudo(SudoCall::sudo {
call: Box::new(block_length_update),
});
let sudo_call = Call::Sudo(SudoCall::sudo { call: Box::new(block_length_update) });
let batch_call = api::tx().utility().batch(vec![sudo_call]);
tx_send!(client, &batch_call, signer)
.find_first::<DaEvent::BlockLengthProposalSubmitted>()?
Expand All @@ -114,14 +108,9 @@ pub async fn fail_simple_tx(client: &Client, signer: &PairSigner) -> Result<()>
let event = events
.find_first::<SudoEvent::Sudid>()?
.expect("1-Fail - Sudid event is emitted .qed");
assert!(event.sudo_result.is_err(), "1-Fail - BlockLengthProposal was abnormally successful");
assert!(
event.sudo_result.is_err(),
"1-Fail - BlockLengthProposal was abnormally successful"
);
assert!(
events
.find_first::<DaEvent::BlockLengthProposalSubmitted>()?
.is_none(),
events.find_first::<DaEvent::BlockLengthProposalSubmitted>()?.is_none(),
"1-Fail - BlockLengthProposal was abnormally successful"
);

Expand All @@ -138,23 +127,16 @@ pub async fn fail_batch_tx(client: &Client, signer: &PairSigner) -> Result<()> {
rows: BLOCK_DIM_VALUE,
cols: BLOCK_DIM_VALUE,
});
let sudo_call = Call::Sudo(SudoCall::sudo {
call: Box::new(block_length_update),
});
let sudo_call = Call::Sudo(SudoCall::sudo { call: Box::new(block_length_update) });
let batch_call = api::tx().utility().batch(vec![sudo_call]);

let events = tx_send!(client, &batch_call, signer);
let event = events
.find_first::<SudoEvent::Sudid>()?
.expect("2-Fail - Sudid event is emitted .qed");
assert!(event.sudo_result.is_err(), "2-Fail - BlockLengthProposal was abnormally successful");
assert!(
event.sudo_result.is_err(),
"2-Fail - BlockLengthProposal was abnormally successful"
);
assert!(
events
.find_first::<DaEvent::BlockLengthProposalSubmitted>()?
.is_none(),
events.find_first::<DaEvent::BlockLengthProposalSubmitted>()?.is_none(),
"2-Fail - BlockLengthProposal was abnormally successful"
);

Expand Down
Loading

0 comments on commit 7538a9b

Please sign in to comment.