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

Take Bytes parameters as borrow #601

Merged
merged 3 commits into from
Jul 3, 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
24 changes: 12 additions & 12 deletions src/api/rpc_api/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub trait SubmitExtrinsic {

/// Submit an encoded, opaque extrsinic to the substrate node.
/// Returns the extrinsic hash.
async fn submit_opaque_extrinsic(&self, encoded_extrinsic: Bytes) -> Result<Self::Hash>;
async fn submit_opaque_extrinsic(&self, encoded_extrinsic: &Bytes) -> Result<Self::Hash>;
}

#[maybe_async::maybe_async(?Send)]
Expand All @@ -69,10 +69,10 @@ where
Signature: Encode,
SignedExtra: Encode,
{
self.submit_opaque_extrinsic(extrinsic.encode().into()).await
self.submit_opaque_extrinsic(&extrinsic.encode().into()).await
}

async fn submit_opaque_extrinsic(&self, encoded_extrinsic: Bytes) -> Result<Self::Hash> {
async fn submit_opaque_extrinsic(&self, encoded_extrinsic: &Bytes) -> Result<Self::Hash> {
let hex_encoded_xt = rpc_params![encoded_extrinsic];
debug!("sending extrinsic: {:?}", hex_encoded_xt);
let xt_hash = self.client().request("author_submitExtrinsic", hex_encoded_xt).await?;
Expand Down Expand Up @@ -101,7 +101,7 @@ pub trait SubmitAndWatch {
/// watch the extrinsic progress.
async fn submit_and_watch_opaque_extrinsic(
&self,
encoded_extrinsic: Bytes,
encoded_extrinsic: &Bytes,
) -> Result<TransactionSubscriptionFor<Self::Client, Self::Hash>>;

/// Submit an extrinsic and watch it until the desired status
Expand Down Expand Up @@ -133,7 +133,7 @@ pub trait SubmitAndWatch {
/// This method is blocking.
async fn submit_and_watch_opaque_extrinsic_until(
&self,
encoded_extrinsic: Bytes,
encoded_extrinsic: &Bytes,
watch_until: XtStatus,
) -> Result<ExtrinsicReport<Self::Hash>>;
}
Expand Down Expand Up @@ -176,7 +176,7 @@ pub trait SubmitAndWatchUntilSuccess {
/// This method is blocking.
async fn submit_and_watch_opaque_extrinsic_until_success(
&self,
encoded_extrinsic: Bytes,
encoded_extrinsic: &Bytes,
wait_for_finalized: bool,
) -> Result<ExtrinsicReport<Self::Hash>>;
}
Expand All @@ -200,12 +200,12 @@ where
Signature: Encode,
SignedExtra: Encode,
{
self.submit_and_watch_opaque_extrinsic(extrinsic.encode().into()).await
self.submit_and_watch_opaque_extrinsic(&extrinsic.encode().into()).await
}

async fn submit_and_watch_opaque_extrinsic(
&self,
encoded_extrinsic: Bytes,
encoded_extrinsic: &Bytes,
) -> Result<TransactionSubscriptionFor<Self::Client, Self::Hash>> {
self.client()
.subscribe(
Expand All @@ -227,13 +227,13 @@ where
Signature: Encode,
SignedExtra: Encode,
{
self.submit_and_watch_opaque_extrinsic_until(extrinsic.encode().into(), watch_until)
self.submit_and_watch_opaque_extrinsic_until(&extrinsic.encode().into(), watch_until)
.await
}

async fn submit_and_watch_opaque_extrinsic_until(
&self,
encoded_extrinsic: Bytes,
encoded_extrinsic: &Bytes,
watch_until: XtStatus,
) -> Result<ExtrinsicReport<Self::Hash>> {
let tx_hash = T::Hasher::hash_of(&encoded_extrinsic.0);
Expand Down Expand Up @@ -285,15 +285,15 @@ where
SignedExtra: Encode,
{
self.submit_and_watch_opaque_extrinsic_until_success(
extrinsic.encode().into(),
&extrinsic.encode().into(),
wait_for_finalized,
)
.await
}

async fn submit_and_watch_opaque_extrinsic_until_success(
&self,
encoded_extrinsic: Bytes,
encoded_extrinsic: &Bytes,
wait_for_finalized: bool,
) -> Result<ExtrinsicReport<Self::Hash>> {
let xt_status = match wait_for_finalized {
Expand Down
8 changes: 4 additions & 4 deletions src/api/rpc_api/pallet_transaction_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ pub trait GetTransactionPayment {

async fn get_fee_details(
&self,
encoded_extrinsic: Bytes,
encoded_extrinsic: &Bytes,
at_block: Option<Self::Hash>,
) -> Result<Option<FeeDetails<Self::Balance>>>;

async fn get_payment_info(
&self,
encoded_extrinsic: Bytes,
encoded_extrinsic: &Bytes,
at_block: Option<Self::Hash>,
) -> Result<Option<RuntimeDispatchInfo<Self::Balance>>>;
}
Expand All @@ -50,7 +50,7 @@ where

async fn get_fee_details(
&self,
encoded_extrinsic: Bytes,
encoded_extrinsic: &Bytes,
at_block: Option<Self::Hash>,
) -> Result<Option<FeeDetails<Self::Balance>>> {
let details: Option<FeeDetails<NumberOrHex>> = self
Expand All @@ -67,7 +67,7 @@ where

async fn get_payment_info(
&self,
encoded_extrinsic: Bytes,
encoded_extrinsic: &Bytes,
at_block: Option<Self::Hash>,
) -> Result<Option<RuntimeDispatchInfo<Self::Balance>>> {
let res = self
Expand Down
5 changes: 3 additions & 2 deletions testing/examples/pallet_transaction_payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ async fn main() {

// Tests
let _fee_details = api
.get_fee_details(encoded_xt.clone().into(), Some(block_hash))
.get_fee_details(&encoded_xt.clone().into(), Some(block_hash))
.unwrap()
.unwrap();
let _payment_info = api.get_payment_info(encoded_xt.into(), Some(block_hash)).unwrap().unwrap();
let _payment_info =
api.get_payment_info(&encoded_xt.into(), Some(block_hash)).unwrap().unwrap();
}