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

feat: wallet integration call contract #378

Merged
Show file tree
Hide file tree
Changes from 138 commits
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
7705462
feat(wallet-integration): server and API (#362)
peterwht Dec 9, 2024
c0c9cd8
feat(up-contract): get call data for upload-only and pass to wallet i…
peterwht Dec 6, 2024
5463501
feat(up-contract): get call data for instantiate and pass to wallet i…
peterwht Dec 6, 2024
2b45cf9
feat(up-contract): run server and pass call_data for signing -- PoC
peterwht Dec 7, 2024
e051c91
feat(up-contract): submit signed payload to node
peterwht Dec 7, 2024
6b99452
fix(up-contract): update to FrontendFromDir type
peterwht Dec 8, 2024
af94cc1
refactor(pop-up): create functions for wallet integration, plus gener…
peterwht Dec 9, 2024
c1c05fb
chore: use git branch for cargo contract
peterwht Dec 9, 2024
ff9d067
feat(pop-up-contract): better error handling and prompt displays
peterwht Dec 9, 2024
6b2787a
chore(up-contract): outdated field name and clippy allow
peterwht Dec 9, 2024
1342b1a
feat(up-contract): handle subxt events better, various improvements
peterwht Dec 11, 2024
01e9a30
feat(up-contract): custom errors in contracts crate
peterwht Dec 11, 2024
b274572
feat(wallet-integration): implement server and API
peterwht Dec 4, 2024
829272b
feat(wallet-integration): add a few tests to server. Needs more
peterwht Dec 4, 2024
1bffd86
refactor(wallet-integration): just use call_data, remove data types
peterwht Dec 5, 2024
31bd99c
feat(wallet-integration): add frontend type for flexible serving
peterwht Dec 5, 2024
8b371d6
feat(wallet-integration): StateHandler in WalletIntegrationManager. A…
peterwht Dec 5, 2024
093f344
refactor(wallet-integration): move to module with pop-cli crate
peterwht Dec 5, 2024
182035a
feat(wallet-integration): server-side error handling, update port to …
peterwht Dec 5, 2024
711c896
refactor(wallet-integration): restructure server for easier use in th…
peterwht Dec 7, 2024
60c05d8
fix(wallet-integration): remove invalid fn `finish`
peterwht Dec 7, 2024
57b747d
docs(wallet-integration): inline comments
peterwht Dec 7, 2024
adfcc5a
test(wallet-integration): unit tests for wallet-integration server. A…
peterwht Dec 8, 2024
48b67b1
feat(wallet-integration): two new routes: error and terminate
peterwht Dec 8, 2024
3def618
refactor(wallet-integration): consistent comments, remove unnecessary…
peterwht Dec 9, 2024
f74c9bb
feat: add TransactionData::new
peterwht Dec 9, 2024
ef6dd5d
feat: guide user to call a contract (#306)
AlexD10S Nov 29, 2024
3bf5426
fix: support new substrate-contracts-node structure and stabilize int…
AlexD10S Dec 3, 2024
bf5fc96
fix: build spec experience (#331)
AlexD10S Dec 5, 2024
f01fb22
feat: guide user to call a parachain (#316)
AlexD10S Dec 10, 2024
c702c62
feat(wallet-integration): server and API (#362)
peterwht Dec 9, 2024
d80d532
feat(up-contract): get call data for upload-only and pass to wallet i…
peterwht Dec 6, 2024
9935efe
chore: use git branch for cargo contract
peterwht Dec 9, 2024
8a8de6d
feat(up-contract): handle subxt events better, various improvements
peterwht Dec 11, 2024
84f0595
refactor: reuse pop up logic
AlexD10S Dec 11, 2024
7301f45
chore: rebase fixes
AlexD10S Dec 11, 2024
d48f34e
refactor: clean after rebase
AlexD10S Dec 11, 2024
9941d36
fix: cargo.lock after rebase
AlexD10S Dec 11, 2024
f6bc272
refactor: move terminate node into common::contracts
AlexD10S Dec 11, 2024
a08b18d
fix: sp-core not only for contracts
AlexD10S Dec 11, 2024
741836f
feat(up-contract): serve HTML from string, fix deployment message on …
peterwht Dec 12, 2024
70e1311
chore: merge latest from peter/feat-wallet-integration-string-content
AlexD10S Dec 12, 2024
e78eb9d
fix: rebase
AlexD10S Dec 12, 2024
179c6f6
chore: deny.toml license
AlexD10S Dec 12, 2024
083149d
feat: secure signing logic for pop call contract
AlexD10S Dec 11, 2024
a521966
feat: integrate secure signing with pop call contract
AlexD10S Dec 12, 2024
6065dad
test: adapt pop-cli ui tests
AlexD10S Dec 12, 2024
d1d18ef
refactor: clean code
AlexD10S Dec 12, 2024
8450d11
docs: improve docs functions
AlexD10S Dec 12, 2024
2b7b3a7
test: ignore failing test (fixed in another PR), and remove println
AlexD10S Dec 13, 2024
9b8f623
fix: import removed by mistake
AlexD10S Dec 13, 2024
18f6677
feat(up-contract): serve HTML from string, fix deployment message on …
peterwht Dec 12, 2024
8b13242
feat(up-contract): serve HTML from string, fix deployment message on …
peterwht Dec 12, 2024
f99fb12
feat(wallet-integration): server and API (#362)
peterwht Dec 9, 2024
b4309d3
feat(up-contract): get call data for upload-only and pass to wallet i…
peterwht Dec 6, 2024
600f021
feat(up-contract): get call data for instantiate and pass to wallet i…
peterwht Dec 6, 2024
965c640
refactor(pop-up): create functions for wallet integration, plus gener…
peterwht Dec 9, 2024
1ceb3f2
chore: use git branch for cargo contract
peterwht Dec 9, 2024
bcda709
feat(up-contract): handle subxt events better, various improvements
peterwht Dec 11, 2024
53f1f5b
feat(wallet-integration): implement server and API
peterwht Dec 4, 2024
37b27f4
feat(wallet-integration): add a few tests to server. Needs more
peterwht Dec 4, 2024
0ad2f2f
refactor(wallet-integration): just use call_data, remove data types
peterwht Dec 5, 2024
a6c0561
feat(wallet-integration): add frontend type for flexible serving
peterwht Dec 5, 2024
534b06b
feat(wallet-integration): StateHandler in WalletIntegrationManager. A…
peterwht Dec 5, 2024
5635677
refactor(wallet-integration): move to module with pop-cli crate
peterwht Dec 5, 2024
a2cd3cc
feat(wallet-integration): server-side error handling, update port to …
peterwht Dec 5, 2024
dce935d
refactor(wallet-integration): restructure server for easier use in th…
peterwht Dec 7, 2024
2b04dfe
fix(wallet-integration): remove invalid fn `finish`
peterwht Dec 7, 2024
7f340a4
docs(wallet-integration): inline comments
peterwht Dec 7, 2024
4198a65
test(wallet-integration): unit tests for wallet-integration server. A…
peterwht Dec 8, 2024
9bf6815
feat(wallet-integration): two new routes: error and terminate
peterwht Dec 8, 2024
fa7b430
refactor(wallet-integration): consistent comments, remove unnecessary…
peterwht Dec 9, 2024
e0d5711
feat: guide user to call a contract (#306)
AlexD10S Nov 29, 2024
63fcb22
fix: support new substrate-contracts-node structure and stabilize int…
AlexD10S Dec 3, 2024
0f32110
feat: guide user to call a parachain (#316)
AlexD10S Dec 10, 2024
344be6b
feat(wallet-integration): server and API (#362)
peterwht Dec 9, 2024
1a5893f
feat(up-contract): get call data for upload-only and pass to wallet i…
peterwht Dec 6, 2024
4446fdb
chore: use git branch for cargo contract
peterwht Dec 9, 2024
a92b6f0
feat(up-contract): handle subxt events better, various improvements
peterwht Dec 11, 2024
d73a986
refactor: reuse pop up logic
AlexD10S Dec 11, 2024
cb9c0ac
chore: rebase fixes
AlexD10S Dec 11, 2024
e450978
refactor: clean after rebase
AlexD10S Dec 11, 2024
d822d0b
fix: cargo.lock after rebase
AlexD10S Dec 11, 2024
2590cb7
refactor: move terminate node into common::contracts
AlexD10S Dec 11, 2024
534d083
fix: sp-core not only for contracts
AlexD10S Dec 11, 2024
d56ee9b
feat(up-contract): serve HTML from string, fix deployment message on …
peterwht Dec 12, 2024
676dd83
fix: rebase
AlexD10S Dec 12, 2024
bef205a
feat: secure signing logic for pop call chain
AlexD10S Dec 12, 2024
3915463
test: unit tests in pop-cli
AlexD10S Dec 12, 2024
995a8b4
feat: secure signing for call from call_data
AlexD10S Dec 12, 2024
60c9b09
refactor: docs and remove unneded functions
AlexD10S Dec 13, 2024
094aea1
refactor: replace hex library
AlexD10S Dec 13, 2024
d51bcf7
fix: rebase issues
AlexD10S Dec 13, 2024
33046a3
chore: merge from alex/feat-wallet-integration-call-chain
AlexD10S Dec 13, 2024
2c461be
fix: merge issues
AlexD10S Dec 13, 2024
16e48a9
feat(wallet-integration): server and API (#362)
peterwht Dec 9, 2024
5271675
feat(up-contract): get call data for upload-only and pass to wallet i…
peterwht Dec 6, 2024
3255f2e
refactor(pop-up): create functions for wallet integration, plus gener…
peterwht Dec 9, 2024
1619e72
chore: use git branch for cargo contract
peterwht Dec 9, 2024
e19d9b9
feat(up-contract): handle subxt events better, various improvements
peterwht Dec 11, 2024
145e44b
feat(wallet-integration): implement server and API
peterwht Dec 4, 2024
f58b4a4
feat(wallet-integration): add a few tests to server. Needs more
peterwht Dec 4, 2024
251162a
refactor(wallet-integration): just use call_data, remove data types
peterwht Dec 5, 2024
5a3bbde
feat(wallet-integration): add frontend type for flexible serving
peterwht Dec 5, 2024
254952f
feat(wallet-integration): StateHandler in WalletIntegrationManager. A…
peterwht Dec 5, 2024
c054efd
refactor(wallet-integration): move to module with pop-cli crate
peterwht Dec 5, 2024
73e312d
feat(wallet-integration): server-side error handling, update port to …
peterwht Dec 5, 2024
a5a55e9
refactor(wallet-integration): restructure server for easier use in th…
peterwht Dec 7, 2024
6b5f29a
fix(wallet-integration): remove invalid fn `finish`
peterwht Dec 7, 2024
de35993
docs(wallet-integration): inline comments
peterwht Dec 7, 2024
15e91d4
test(wallet-integration): unit tests for wallet-integration server. A…
peterwht Dec 8, 2024
523cdc8
feat(wallet-integration): two new routes: error and terminate
peterwht Dec 8, 2024
0cbd8de
refactor(wallet-integration): consistent comments, remove unnecessary…
peterwht Dec 9, 2024
f000225
feat: guide user to call a contract (#306)
AlexD10S Nov 29, 2024
048ed33
fix: support new substrate-contracts-node structure and stabilize int…
AlexD10S Dec 3, 2024
d003d2f
feat: guide user to call a parachain (#316)
AlexD10S Dec 10, 2024
9fc9529
feat(wallet-integration): server and API (#362)
peterwht Dec 9, 2024
27102bd
feat(up-contract): get call data for upload-only and pass to wallet i…
peterwht Dec 6, 2024
f1dd455
chore: use git branch for cargo contract
peterwht Dec 9, 2024
725597e
feat(up-contract): handle subxt events better, various improvements
peterwht Dec 11, 2024
bbf8b71
refactor: reuse pop up logic
AlexD10S Dec 11, 2024
5870b9c
chore: rebase fixes
AlexD10S Dec 11, 2024
c48def7
refactor: clean after rebase
AlexD10S Dec 11, 2024
1070f2c
fix: cargo.lock after rebase
AlexD10S Dec 11, 2024
8066e56
refactor: move terminate node into common::contracts
AlexD10S Dec 11, 2024
257da81
fix: sp-core not only for contracts
AlexD10S Dec 11, 2024
f3b73cc
feat(up-contract): serve HTML from string, fix deployment message on …
peterwht Dec 12, 2024
b1e5561
fix: rebase
AlexD10S Dec 12, 2024
1e51fe2
feat: secure signing logic for pop call chain
AlexD10S Dec 12, 2024
7f734ad
test: unit tests in pop-cli
AlexD10S Dec 12, 2024
ade77a6
feat: secure signing for call from call_data
AlexD10S Dec 12, 2024
90e468e
refactor: docs and remove unneded functions
AlexD10S Dec 13, 2024
cb21505
refactor: replace hex library
AlexD10S Dec 13, 2024
0f0fb1a
fix: rebase issues
AlexD10S Dec 13, 2024
c335561
fix: rebase
AlexD10S Dec 13, 2024
20cda5e
chore: merge main branch
AlexD10S Dec 13, 2024
223a2fd
refactor: small changes
AlexD10S Dec 13, 2024
1fbddb0
Merge branch 'alex/feat-wallet-integration-call-chain' into alex/feat…
AlexD10S Dec 13, 2024
acc67b7
refactor: improve small details
AlexD10S Dec 13, 2024
98f4de2
fix: dry run with use_wallet
AlexD10S Dec 13, 2024
2de0997
test: fix unit test
AlexD10S Dec 13, 2024
df6c78c
feat: use_wallet short flag 'w'
peterwht Dec 14, 2024
b70cb52
fix: don't prompt for dry-run when --use-wallet
peterwht Dec 14, 2024
81738f4
fix: do not prompt for signer account if is a read-only function
AlexD10S Dec 14, 2024
55367b0
refactor: storage_deposit_limit
AlexD10S Dec 14, 2024
6327d7e
chore: warning if use_wallet is specified in a read-only call
AlexD10S Dec 14, 2024
094e096
chore: cleanup TODOs
peterwht Dec 15, 2024
cc84f4e
chore: solve merging conflicts
AlexD10S Dec 15, 2024
1ff19b1
Merge branch 'alex/feat-wallet-integration-call-contract' of https://…
AlexD10S Dec 15, 2024
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
462 changes: 231 additions & 231 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,14 @@ subxt = "0.38.0"
ink_env = "5.0.0"
sp-core = "32.0.0"
sp-weights = "31.0.0"
scale-info = { version = "2.11.4", default-features = false, features = ["derive"] }
scale-value = { version = "0.17.0", default-features = false, features = ["from-string", "parser-ss58"] }
# TODO: git deps
#contract-build = "5.0.0-alpha"
contract-build = { git = "https://github.com/use-ink/cargo-contract", branch = "peter/chore-make-types-pub" }
#contract-extrinsics = "5.0.0-alpha"
contract-extrinsics = { git = "https://github.com/use-ink/cargo-contract", branch = "peter/chore-make-types-pub" }
#contract-transcode = "5.0.0"
#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 All @@ -68,6 +65,8 @@ walkdir = "2.5"
indexmap = "2.2"
toml_edit = { version = "0.22", features = ["serde"] }
symlink = "0.1"
scale-info = { version = "2.11.4", default-features = false, features = ["derive"] }
scale-value = { version = "0.17.0", default-features = false, features = ["from-string", "parser-ss58"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
serde = { version = "1.0", features = ["derive"] }
zombienet-sdk = "0.2.18"
Expand Down
6 changes: 3 additions & 3 deletions crates/pop-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ url.workspace = true
clap.workspace = true
cliclack.workspace = true
console.workspace = true
sp-core.workspace = true
strum.workspace = true
strum_macros.workspace = true

# contracts
pop-contracts = { path = "../pop-contracts", version = "0.5.0", optional = true }
sp-core = { workspace = true, optional = true }
sp-weights = { workspace = true, optional = true }

# parachains
Expand All @@ -49,7 +49,7 @@ pop-common = { path = "../pop-common", version = "0.5.0" }

# wallet-integration
axum.workspace = true
tower-http = { workspace = true, features = ["fs"] }
tower-http = { workspace = true, features = ["fs", "cors"] }

[dev-dependencies]
assert_cmd.workspace = true
Expand All @@ -59,6 +59,6 @@ subxt-signer.workspace = true

[features]
default = ["contract", "parachain", "telemetry"]
contract = ["dep:pop-contracts", "dep:sp-core", "dep:sp-weights", "dep:dirs"]
contract = ["dep:pop-contracts", "dep:sp-weights", "dep:dirs"]
parachain = ["dep:pop-parachains", "dep:dirs"]
telemetry = ["dep:pop-telemetry"]
134 changes: 134 additions & 0 deletions crates/pop-cli/src/assets/index.html

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion crates/pop-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ impl traits::Confirm for Confirm {

/// A input prompt using cliclack.
struct Input(cliclack::Input);

impl traits::Input for Input {
/// Sets the default value for the input.
fn default_input(mut self, value: &str) -> Self {
Expand Down
130 changes: 114 additions & 16 deletions crates/pop-cli/src/commands/call/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

use std::path::Path;

use crate::cli::{self, traits::*};
use crate::{
cli::{self, traits::*},
common::wallet::wait_for_signature,
};
use anyhow::{anyhow, Result};
use clap::Args;
use pop_parachains::{
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, supported_actions, Action, CallData, DynamicPayload, Function,
OnlineClient, Pallet, Param, SubstrateConfig,
sign_and_submit_extrinsic, submit_signed_extrinsic, supported_actions, Action, CallData,
DynamicPayload, Function, OnlineClient, Pallet, Param, Payload, SubstrateConfig,
};
use url::Url;

Expand Down Expand Up @@ -40,6 +43,9 @@
/// - with a password "//Alice///SECRET_PASSWORD"
#[arg(short, long)]
suri: Option<String>,
/// Use your browser wallet to sign the extrinsic.
#[arg(name = "use-wallet", long, default_value = "false", conflicts_with = "suri")]
use_wallet: bool,
/// SCALE encoded bytes representing the call data of the extrinsic.
#[arg(name = "call", short, long, conflicts_with_all = ["pallet", "function", "args"])]
call_data: Option<String>,
Expand Down Expand Up @@ -95,7 +101,15 @@
};

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

if let Err(e) = result {
display_message(&e.to_string(), false, &mut cli)?;
break;
}
Expand Down Expand Up @@ -197,11 +211,25 @@
// sudo.
self.configure_sudo(chain, cli)?;

// Resolve who is signing the extrinsic.
// Resolve who is signing the extrinsic. If a `suri` was provided via the command line,
// skip the prompt.
let suri = match self.suri.as_ref() {
Some(suri) => suri.clone(),
None =>
cli.input("Signer of the extrinsic:").default_input(DEFAULT_URI).interact()?,
None => {
if !self.use_wallet {
if cli.confirm("Do you want to use your browser wallet to sign the transaction? (Selecting 'No' will prompt you to manually enter the secret key URI for signing, e.g., '//Alice')")
.initial_value(true)
.interact()? {
self.use_wallet = true;
DEFAULT_URI.to_string() // Default value because the user is using the browser wallet.
}
else {
cli.input("Signer of the extrinsic:").default_input(DEFAULT_URI).interact()?
}
} else {
DEFAULT_URI.to_string() // Default value because the user is using the browser wallet.
}
},
};

return Ok(Call {
Expand All @@ -210,6 +238,7 @@
suri,
skip_confirm: self.skip_confirm,
sudo: self.sudo,
use_wallet: self.use_wallet,
});
}
}
Expand All @@ -222,11 +251,36 @@
call_data: &str,
cli: &mut impl Cli,
) -> Result<()> {
// Resolve who is signing the extrinsic.
// Resolve who is signing the extrinsic. If a `suri` was provided via the command line,
// skip the prompt.
let mut use_wallet = self.use_wallet;
let suri = match self.suri.as_ref() {
Some(suri) => suri,
None => &cli.input("Signer of the extrinsic:").default_input(DEFAULT_URI).interact()?,
Some(suri) => suri.clone(),
None =>
if !self.use_wallet {
if cli.confirm("Do you want to use your browser wallet to sign the transaction? (Selecting 'No' will prompt you to manually enter the secret key URI for signing, e.g., '//Alice')")
.initial_value(true)
.interact()? {
use_wallet = true;
DEFAULT_URI.to_string()
}
else {
cli.input("Signer of the extrinsic:").default_input(DEFAULT_URI).interact()?
}
} else {
DEFAULT_URI.to_string()
},
};
// Perform signing steps with wallet integration and return early.
if use_wallet {
let call_data_bytes =
decode_call_data(call_data).map_err(|err| anyhow!("{}", format!("{err:?}")))?;
submit_extrinsic_with_secure_signing(client, &url, call_data_bytes, cli)

Check warning on line 278 in crates/pop-cli/src/commands/call/chain.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

warning: this expression creates a reference which is immediately dereferenced by the compiler --> crates/pop-cli/src/commands/call/chain.rs:278:49 | 278 | submit_extrinsic_with_secure_signing(client, &url, call_data_bytes, cli) | ^^^^ help: change this to: `url` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow = note: `#[warn(clippy::needless_borrow)]` on by default
.await
.map_err(|err| anyhow!("{}", format!("{err:?}")))?;
display_message("Call complete.", true, cli)?;
return Ok(());
}
cli.info(format!("Encoded call data: {}", call_data))?;
if !self.skip_confirm &&
!cli.confirm("Do you want to submit the extrinsic?")
Expand All @@ -244,7 +298,7 @@
spinner.start("Signing and submitting the extrinsic and then waiting for finalization, please be patient...");
let call_data_bytes =
decode_call_data(call_data).map_err(|err| anyhow!("{}", format!("{err:?}")))?;
let result = sign_and_submit_extrinsic(client, url, CallData::new(call_data_bytes), suri)
let result = sign_and_submit_extrinsic(client, url, CallData::new(call_data_bytes), &suri)
.await
.map_err(|err| anyhow!("{}", format!("{err:?}")))?;

Expand Down Expand Up @@ -283,6 +337,7 @@
self.function = None;
self.args.clear();
self.sudo = false;
self.use_wallet = false;
}

// Function to check if all required fields are specified.
Expand Down Expand Up @@ -334,6 +389,8 @@
/// - for a dev account "//Alice"
/// - with a password "//Alice///SECRET_PASSWORD"
suri: String,
/// Whether to use your browser wallet to sign the extrinsic.
use_wallet: bool,
/// Whether to automatically sign and submit the extrinsic without prompting for confirmation.
skip_confirm: bool,
/// Whether to dispatch the function call with `Root` origin.
Expand Down Expand Up @@ -411,14 +468,45 @@
.collect();
full_message.push_str(&format!(" --args {}", args.join(" ")));
}
full_message.push_str(&format!(" --url {} --suri {}", chain.url, self.suri));
full_message.push_str(&format!(" --url {}", chain.url));
if self.use_wallet {
full_message.push_str(" --use-wallet");
} else {
full_message.push_str(&format!(" --suri {}", self.suri));
}
if self.sudo {
full_message.push_str(" --sudo");
}
full_message
}
}

// Sign and submit an extrinsic using wallet integration.
async fn submit_extrinsic_with_secure_signing(
client: &OnlineClient<SubstrateConfig>,
url: &Url,
call_data: Vec<u8>,
cli: &mut impl Cli,
) -> Result<()> {
let maybe_payload = wait_for_signature(call_data, url.to_string()).await?;
if let Some(payload) = maybe_payload {
cli.success("Signed payload received.")?;
let spinner = cliclack::spinner();
spinner.start(
"Submitting the extrinsic and then waiting for finalization, please be patient...",
);

let result = submit_signed_extrinsic(client.clone(), payload)
.await
.map_err(|err| anyhow!("{}", format!("{err:?}")))?;

spinner.stop(format!("Extrinsic submitted with hash: {:?}", result));
} else {
display_message("No signed payload received.", false, cli)?;
}
Ok(())
}

// Displays a message to the user, with formatting based on the success status.
fn display_message(message: &str, success: bool, cli: &mut impl Cli) -> Result<()> {
if success {
Expand Down Expand Up @@ -642,7 +730,7 @@
)
.expect_input("The value for `remark` might be too large to enter. You may enter the path to a file instead.", "0x11".into())
.expect_confirm("Would you like to dispatch this function call with `Root` origin?", true)
.expect_input("Signer of the extrinsic:", "//Bob".into());
.expect_confirm("Do you want to use your browser wallet to sign the transaction? (Selecting 'No' will prompt you to manually enter the secret key URI for signing, e.g., '//Alice')", true);

let chain = call_config.configure_chain(&mut cli).await?;
assert_eq!(chain.url, Url::parse(POP_NETWORK_TESTNET_URL)?);
Expand All @@ -651,9 +739,10 @@
assert_eq!(call_chain.function.pallet, "System");
assert_eq!(call_chain.function.name, "remark");
assert_eq!(call_chain.args, ["0x11".to_string()].to_vec());
assert_eq!(call_chain.suri, "//Bob");
assert_eq!(call_chain.suri, "//Alice"); // Default value
assert!(call_chain.use_wallet);
assert!(call_chain.sudo);
assert_eq!(call_chain.display(&chain), "pop call chain --pallet System --function remark --args \"0x11\" --url wss://rpc1.paseo.popnetwork.xyz/ --suri //Bob --sudo");
assert_eq!(call_chain.display(&chain), "pop call chain --pallet System --function remark --args \"0x11\" --url wss://rpc1.paseo.popnetwork.xyz/ --use-wallet --sudo");
cli.verify()
}

Expand Down Expand Up @@ -714,6 +803,7 @@
},
args: vec!["0x11".to_string()].to_vec(),
suri: DEFAULT_URI.to_string(),
use_wallet: false,
skip_confirm: false,
sudo: false,
};
Expand Down Expand Up @@ -753,6 +843,7 @@
function: find_dispatchable_by_name(&pallets, "System", "remark")?.clone(),
args: vec!["0x11".to_string()].to_vec(),
suri: DEFAULT_URI.to_string(),
use_wallet: false,
skip_confirm: false,
sudo: false,
};
Expand All @@ -776,11 +867,13 @@
args: vec![].to_vec(),
url: Some(Url::parse(POP_NETWORK_TESTNET_URL)?),
suri: None,
use_wallet: false,
skip_confirm: false,
call_data: Some("0x00000411".to_string()),
sudo: false,
};
let mut cli = MockCli::new()
.expect_confirm("Do you want to use your browser wallet to sign the transaction? (Selecting 'No' will prompt you to manually enter the secret key URI for signing, e.g., '//Alice')", false)
.expect_input("Signer of the extrinsic:", "//Bob".into())
.expect_confirm("Do you want to submit the extrinsic?", false)
.expect_outro_cancel("Extrinsic with call data 0x00000411 was not submitted.");
Expand All @@ -803,8 +896,9 @@
pallet: None,
function: None,
args: vec![].to_vec(),
url: Some(Url::parse("wss://polkadot-rpc.publicnode.com")?),
url: Some(Url::parse(POLKADOT_NETWORK_URL)?),
suri: Some("//Alice".to_string()),
use_wallet: false,
skip_confirm: false,
call_data: Some("0x00000411".to_string()),
sudo: true,
Expand Down Expand Up @@ -836,6 +930,7 @@
function: Some("remark".to_string()),
args: vec!["0x11".to_string()].to_vec(),
url: Some(Url::parse(POP_NETWORK_TESTNET_URL)?),
use_wallet: true,
suri: Some(DEFAULT_URI.to_string()),
skip_confirm: false,
call_data: None,
Expand All @@ -846,6 +941,7 @@
assert_eq!(call_config.function, None);
assert_eq!(call_config.args.len(), 0);
assert!(!call_config.sudo);
assert!(!call_config.use_wallet);
Ok(())
}

Expand All @@ -857,6 +953,7 @@
args: vec!["0x11".to_string()].to_vec(),
url: Some(Url::parse(POP_NETWORK_TESTNET_URL)?),
suri: Some(DEFAULT_URI.to_string()),
use_wallet: false,
skip_confirm: false,
call_data: None,
sudo: false,
Expand All @@ -875,6 +972,7 @@
args: vec!["2000".to_string(), "0x1".to_string(), "0x12".to_string()].to_vec(),
url: Some(Url::parse(POP_NETWORK_TESTNET_URL)?),
suri: Some(DEFAULT_URI.to_string()),
use_wallet: false,
call_data: None,
skip_confirm: false,
sudo: false,
Expand Down
Loading
Loading