-
Notifications
You must be signed in to change notification settings - Fork 27
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
feat: logic for parachain registration #410
base: feat/deploy-parachain
Are you sure you want to change the base?
Changes from 12 commits
77309e2
f9dffc6
8016272
11869aa
d30c135
9bd7229
5952580
d5bd298
6abeba8
d360dba
7f9b926
ece5507
e413871
7d87f17
ae3d9a4
54a676e
db6e30d
50983c1
cfc566e
93053df
849dff0
74cf390
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ | |
construct_extrinsic, construct_sudo_extrinsic, decode_call_data, encode_call_data, | ||
find_dispatchable_by_name, find_pallet_by_name, parse_chain_metadata, set_up_client, | ||
sign_and_submit_extrinsic, submit_signed_extrinsic, supported_actions, Action, CallData, | ||
DynamicPayload, Function, OnlineClient, Pallet, Param, Payload, SubstrateConfig, | ||
DynamicPayload, ExtrinsicEvents, Function, OnlineClient, Pallet, Param, Payload, | ||
SubstrateConfig, | ||
}; | ||
use url::Url; | ||
|
||
|
@@ -109,7 +110,15 @@ | |
// Sign and submit the extrinsic. | ||
let result = if self.use_wallet { | ||
let call_data = xt.encode_call_data(&chain.client.metadata())?; | ||
submit_extrinsic_with_wallet(&chain.client, &chain.url, call_data, &mut cli).await | ||
match submit_extrinsic_with_wallet(&chain.client, &chain.url, call_data, &mut cli) | ||
.await | ||
{ | ||
Ok(_) => Ok(()), | ||
Err(e) => { | ||
display_message(&e.to_string(), false, &mut cli)?; | ||
break; | ||
}, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary? And is the error not duplicate with line 127 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, improved in ae3d9a4 |
||
} else { | ||
call.submit_extrinsic(&chain.client, &chain.url, xt, &mut cli).await | ||
}; | ||
|
@@ -358,13 +367,13 @@ | |
} | ||
|
||
// Represents a chain, including its URL, client connection, and available pallets. | ||
struct Chain { | ||
pub(crate) struct Chain { | ||
// Websocket endpoint of the node. | ||
url: Url, | ||
pub(crate) url: Url, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trivial but line 363 already set this struct to |
||
// The client used to interact with the chain. | ||
client: OnlineClient<SubstrateConfig>, | ||
pub(crate) client: OnlineClient<SubstrateConfig>, | ||
// A list of pallets available on the chain. | ||
pallets: Vec<Pallet>, | ||
pub(crate) pallets: Vec<Pallet>, | ||
} | ||
|
||
/// Represents a configured dispatchable function call, including the pallet, function, arguments, | ||
|
@@ -473,13 +482,19 @@ | |
} | ||
} | ||
|
||
// Sign and submit an extrinsic using wallet integration. | ||
async fn submit_extrinsic_with_wallet( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For context: Moved into common/wallet |
||
/// Sign and submit an extrinsic using wallet integration, then returns the resulting events. | ||
/// | ||
/// # Arguments | ||
/// * `client` - The client used to interact with the chain. | ||
/// * `url` - Endpoint of the node. | ||
/// * `call_data` - The call data to be signed. | ||
/// * `cli` - The CLI implementation to be used. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only required for public docs, as well as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored 7d87f17 |
||
pub(crate) async fn submit_extrinsic_with_wallet( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is now reused in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this should be moved there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree! Moved in 7d87f17 |
||
client: &OnlineClient<SubstrateConfig>, | ||
url: &Url, | ||
call_data: Vec<u8>, | ||
cli: &mut impl Cli, | ||
) -> Result<()> { | ||
) -> Result<ExtrinsicEvents<SubstrateConfig>> { | ||
let maybe_payload = request_signature(call_data, url.to_string()).await?; | ||
if let Some(payload) = maybe_payload { | ||
cli.success("Signed payload received.")?; | ||
|
@@ -492,11 +507,11 @@ | |
.await | ||
.map_err(|err| anyhow!("{}", format!("{err:?}")))?; | ||
|
||
spinner.stop(format!("Extrinsic submitted with hash: {:?}", result)); | ||
spinner.stop(format!("Extrinsic submitted with hash: {:?}", result.extrinsic_hash())); | ||
Ok(result) | ||
} else { | ||
display_message("No signed payload received.", false, cli)?; | ||
return Err(anyhow!("No signed payload received.")); | ||
Check warning on line 513 in crates/pop-cli/src/commands/call/chain.rs
|
||
} | ||
Ok(()) | ||
} | ||
|
||
// Displays a message to the user, with formatting based on the success status. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,8 @@ use std::path::PathBuf; | |
mod contract; | ||
#[cfg(feature = "parachain")] | ||
mod network; | ||
#[cfg(feature = "parachain")] | ||
mod parachain; | ||
|
||
/// Arguments for launching or deploying a project. | ||
#[derive(Args, Clone)] | ||
|
@@ -25,6 +27,10 @@ pub(crate) struct UpArgs { | |
#[arg(value_name = "PATH", index = 1, global = true, conflicts_with = "path")] | ||
pub path_pos: Option<PathBuf>, | ||
|
||
#[command(flatten)] | ||
#[cfg(feature = "parachain")] | ||
pub(crate) parachain: parachain::UpParachainCommand, | ||
|
||
#[command(flatten)] | ||
#[cfg(feature = "contract")] | ||
pub(crate) contract: contract::UpContractCommand, | ||
|
@@ -73,7 +79,9 @@ impl Command { | |
} | ||
#[cfg(feature = "parachain")] | ||
if pop_parachains::is_supported(project_path.as_deref())? { | ||
cli.warning("Parachain deployment is currently not implemented.")?; | ||
let mut cmd = args.parachain; | ||
cmd.path = project_path; | ||
cmd.execute(cli).await?; | ||
return Ok("parachain"); | ||
} | ||
cli.warning( | ||
|
@@ -85,7 +93,7 @@ impl Command { | |
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::{contract::UpContractCommand, *}; | ||
use super::{contract::UpContractCommand, parachain::UpParachainCommand, *}; | ||
|
||
use cli::MockCli; | ||
use duct::cmd; | ||
|
@@ -114,6 +122,7 @@ mod tests { | |
skip_confirm: false, | ||
valid: false, | ||
}, | ||
parachain: UpParachainCommand::default(), | ||
command: None, | ||
}) | ||
} | ||
|
@@ -138,17 +147,21 @@ mod tests { | |
async fn detects_parachain_correctly() -> anyhow::Result<()> { | ||
let temp_dir = tempfile::tempdir()?; | ||
let name = "parachain"; | ||
let project_path = temp_dir.path().join(name); | ||
let path = temp_dir.path(); | ||
let project_path = path.join(name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems unnecessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refactored ae3d9a4 |
||
let config = Config { | ||
symbol: "DOT".to_string(), | ||
decimals: 18, | ||
initial_endowment: "1000000".to_string(), | ||
}; | ||
instantiate_template_dir(&Parachain::Standard, &project_path, None, config)?; | ||
|
||
let args = create_up_args(project_path)?; | ||
let mut cli = | ||
MockCli::new().expect_warning("Parachain deployment is currently not implemented."); | ||
let mut args = create_up_args(project_path)?; | ||
args.parachain.relay_url = Some(Url::parse("wss://polkadot-rpc.publicnode.com")?); | ||
args.parachain.id = Some(2000); | ||
args.parachain.genesis_code = Some(PathBuf::from("path/to/genesis")); | ||
args.parachain.genesis_state = Some(PathBuf::from("path/to/state")); | ||
let mut cli = MockCli::new(); | ||
assert_eq!(Command::execute_project_deployment(args, &mut cli).await?, "parachain"); | ||
cli.verify() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored the logic for generating the chain spec and raw chain spec into the
generate_chain_spec
function.