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

Fix reported extrinsic hash #629

Merged
merged 5 commits into from
Jul 25, 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
1 change: 0 additions & 1 deletion examples/examples/check_extrinsic_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ async fn main() {
println!("[+] Extrinsic with hash {extrinsic_hash:?} was successfully executed.",);
println!("[+] Extrinsic got included in block with hash {block_hash:?}");
println!("[+] Watched extrinsic until it reached the status {extrinsic_status:?}");
println!("[+] The following events were thrown when the extrinsic was executed: {extrinsic_events:?}");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this line because the printing was way too verbose.


assert!(matches!(extrinsic_status, TransactionStatus::InBlock(_block_hash)));
assert_associated_events_match_expected(extrinsic_events);
Expand Down
2 changes: 1 addition & 1 deletion src/api/rpc_api/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ where
encoded_extrinsic: &Bytes,
watch_until: XtStatus,
) -> Result<ExtrinsicReport<Self::Hash>> {
let tx_hash = T::Hasher::hash_of(&encoded_extrinsic.0);
let tx_hash = T::Hasher::hash(encoded_extrinsic);
let mut subscription: TransactionSubscriptionFor<Self::Client, Self::Hash> =
self.submit_and_watch_opaque_extrinsic(encoded_extrinsic).await?;

Expand Down
10 changes: 5 additions & 5 deletions src/api/rpc_api/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use ac_compose_macros::rpc_params;
use ac_node_api::{metadata::Metadata, EventDetails, EventRecord, Events, Phase};
use ac_primitives::config::Config;
use alloc::{vec, vec::Vec};
use codec::{Decode, Encode};
use codec::Decode;
use core::marker::PhantomData;
use log::*;
use serde::de::DeserializeOwned;
Expand Down Expand Up @@ -194,7 +194,7 @@ where
.extrinsics()
.iter()
.position(|xt| {
let xt_hash = T::Hasher::hash_of(&xt.encode());
let xt_hash = T::Hasher::hash_of(&xt);
trace!("Looking for: {:?}, got xt_hash {:?}", extrinsic_hash, xt_hash);
extrinsic_hash == xt_hash
})
Expand Down Expand Up @@ -379,9 +379,9 @@ mod tests {
let xt2: Bytes = UncheckedExtrinsic::new_unsigned(call2).encode().into();
let xt3: Bytes = UncheckedExtrinsic::new_unsigned(call3).encode().into();

let xt_hash1 = <DefaultRuntimeConfig as Config>::Hasher::hash_of(&xt1.0);
let xt_hash2 = <DefaultRuntimeConfig as Config>::Hasher::hash_of(&xt2.0);
let xt_hash3 = <DefaultRuntimeConfig as Config>::Hasher::hash_of(&xt3.0);
let xt_hash1 = <DefaultRuntimeConfig as Config>::Hasher::hash(&xt1);
let xt_hash2 = <DefaultRuntimeConfig as Config>::Hasher::hash(&xt2);
let xt_hash3 = <DefaultRuntimeConfig as Config>::Hasher::hash(&xt3);

let block = Block { header: default_header(), extrinsics: vec![xt1, xt2, xt3] };
let signed_block = SignedBlock { block, justifications: None };
Expand Down
3 changes: 3 additions & 0 deletions testing/examples/author_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//! Tests for the author rpc interface functions.

use kitchensink_runtime::AccountId;
use sp_core::{Encode, H256};
use sp_keyring::AccountKeyring;
use std::{thread, time::Duration};
use substrate_api_client::{
Expand Down Expand Up @@ -66,7 +67,9 @@ async fn main() {
// Test different _watch_untils with events
thread::sleep(Duration::from_secs(6)); // Wait a little to avoid transaction too low priority error.
let xt2 = api.balance_transfer_allow_death(bob.clone(), 1000);
let extrinsic_hash: H256 = sp_core::blake2_256(&xt2.encode()).into();
let report = api.submit_and_watch_extrinsic_until(xt2, XtStatus::Ready).unwrap();
assert_eq!(extrinsic_hash, report.extrinsic_hash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

assert!(report.block_hash.is_none());
assert!(matches!(report.status, TransactionStatus::Ready));
assert!(report.events.is_none());
Expand Down