Skip to content

Commit

Permalink
Merge branch 'development' into apps-fix-no-address-error
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Apr 5, 2022
2 parents f8359ea + 6bd5d44 commit 823563a
Show file tree
Hide file tree
Showing 386 changed files with 2,120 additions and 2,003 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ env:
PROTOC: protoc

jobs:

checks:
name: npm checks
runs-on: ubuntu-latest
Expand Down Expand Up @@ -84,11 +83,16 @@ jobs:
with:
command: fmt
args: --all -- --check
- name: Clippy check
- name: Install cargo-lints
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-lints
- name: Clippy check (with lints)
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets -- -D warnings
command: lints
args: clippy --all-targets
build:
name: check nightly
runs-on: ubuntu-18.04
Expand Down
17 changes: 16 additions & 1 deletion Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,19 @@ You can automatically format the code using the command:
cargo fmt --all
```

The toolchain version may change from time to time, so check in `.circlecit/config.yml` for the latest toolchain version
The toolchain version may change from time to time, so check in `.circlecit/config.yml` for the latest toolchain version

# Clippy

Currently, there isn't a neat way provided by cargo or clippy to specify
a common lint file for every project, so the lints are defined in
`lints.toml` and you will need to install `cargo-lints` to run them.
This is done on the CI Github Actions, so you will need to pass them.
They can be run locally using:

`cargo lint clippy --all-targets`

> Note: Generally, you should not put explicit crate level `deny` attributes
> in the code, and prefer to put them in the `lints.toml`. You SHOULD however,
> put crate level `allow` attributes, so that developers running `cargo clippy`
> will not encounter these warnings
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::{commands::AppState, docker::create_workspace_folders, error::Launche
pub fn create_new_workspace(app: AppHandle<Wry>, root_path: String) -> Result<(), String> {
let config = app.config();
let package_info = &app.state::<AppState>().package_info;
let _ = create_workspace_folders(root_path.as_str()).map_err(|e| e.chained_message());
let _result = create_workspace_folders(root_path.as_str()).map_err(|e| e.chained_message());
let path = Path::new(&root_path);
copy_config_file(path, config.as_ref(), package_info, "log4rs.yml").map_err(|e| e.chained_message())?;
copy_config_file(path, config.as_ref(), package_info, "config.toml").map_err(|e| e.chained_message())?;
Expand Down
105 changes: 52 additions & 53 deletions applications/launchpad/backend/src/commands/launch_docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,65 +79,64 @@ impl TryFrom<WorkspaceLaunchOptions> for LaunchpadConfig {
let tari_network = TariNetwork::try_from(options.tari_network.to_lowercase().as_str())?;
let tor_control_password = create_password(16);
let tor_delay = Duration::from_secs(options.wait_for_tor.unwrap_or(10));
let base_node = match options.has_base_node {
false => None,
true => Some(BaseNodeConfig { delay: tor_delay }),
let base_node = if options.has_base_node {
Some(BaseNodeConfig { delay: tor_delay })
} else {
None
};
let wallet = match options.has_wallet {
false => None,
true => {
if options.wallet_password.is_none() {
return Err(LauncherError::ConfigVariableRequired(
"wallet".to_string(),
"wallet_password".to_string(),
));
}
Some(WalletConfig {
delay: tor_delay,
password: options.wallet_password.unwrap(),
})
},
let wallet = if options.has_wallet {
if options.wallet_password.is_none() {
return Err(LauncherError::ConfigVariableRequired(
"wallet".to_string(),
"wallet_password".to_string(),
));
}
Some(WalletConfig {
delay: tor_delay,
password: options.wallet_password.unwrap(),
})
} else {
None
};
let sha3_miner = match options.has_sha3_miner {
false => None,
true => Some(Sha3MinerConfig {
let sha3_miner = if options.has_sha3_miner {
Some(Sha3MinerConfig {
delay: Duration::from_secs(options.wait_for_tor.unwrap_or(15)),
num_mining_threads: options.sha3_mining_threads.unwrap_or(1),
}),
})
} else {
None
};
let mm_proxy = match options.has_mm_proxy {
false => None,
true => {
let mut config = MmProxyConfig {
delay: Duration::from_secs(options.wait_for_tor.unwrap_or(15)),
..Default::default()
};
if let Some(val) = options.monerod_url {
config.monerod_url = val;
}
if let Some(val) = options.monero_username {
config.monero_username = val;
}
if let Some(val) = options.monero_password {
config.monero_password = val;
}
if let Some(val) = options.monero_use_auth {
config.monero_use_auth = val;
}
Some(config)
},
let mm_proxy = if options.has_mm_proxy {
let mut config = MmProxyConfig {
delay: Duration::from_secs(options.wait_for_tor.unwrap_or(15)),
..Default::default()
};
if let Some(val) = options.monerod_url {
config.monerod_url = val;
}
if let Some(val) = options.monero_username {
config.monero_username = val;
}
if let Some(val) = options.monero_password {
config.monero_password = val;
}
if let Some(val) = options.monero_use_auth {
config.monero_use_auth = val;
}
Some(config)
} else {
None
};
let xmrig = match options.has_xmrig {
false => None,
true => {
let monero_mining_address = options
.monero_mining_address
.unwrap_or_else(|| DEFAULT_MINING_ADDRESS.to_string());
Some(XmRigConfig {
delay: Duration::from_secs(options.wait_for_tor.unwrap_or(20)),
monero_mining_address,
})
},
let xmrig = if options.has_xmrig {
let monero_mining_address = options
.monero_mining_address
.unwrap_or_else(|| DEFAULT_MINING_ADDRESS.to_string());
Some(XmRigConfig {
delay: Duration::from_secs(options.wait_for_tor.unwrap_or(20)),
monero_mining_address,
})
} else {
None
};
Ok(LaunchpadConfig {
data_directory: PathBuf::from(options.root_folder),
Expand Down
4 changes: 2 additions & 2 deletions applications/launchpad/backend/src/commands/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl TryFrom<ServiceSettings> for LaunchpadConfig {
};
let sha3_miner = Sha3MinerConfig {
delay: zero_delay,
num_mining_threads: settings.num_mining_threads as usize,
num_mining_threads: usize::try_from(settings.num_mining_threads).unwrap(),
};
let mut mm_proxy = MmProxyConfig {
delay: zero_delay,
Expand Down Expand Up @@ -196,7 +196,7 @@ async fn create_default_workspace_impl(app: AppHandle<Wry>, settings: ServiceSet
}; // drop read-only lock
if should_create_workspace {
let package_info = &state.package_info;
let _ = create_workspace_folders(&config.data_directory).map_err(|e| e.chained_message());
let _result = create_workspace_folders(&config.data_directory).map_err(|e| e.chained_message());
copy_config_file(&config.data_directory, app_config.as_ref(), package_info, "log4rs.yml")?;
copy_config_file(&config.data_directory, app_config.as_ref(), package_info, "config.toml")?;
// Only get a write-lock if we need one
Expand Down
37 changes: 17 additions & 20 deletions applications/launchpad/backend/src/docker/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,30 @@ use crate::docker::{DockerWrapperError, ImageType};
pub fn create_workspace_folders<P: AsRef<Path>>(root: P) -> Result<(), DockerWrapperError> {
if !root.as_ref().exists() {
info!("Creating new workspace at {}", root.as_ref().to_str().unwrap_or("???"));
fs::create_dir(&root)?
fs::create_dir_all(&root)?
}
let make_subfolder = |folder: &str| -> Result<(), std::io::Error> {
let p = root.as_ref().join(folder);
let p_str = p.as_path().to_str().unwrap_or("???");
match p.exists() {
true => {
debug!("{} already exists", p_str);
Ok(())
},
false => {
info!("Creating new data folder, {}", p_str);
fs::create_dir(&p)?;
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
use std::os::unix::fs::PermissionsExt;
let mut perms = std::fs::metadata(&p)?.permissions();
perms.set_mode(0o777);
fs::set_permissions(&p, perms)?;
}
Ok(())
},
if p.exists() {
debug!("{} already exists", p_str);
Ok(())
} else {
info!("Creating new data folder, {}", p_str);
fs::create_dir_all(&p)?;
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
use std::os::unix::fs::PermissionsExt;
let mut perms = std::fs::metadata(&p)?.permissions();
perms.set_mode(0o777);
fs::set_permissions(&p, perms)?;
}
Ok(())
}
};
let _ = make_subfolder("config")?;
make_subfolder("config")?;
for image in ImageType::iter() {
let _ = make_subfolder(image.data_folder())?;
make_subfolder(image.data_folder())?;
}
Ok(())
}
2 changes: 1 addition & 1 deletion applications/launchpad/backend/src/docker/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl TariWorkspace {
let mut ids = HashMap::new();
for image in ImageType::iter() {
if let Some(id) = self.create_or_load_identity(root_path.as_str(), image)? {
let _ = ids.insert(image, id);
let _node_identity = ids.insert(image, id);
}
}
Ok(ids)
Expand Down
2 changes: 1 addition & 1 deletion applications/launchpad/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn main() {
info!("Received Exit event");
block_on(async move {
let state = app.state();
let _ = shutdown(state).await;
let _message = shutdown(state).await;
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use tari_core::base_node::state_machine_service::states::{StateInfo, StateInfo::*};
use tari_core::base_node::state_machine_service::states::{
StateInfo,
StateInfo::{BlockSync, BlockSyncStarting, HeaderSync, HorizonSync, Listening, StartUp},
};

use crate::tari_rpc as grpc;

Expand Down
2 changes: 1 addition & 1 deletion applications/tari_app_grpc/src/conversions/block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl From<BlockHeader> for grpc::BlockHeader {
let pow_algo = h.pow_algo();
Self {
hash: h.hash(),
version: h.version as u32,
version: u32::from(h.version),
height: h.height,
prev_hash: h.prev_hash,
timestamp: Some(datetime_to_timestamp(h.timestamp)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl TryFrom<NewBlockTemplate> for grpc::NewBlockTemplate {

fn try_from(block: NewBlockTemplate) -> Result<Self, Self::Error> {
let header = grpc::NewBlockHeaderTemplate {
version: block.header.version as u32,
version: u32::from(block.header.version),
height: block.header.height,
prev_hash: block.header.prev_hash.clone(),
total_kernel_offset: Vec::from(block.header.total_kernel_offset.as_bytes()),
Expand Down
4 changes: 2 additions & 2 deletions applications/tari_app_grpc/src/conversions/output_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl TryFrom<grpc::OutputFeatures> for OutputFeatures {
impl From<OutputFeatures> for grpc::OutputFeatures {
fn from(features: OutputFeatures) -> Self {
Self {
flags: features.flags.bits() as u32,
flags: u32::from(features.flags.bits()),
maturity: features.maturity,
metadata: features.metadata,
unique_id: features.unique_id.unwrap_or_default(),
Expand All @@ -90,7 +90,7 @@ impl From<OutputFeatures> for grpc::OutputFeatures {
sidechain_checkpoint: features.sidechain_checkpoint.map(|m| m.into()),
version: features.version as u32,
committee_definition: features.committee_definition.map(|c| c.into()),
recovery_byte: features.recovery_byte as u32,
recovery_byte: u32::from(features.recovery_byte),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions applications/tari_app_grpc/src/conversions/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl From<Peer> for grpc::Peer {
for address in peer.addresses.addresses {
addresses.push(address.clone().into())
}
let flags = peer.flags.bits() as u32;
let flags = u32::from(peer.flags.bits());
let banned_until = match peer.banned_until {
Some(v) => Some(datetime_to_timestamp((v.timestamp() as u64).into())),
None => Some(datetime_to_timestamp(0.into())),
Expand Down Expand Up @@ -94,7 +94,7 @@ impl From<MutliaddrWithStats> for grpc::Address {

impl From<ConnectivityStatus> for grpc::ConnectivityStatus {
fn from(status: ConnectivityStatus) -> Self {
use ConnectivityStatus::*;
use ConnectivityStatus::{Degraded, Initializing, Offline, Online};
match status {
Initializing => grpc::ConnectivityStatus::Initializing,
Online(_) => grpc::ConnectivityStatus::Online,
Expand Down
3 changes: 2 additions & 1 deletion applications/tari_app_grpc/src/conversions/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl TryFrom<grpc::Transaction> for Transaction {

impl From<TransactionDirection> for grpc::TransactionDirection {
fn from(status: TransactionDirection) -> Self {
use TransactionDirection::*;
use TransactionDirection::{Inbound, Outbound, Unknown};
match status {
Unknown => grpc::TransactionDirection::Unknown,
Inbound => grpc::TransactionDirection::Inbound,
Expand All @@ -88,6 +88,7 @@ impl From<TransactionDirection> for grpc::TransactionDirection {

impl From<TransactionStatus> for grpc::TransactionStatus {
fn from(status: TransactionStatus) -> Self {
#[allow(clippy::enum_glob_use)]
use TransactionStatus::*;
match status {
Completed => grpc::TransactionStatus::Completed,
Expand Down
20 changes: 10 additions & 10 deletions applications/tari_app_grpc/src/conversions/transaction_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ impl TryFrom<grpc::TransactionInput> for TransactionInput {
.map_err(|_| "script_signature could not be converted".to_string())?;

// Check if the received Transaction input is in compact form or not
if !input.commitment.is_empty() {
if input.commitment.is_empty() {
if input.output_hash.is_empty() {
return Err("Compact Transaction Input does not contain `output_hash`".to_string());
}
Ok(TransactionInput::new_with_output_hash(
input.output_hash,
ExecutionStack::from_bytes(input.input_data.as_slice()).map_err(|err| format!("{:?}", err))?,
script_signature,
))
} else {
let commitment = Commitment::from_bytes(&input.commitment).map_err(|e| e.to_string())?;
let features = input
.features
Expand All @@ -66,15 +75,6 @@ impl TryFrom<grpc::TransactionInput> for TransactionInput {
sender_offset_public_key,
covenant,
))
} else {
if input.output_hash.is_empty() {
return Err("Compact Transaction Input does not contain `output_hash`".to_string());
}
Ok(TransactionInput::new_with_output_hash(
input.output_hash,
ExecutionStack::from_bytes(input.input_data.as_slice()).map_err(|err| format!("{:?}", err))?,
script_signature,
))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl From<TransactionKernel> for grpc::TransactionKernel {
let hash = kernel.hash();

grpc::TransactionKernel {
features: kernel.features.bits() as u32,
features: u32::from(kernel.features.bits()),
fee: kernel.fee.0,
lock_height: kernel.lock_height,
excess: Vec::from(kernel.excess.as_bytes()),
Expand Down
Loading

0 comments on commit 823563a

Please sign in to comment.