Skip to content

Commit

Permalink
Manually convert Url::url to String in order to include the default p…
Browse files Browse the repository at this point in the history
…ort (use-ink#591)
  • Loading branch information
h4nsu authored May 27, 2022
1 parent 7035710 commit 9902ee6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/cmd/extrinsics/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl CallCommand {
let signer = super::pair_signer(self.extrinsic_opts.signer()?);

async_std::task::block_on(async {
let url = self.extrinsic_opts.url.to_string();
let url = self.extrinsic_opts.url_to_string();
let api = ClientBuilder::new()
.set_url(&url)
.build()
Expand All @@ -111,7 +111,7 @@ impl CallCommand {
signer: &PairSigner,
transcoder: &ContractMessageTranscoder<'_>,
) -> Result<()> {
let url = self.extrinsic_opts.url.to_string();
let url = self.extrinsic_opts.url_to_string();
let cli = WsClientBuilder::default().build(&url).await?;
let storage_deposit_limit = self
.extrinsic_opts
Expand Down
9 changes: 4 additions & 5 deletions src/cmd/extrinsics/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl InstantiateCommand {
let transcoder = ContractMessageTranscoder::new(&contract_metadata);
let data = transcoder.encode(&self.constructor, &self.args)?;
let signer = super::pair_signer(self.extrinsic_opts.signer()?);
let url = self.extrinsic_opts.url.clone();
let url = self.extrinsic_opts.url_to_string();
let verbosity = self.extrinsic_opts.verbosity()?;

fn load_code(wasm_path: &Path) -> Result<Code> {
Expand Down Expand Up @@ -195,15 +195,15 @@ struct InstantiateArgs {
pub struct Exec<'a> {
args: InstantiateArgs,
verbosity: Verbosity,
url: url::Url,
url: String,
signer: PairSigner,
transcoder: ContractMessageTranscoder<'a>,
}

impl<'a> Exec<'a> {
async fn subxt_api(&self) -> Result<RuntimeApi> {
let api = ClientBuilder::new()
.set_url(self.url.to_string())
.set_url(&self.url)
.build()
.await?
.to_runtime_api::<RuntimeApi>();
Expand Down Expand Up @@ -326,8 +326,7 @@ impl<'a> Exec<'a> {
}

async fn instantiate_dry_run(&self, code: Code) -> Result<ContractInstantiateResult> {
let url = self.url.to_string();
let cli = WsClientBuilder::default().build(&url).await?;
let cli = WsClientBuilder::default().build(&self.url).await?;
let storage_deposit_limit = self
.args
.storage_deposit_limit
Expand Down
12 changes: 12 additions & 0 deletions src/cmd/extrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ impl ExtrinsicOpts {
pub fn verbosity(&self) -> Result<Verbosity> {
TryFrom::try_from(&self.verbosity)
}

/// Convert URL to String without omitting the default port
pub fn url_to_string(&self) -> String {
let mut res = self.url.to_string();
match (self.url.port(), self.url.port_or_known_default()) {
(None, Some(port)) => {
res.insert_str(res.len() - 1, &format!(":{}", port));
res
}
_ => res,
}
}
}

/// For a contract project with its `Cargo.toml` at the specified `manifest_path`, load the cargo
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/extrinsics/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl UploadCommand {
.context(format!("Failed to read from {}", wasm_path.display()))?;

async_std::task::block_on(async {
let url = self.extrinsic_opts.url.to_string();
let url = self.extrinsic_opts.url_to_string();
let api = ClientBuilder::new()
.set_url(&url)
.build()
Expand Down Expand Up @@ -121,7 +121,7 @@ impl UploadCommand {
code: Vec<u8>,
signer: &PairSigner,
) -> Result<CodeUploadResult> {
let url = self.extrinsic_opts.url.to_string();
let url = self.extrinsic_opts.url_to_string();
let cli = WsClientBuilder::default().build(&url).await?;
let storage_deposit_limit = self
.extrinsic_opts
Expand Down

0 comments on commit 9902ee6

Please sign in to comment.