Skip to content

Commit

Permalink
refactor: replace hex library
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexD10S committed Dec 13, 2024
1 parent 44ad374 commit fdaaa40
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 23 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ contract-extrinsics = { git = "https://github.com/use-ink/cargo-contract", branc
#contract-transcode = "5.0.0-alpha"
contract-transcode = { git = "https://github.com/use-ink/cargo-contract", branch = "peter/chore-make-types-pub" }
heck = "0.5.0"
hex = { version = "0.4.3", default-features = false }

# parachains
askama = "0.12"
Expand Down
21 changes: 8 additions & 13 deletions crates/pop-cli/src/commands/call/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,16 @@ impl CallChainCommand {
},
};

if self.use_wallet {
// Sign and submit the extrinsic.
// Sign and submit the extrinsic.
let result = if self.use_wallet {
let call_data = xt.encode_call_data(&chain.client.metadata())?;
if let Err(e) =
submit_extrinsic_with_secure_signing(&chain, call_data, &mut cli).await
{
display_message(&e.to_string(), false, &mut cli)?;
break;
}
submit_extrinsic_with_secure_signing(&chain, call_data, &mut cli).await
} else {
// Sign and submit the extrinsic.
if let Err(e) = call.submit_extrinsic(&chain.client, xt, &mut cli).await {
display_message(&e.to_string(), false, &mut cli)?;
break;
}
call.submit_extrinsic(&chain.client, xt, &mut cli).await
};

if let Err(e) = result {
display_message(&e.to_string(), false, &mut cli)?;
}

if !prompt_to_repeat_call ||
Expand Down
1 change: 0 additions & 1 deletion crates/pop-parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ tokio.workspace = true
url.workspace = true

askama.workspace = true
hex.workspace = true
indexmap.workspace = true
reqwest.workspace = true
scale-info.workspace = true
Expand Down
7 changes: 4 additions & 3 deletions crates/pop-parachains/src/call/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::errors::Error;
use params::Param;
use scale_value::stringify::custom_parsers;
use std::fmt::{Display, Formatter};
use subxt::{dynamic::Value, Metadata, OnlineClient, SubstrateConfig};
use subxt::{dynamic::Value, utils::to_hex, Metadata, OnlineClient, SubstrateConfig};

pub mod action;
pub mod params;
Expand Down Expand Up @@ -179,7 +179,7 @@ pub fn parse_dispatchable_arguments(
.map(|(param, raw_param)| {
// Convert sequence parameters to hex if is_sequence
let processed_param = if param.is_sequence && !raw_param.starts_with("0x") {
format!("0x{}", hex::encode(raw_param))
to_hex(&raw_param)
} else {
raw_param
};
Expand All @@ -199,6 +199,7 @@ mod tests {

use crate::{call::tests::POP_NETWORK_TESTNET_URL, set_up_client};
use anyhow::Result;
use sp_core::bytes::from_hex;
use subxt::ext::scale_bits;

#[tokio::test]
Expand Down Expand Up @@ -283,7 +284,7 @@ mod tests {
]
.to_vec();
let addr: Vec<_> =
hex::decode("8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48")
from_hex("8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48")
.unwrap()
.into_iter()
.map(|b| Value::u128(b as u128))
Expand Down
7 changes: 3 additions & 4 deletions crates/pop-parachains/src/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{errors::Error, Function};
use pop_common::create_signer;
use sp_core::bytes::from_hex;
use sp_core::bytes::{from_hex, to_hex};
use subxt::{
dynamic::Value,
tx::{DynamicPayload, Payload, SubmittableExtrinsic},
Expand Down Expand Up @@ -99,16 +99,15 @@ pub fn encode_call_data(
let call_data = xt
.encode_call_data(&client.metadata())
.map_err(|e| Error::CallDataEncodingError(e.to_string()))?;
Ok(format!("0x{}", hex::encode(call_data)))
Ok(to_hex(&call_data, false))
}

/// Decodes a hex-encoded string into a vector of bytes representing the call data.
///
/// # Arguments
/// * `call_data` - The hex-encoded string representing call data.
pub fn decode_call_data(call_data: &str) -> Result<Vec<u8>, Error> {
hex::decode(call_data.trim_start_matches("0x"))
.map_err(|e| Error::CallDataDecodingError(e.to_string()))
from_hex(call_data).map_err(|e| Error::CallDataDecodingError(e.to_string()))
}

// This struct implements the [`Payload`] trait and is used to submit
Expand Down

0 comments on commit fdaaa40

Please sign in to comment.