Skip to content

Commit

Permalink
[config] add ws config, to_string to to_owned.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feliciss committed Jul 5, 2023
1 parent 3546383 commit 7e67d6e
Show file tree
Hide file tree
Showing 23 changed files with 138 additions and 87 deletions.
1 change: 1 addition & 0 deletions crates/rooch-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

pub mod rpc;
pub mod ws;

use anyhow::{Context, Result};
use serde::{de::DeserializeOwned, Serialize};
Expand Down
4 changes: 2 additions & 2 deletions crates/rooch-config/src/rpc/server_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct ServerConfig {
}

impl ServerConfig {
pub fn url(&self, https: bool) -> String {
pub fn rpc_url(&self, https: bool) -> String {
let schema = if https { "https" } else { "http" };

format!("{}://{}:{}", schema, self.host, self.port)
Expand All @@ -37,7 +37,7 @@ impl Display for ServerConfig {
impl Default for ServerConfig {
fn default() -> Self {
Self {
host: "0.0.0.0".to_string(),
host: "0.0.0.0".to_owned(),
port: 50051,
proposer_address: None,
sequencer_address: None,
Expand Down
4 changes: 4 additions & 0 deletions crates/rooch-config/src/ws/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

pub mod relay_config;
44 changes: 44 additions & 0 deletions crates/rooch-config/src/ws/relay_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use serde::Deserialize;
use serde::Serialize;
use std::fmt::{Display, Formatter, Result, Write};

#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Hash)]
pub struct RelayConfig {
pub host: String,
pub port: u16,
pub remote_ip_header: Option<String>,
pub ping_interval_seconds: u32,
}

impl RelayConfig {
pub fn ws_url(&self, https: bool) -> String {
let schema = if https { "wss" } else { "ws" };

format!("{}://{}:{}", schema, self.host, self.port)
}
}

impl Display for RelayConfig {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let mut writer = String::new();

writeln!(writer, "host : {}", self.host)?;
writeln!(writer, "port : {}", self.port)?;

write!(f, "{}", writer)
}
}

impl Default for RelayConfig {
fn default() -> Self {
Self {
host: "0.0.0.0".to_owned(),
port: 8080,
remote_ip_header: None,
ping_interval_seconds: 300,
}
}
}
2 changes: 1 addition & 1 deletion crates/rooch-integration-test-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ pub fn run_integration_test_with_extended_check(
let buffer_output = String::from_utf8_lossy(buffer.as_slice()).to_string();
let re = Regex::new("(/.*)(.move:[0-9]+:[0-9]+)").unwrap();
Some(
re.replace(buffer_output.as_str(), "/tmp/tempfile$2".to_string())
re.replace(buffer_output.as_str(), "/tmp/tempfile$2".to_owned())
.to_string(),
)
} else {
Expand Down
6 changes: 3 additions & 3 deletions crates/rooch-key/src/key_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ pub fn validate_path(
{
Ok(p)
} else {
Err(RoochError::SignatureKeyGenError("Invalid path".to_string()))
Err(RoochError::SignatureKeyGenError("Invalid path".to_owned()))
}
} else {
Err(RoochError::SignatureKeyGenError("Invalid path".to_string()))
Err(RoochError::SignatureKeyGenError("Invalid path".to_owned()))
}
}
None => Ok(format!(
"m/{DERVIATION_PATH_PURPOSE_ED25519}'/{DERIVATION_PATH_COIN_TYPE}'/0'/0'/0'"
)
.parse()
.map_err(|_| RoochError::SignatureKeyGenError("Cannot parse path".to_string()))?),
.map_err(|_| RoochError::SignatureKeyGenError("Cannot parse path".to_owned()))?),
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/rooch-open-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Project {
license: &str,
license_url: &str,
) -> Self {
let openrpc: String = "1.2.6".to_string();
let openrpc: String = "1.2.6".to_owned();
Self {
openrpc,
info: Info {
Expand Down Expand Up @@ -230,7 +230,7 @@ impl ExamplePairing {
})
.collect(),
result: Example {
name: "Result".to_string(),
name: "Result".to_owned(),
summary: None,
description: None,
value: result,
Expand Down Expand Up @@ -309,7 +309,7 @@ impl Default for RpcModuleDocBuilder {
fn default() -> Self {
let schema_generator = SchemaSettings::default()
.with(|s| {
s.definitions_path = "#/components/schemas/".to_string();
s.definitions_path = "#/components/schemas/".to_owned();
})
.into_generator();

Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-rpc-api/src/api/eth_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub trait EthAPI {
// because it requires a signer to be available.
// Please use the `eth_sendRawTransaction` method instead.
//TODO find a suitable error code
Err(jsonrpsee::core::Error::Custom("eth_sendTransaction is not supported by this server. Please use eth_sendRawTransaction instead.".to_string()))
Err(jsonrpsee::core::Error::Custom("eth_sendTransaction is not supported by this server. Please use eth_sendRawTransaction instead.".to_owned()))
}

/// Sends signed transaction, returning its hash.
Expand Down
7 changes: 4 additions & 3 deletions crates/rooch-rpc-client/src/client_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::{Client, ClientBuilder};
use anyhow::anyhow;
use rooch_config::rpc::server_config::ServerConfig;
use rooch_config::ws::relay_config::RelayConfig;
use rooch_config::Config;
use rooch_key::keystore::{AccountKeystore, Keystore};
use rooch_types::address::RoochAddress;
Expand Down Expand Up @@ -91,9 +92,9 @@ impl Env {
impl Default for Env {
fn default() -> Self {
Env {
alias: "default".to_string(),
rpc: ServerConfig::default().url(false),
ws: None,
alias: "default".to_owned(),
rpc: ServerConfig::default().rpc_url(false),
ws: Some(RelayConfig::default().ws_url(false)),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rooch-rpc-client/src/wallet_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl WalletContext {
let address = match account.as_str() {
"default" => AccountAddress::from(self.config.active_address.unwrap()),
_ => Err(RoochError::CommandArgumentError(
"Use rooch init configuration".to_string(),
"Use rooch init configuration".to_owned(),
))?,
};

Expand Down
20 changes: 10 additions & 10 deletions crates/rooch-types/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl BuiltinScheme {
pub fn from_flag(flag: &str) -> Result<BuiltinScheme, RoochError> {
let byte_int = flag
.parse::<u8>()
.map_err(|_| RoochError::KeyConversionError("Invalid key scheme".to_string()))?;
.map_err(|_| RoochError::KeyConversionError("Invalid key scheme".to_owned()))?;
Self::from_flag_byte(&byte_int)
}

Expand All @@ -72,7 +72,7 @@ impl BuiltinScheme {
0x01 => Ok(BuiltinScheme::MultiEd25519),
0x02 => Ok(BuiltinScheme::Secp256k1),
_ => Err(RoochError::KeyConversionError(
"Invalid key scheme".to_string(),
"Invalid key scheme".to_owned(),
)),
}
}
Expand Down Expand Up @@ -319,7 +319,7 @@ pub trait RoochSignatureInner: Sized + ToFromBytes + PartialEq + Eq + Hash {
// Is this signature emitted by the expected author?
let bytes = self.public_key_bytes();
let pk = Self::PubKey::from_bytes(bytes)
.map_err(|_| RoochError::KeyConversionError("Invalid public key".to_string()))?;
.map_err(|_| RoochError::KeyConversionError("Invalid public key".to_owned()))?;

let received_addr = RoochAddress::from(&pk);
if received_addr != author {
Expand All @@ -331,7 +331,7 @@ pub trait RoochSignatureInner: Sized + ToFromBytes + PartialEq + Eq + Hash {
// deserialize the signature
let signature = Self::Sig::from_bytes(self.signature_bytes()).map_err(|_| {
RoochError::InvalidSignature {
error: "Fail to get pubkey and sig".to_string(),
error: "Fail to get pubkey and sig".to_owned(),
}
})?;

Expand Down Expand Up @@ -418,21 +418,21 @@ impl Signature {
BuiltinScheme::Ed25519 => Ok(CompressedSignature::Ed25519(
(&Ed25519Signature::from_bytes(bytes).map_err(|_| {
RoochError::InvalidSignature {
error: "Cannot parse sig".to_string(),
error: "Cannot parse sig".to_owned(),
}
})?)
.into(),
)),
BuiltinScheme::Secp256k1 => Ok(CompressedSignature::Secp256k1(
(&Secp256k1Signature::from_bytes(bytes).map_err(|_| {
RoochError::InvalidSignature {
error: "Cannot parse sig".to_string(),
error: "Cannot parse sig".to_owned(),
}
})?)
.into(),
)),
_ => Err(RoochError::UnsupportedFeatureError {
error: "Unsupported signature scheme in MultiSig".to_string(),
error: "Unsupported signature scheme in MultiSig".to_owned(),
}),
}
}
Expand All @@ -444,16 +444,16 @@ impl Signature {
match self.scheme() {
BuiltinScheme::Ed25519 => Ok(PublicKey::Ed25519(
(&Ed25519PublicKey::from_bytes(bytes)
.map_err(|_| RoochError::KeyConversionError("Cannot parse pk".to_string()))?)
.map_err(|_| RoochError::KeyConversionError("Cannot parse pk".to_owned()))?)
.into(),
)),
BuiltinScheme::Secp256k1 => Ok(PublicKey::Secp256k1(
(&Secp256k1PublicKey::from_bytes(bytes)
.map_err(|_| RoochError::KeyConversionError("Cannot parse pk".to_string()))?)
.map_err(|_| RoochError::KeyConversionError("Cannot parse pk".to_owned()))?)
.into(),
)),
_ => Err(RoochError::UnsupportedFeatureError {
error: "Unsupported signature scheme in MultiSig".to_string(),
error: "Unsupported signature scheme in MultiSig".to_owned(),
}),
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/rooch/src/cli_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub fn load_account_arg(str: &str) -> RoochResult<AccountAddress> {
} else {
Err(RoochError::UnableToParse(
"Address",
"Address should be in hex format".to_string(),
"Address should be in hex format".to_owned(),
))
}
}
Expand Down Expand Up @@ -264,11 +264,11 @@ impl FromStr for FunctionArgType {

if arg == FunctionArgType::Raw {
return Err(RoochError::CommandArgumentError(
"vector<raw> is not supported".to_string(),
"vector<raw> is not supported".to_owned(),
));
} else if matches!(arg, FunctionArgType::Vector(_)) {
return Err(RoochError::CommandArgumentError(
"nested vector<vector<_>> is not supported".to_string(),
"nested vector<vector<_>> is not supported".to_owned(),
));
}

Expand Down Expand Up @@ -370,7 +370,7 @@ impl ArgWithType {
}
FunctionArgType::Raw | FunctionArgType::Vector(_) => {
return Err(RoochError::UnexpectedError(
"Nested vectors not supported".to_string(),
"Nested vectors not supported".to_owned(),
));
}
},
Expand All @@ -396,7 +396,7 @@ impl FromStr for ArgWithType {
let u = s.splitn(2, 'u').collect::<Vec<_>>();
if u.len() != 2 {
return Err(RoochError::CommandArgumentError(
"Arguments must be pairs of <type>:<arg> e.g. bool:true".to_string(),
"Arguments must be pairs of <type>:<arg> e.g. bool:true".to_owned(),
));
} else {
let ty_str = String::from("u") + u[1];
Expand All @@ -411,7 +411,7 @@ impl FromStr for ArgWithType {
(ty, arg)
} else {
return Err(RoochError::CommandArgumentError(
"Arguments must be pairs of <type>:<arg> e.g. bool:true".to_string(),
"Arguments must be pairs of <type>:<arg> e.g. bool:true".to_owned(),
));
};
let arg = ty.parse_arg(arg)?;
Expand Down
4 changes: 2 additions & 2 deletions crates/rooch/src/commands/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ impl CommandAction<String> for Account {
AccountCommand::Create(create) => create.execute().await.map(|resp| {
serde_json::to_string_pretty(&resp).expect("Failed to serialize response")
}),
AccountCommand::List(list) => list.execute().await.map(|_| "".to_string()),
AccountCommand::Import(import) => import.execute().await.map(|_| "".to_string()),
AccountCommand::List(list) => list.execute().await.map(|_| "".to_owned()),
AccountCommand::Import(import) => import.execute().await.map(|_| "".to_owned()),
}
.map_err(RoochError::from)
}
Expand Down
13 changes: 7 additions & 6 deletions crates/rooch/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ impl CommandAction<String> for Init {
};
// Prompt user for connect to devnet fullnode if config does not exist.
if !client_config_path.exists() {
let env = match std::env::var_os("ROOCH_CONFIG_WITH_RPC_URL") {
let env = match std::env::var_os("ROOCH_CONFIG_WITH_RPC_WS_URL") {
Some(v) => Some(Env {
alias: "custom".to_string(),
rpc: v.into_string().unwrap(),
ws: None,
alias: "custom".to_owned(),
rpc: v.clone().into_string().unwrap(),
ws: Some(v.clone().into_string().unwrap()),
}),
None => {
if self.accept_defaults {
Expand All @@ -63,16 +63,17 @@ impl CommandAction<String> for Init {
Env::default()
} else {
print!("Environment alias for [{url}] : ");
let cloned_url = url.clone();
let alias = read_line()?;
let alias = if alias.trim().is_empty() {
"custom".to_string()
"custom".to_owned()
} else {
alias
};
Env {
alias,
rpc: url,
ws: None,
ws: Some(cloned_url),
}
})
} else {
Expand Down
18 changes: 9 additions & 9 deletions crates/rooch/src/commands/move_cli/commands/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,33 +217,33 @@ impl IntegrationTest {
data,
)
},
"integration-test333".to_string(),
"integration-test333".to_owned(),
tests_dir.display().to_string(),
r".*\.move".to_string(),
r".*\.move".to_owned(),
named_address_string_map,
);
if self.update_baseline {
std::env::set_var(UPDATE_BASELINE, "true");
}
let mut test_args = vec![
"test_runner".to_string(),
"--format".to_string(),
"test_runner".to_owned(),
"--format".to_owned(),
self.test_opts.format.to_string(),
"--test-threads".to_string(),
"--test-threads".to_owned(),
self.test_opts.test_threads.to_string(),
];
if self.test_opts.list {
test_args.push("--list".to_string());
test_args.push("--list".to_owned());
}
if self.test_opts.quiet {
test_args.push("--quiet".to_string());
test_args.push("--quiet".to_owned());
}
if self.test_opts.filter_exact {
test_args.push("--exact".to_string());
test_args.push("--exact".to_owned());
}

if let Some(filter) = self.test_opts.filter {
test_args.push("--".to_string());
test_args.push("--".to_owned());
test_args.push(filter);
}

Expand Down
Loading

0 comments on commit 7e67d6e

Please sign in to comment.