Miscellaneous fixes and 'make fix'.

This commit is contained in:
parazyd
2022-03-16 22:30:31 +01:00
parent c7d0d4ca32
commit 92a4410e31
28 changed files with 72 additions and 110 deletions

1
.gitignore vendored
View File

@@ -13,3 +13,4 @@
/ircd
/map
/vanityaddr
/dnetview

27
Cargo.lock generated
View File

@@ -537,7 +537,7 @@ dependencies = [
"base64-compat",
"bech32",
"bitcoin_hashes",
"secp256k1 0.20.3",
"secp256k1",
"serde",
]
@@ -850,7 +850,7 @@ dependencies = [
"num-bigint",
"num_cpus",
"rand 0.8.5",
"secp256k1 0.22.1",
"secp256k1",
"serde",
"serde_json",
"simplelog",
@@ -4630,19 +4630,10 @@ name = "secp256k1"
version = "0.20.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97d03ceae636d0fed5bae6a7f4f664354c5f4fcedf6eef053fef17e49f837d0a"
dependencies = [
"secp256k1-sys 0.4.2",
"serde",
]
[[package]]
name = "secp256k1"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26947345339603ae8395f68e2f3d85a6b0a8ddfe6315818e80b8504415099db0"
dependencies = [
"rand 0.6.5",
"secp256k1-sys 0.5.0",
"secp256k1-sys",
"serde",
]
[[package]]
@@ -4654,15 +4645,6 @@ dependencies = [
"cc",
]
[[package]]
name = "secp256k1-sys"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07b5b9d7322572e1f3aeed208668ce87789b3645dbb73082c5ce99a004103a35"
dependencies = [
"cc",
]
[[package]]
name = "security-framework"
version = "2.4.2"
@@ -6227,6 +6209,7 @@ dependencies = [
"bitflags",
"cassowary",
"crossterm",
"termion",
"unicode-segmentation",
"unicode-width",
]

View File

@@ -36,7 +36,7 @@ serde_json = "1.0.79"
bdk = {version = "0.16.1", optional = true}
anyhow = {version = "1.0.56", optional = true}
bitcoin = {version = "0.27.1", optional = true}
secp256k1 = {version = "0.22.1", default-features = false, features = ["rand-std"], optional = true}
secp256k1 = {version = "0.20.1", default-features = false, features = ["rand-std"], optional = true}
# Ethereum bridge dependencies
hex = {version = "0.4.3", optional = true}

View File

@@ -736,7 +736,7 @@ async fn start(
#[async_std::main]
async fn main() -> Result<()> {
let args = CliCashierd::parse();
let matches = CliCashierd::into_app().get_matches();
let matches = CliCashierd::command().get_matches();
let config_path = if args.config.is_some() {
expand_path(&args.config.unwrap())?

View File

@@ -761,7 +761,7 @@ pub struct BtcTransaction(bitcoin::Transaction);
pub struct BtcAddress(bitcoin::Address);
pub struct BtcPublicKey(bitcoin::PublicKey);
pub struct BtcPrivateKey(bitcoin::PrivateKey);
pub struct SecPublicKey(secp256k1::key::PublicKey);
pub struct SecPublicKey(secp256k1::PublicKey);
impl Encodable for BtcTransaction {
fn encode<S: std::io::Write>(&self, s: S) -> Result<usize> {
@@ -830,7 +830,7 @@ impl Encodable for SecPublicKey {
impl Decodable for SecPublicKey {
fn decode<D: std::io::Read>(mut d: D) -> Result<Self> {
let key: Vec<u8> = Decodable::decode(&mut d)?;
let key = secp256k1::key::PublicKey::from_slice(&key)
let key = secp256k1::PublicKey::from_slice(&key)
.map_err(|err| darkfi::Error::from(BtcFailed::from(err)))?;
Ok(SecPublicKey(key))
}

View File

@@ -85,7 +85,7 @@ async fn start(options: CliDao) -> Result<()> {
#[async_std::main]
async fn main() -> Result<()> {
let args = CliDao::parse();
let _matches = CliDao::into_app().get_matches();
let _matches = CliDao::command().get_matches();
//let config_path = if args.config.is_some() {
// expand_path(&args.config.clone().unwrap())?

View File

@@ -64,7 +64,7 @@ impl JsonRpcInterface {
async fn main() -> Result<()> {
//let args = CliDao::parse();
//let matches = CliDao::into_app().get_matches();
//let matches = CliDao::command().get_matches();
TermLogger::init(
LevelFilter::Debug,

View File

@@ -874,7 +874,7 @@ async fn start(
#[async_std::main]
async fn main() -> Result<()> {
let args = CliDarkfid::parse();
let matches = CliDarkfid::into_app().get_matches();
let matches = CliDarkfid::command().get_matches();
let config_path = if args.config.is_some() {
expand_path(&args.config.unwrap())?

View File

@@ -10,7 +10,7 @@ features = ["rpc"]
[dependencies]
# Tui
termion = "1.5.6"
tui = "0.17.0"
tui = {version = "0.17.0", features = ["termion"]}
# Async
smol = "1.2.5"

View File

@@ -1,4 +1,4 @@
use clap::{App, Arg, ArgMatches};
use clap::{Arg, ArgMatches, Command};
use darkfi::Result;
@@ -9,7 +9,7 @@ pub struct ProgramOptions {
impl ProgramOptions {
pub fn load() -> Result<ProgramOptions> {
let app = App::new("dnetview")
let app = Command::new("dnetview")
.version("0.1.0")
.author("lunar_mining")
.about("dnetview")

View File

@@ -3,7 +3,7 @@ use log::debug;
use tui::{
backend::Backend,
layout::{Alignment, Constraint, Direction, Layout, Rect},
layout::{Constraint, Direction, Layout, Rect},
style::Style,
text::{Span, Spans},
widgets::{Block, Borders, List, ListItem, Paragraph},
@@ -37,7 +37,7 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
format!(" [S: {}]", slot.channel.last_msg),
style,
),
a => Span::styled(format!("{}", a), style),
a => Span::styled(a.to_string(), style),
};
lines.push(Spans::from(vec![addr, msg]));
} else {
@@ -59,7 +59,7 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
format!(" [R: {}]", connect.channel.last_msg),
style,
),
a => Span::styled(format!("{}", a), style),
a => Span::styled(a.to_string(), style),
};
lines.push(Spans::from(vec![addr, msg]));
} else {

View File

@@ -14,7 +14,7 @@ impl View {
}
pub fn update(&mut self, infos: HashMap<String, NodeInfo>) {
for (id, info) in infos.clone() {
for (id, info) in infos {
self.id_list.node_id.insert(id.clone());
self.info_list.infos.insert(id, info);
}

View File

@@ -1,6 +1,6 @@
use std::{path::PathBuf, str::FromStr};
use clap::{AppSettings, IntoApp, Parser, Subcommand};
use clap::{IntoApp, Parser, Subcommand};
use log::{debug, error};
use prettytable::{cell, format, row, Table};
use serde::{Deserialize, Serialize};
@@ -115,9 +115,6 @@ pub enum CliDrkSubCommands {
#[derive(Parser)]
#[clap(name = "drk")]
#[clap(author, version, about)]
#[clap(global_setting(AppSettings::PropagateVersion))]
#[clap(global_setting(AppSettings::UseLongFormatForHelpSubcommand))]
#[clap(setting(AppSettings::SubcommandRequiredElseHelp))]
pub struct CliDrk {
/// Sets a custom config file
#[clap(short, long)]
@@ -471,7 +468,8 @@ async fn start(config: &DrkConfig, options: CliDrk) -> Result<()> {
#[async_std::main]
async fn main() -> Result<()> {
let args = CliDrk::parse();
let matches = CliDrk::into_app().get_matches();
let matches =
CliDrk::command().propagate_version(true).arg_required_else_help(true).get_matches();
let config_path = if args.config.is_some() {
expand_path(&args.config.clone().unwrap())?

View File

@@ -64,7 +64,7 @@ async fn start(executor: Arc<Executor<'_>>, config: &GatewaydConfig) -> Result<(
#[async_std::main]
async fn main() -> Result<()> {
let args = CliGatewayd::parse();
let matches = CliGatewayd::into_app().get_matches();
let matches = CliGatewayd::command().get_matches();
let config_path = if args.config.is_some() {
expand_path(&args.config.unwrap())?

View File

@@ -152,17 +152,12 @@ impl JsonRpcInterface {
}
let result = || -> Result<Vec<TaskInfo>> {
let tasks: Vec<TaskInfo>;
if args[0].is_i64() {
tasks = MonthTasks::load_or_create(
&Timestamp(args[0].as_i64().unwrap()),
&self.settings,
)?
.objects()?;
let tasks: Vec<TaskInfo> = if args[0].is_i64() {
MonthTasks::load_or_create(&Timestamp(args[0].as_i64().unwrap()), &self.settings)?
.objects()?
} else {
tasks = MonthTasks::load_current_open_tasks(&self.settings)?;
}
MonthTasks::load_current_open_tasks(&self.settings)?
};
Ok(tasks)
};
@@ -195,12 +190,10 @@ impl JsonRpcInterface {
let task_id = args[0].as_u64().unwrap();
let data = args[1].as_object().unwrap();
let mut task: TaskInfo;
match self.load_task_by_id(task_id) {
Ok(t) => task = t,
let mut task: TaskInfo = match self.load_task_by_id(task_id) {
Ok(t) => t,
Err(e) => return JsonResult::Err(jsonerr(InternalError, Some(e), id)),
}
};
let mut result = || -> std::result::Result<(), String> {
if data.contains_key("title") {
@@ -297,12 +290,10 @@ impl JsonRpcInterface {
let task_id = args[0].as_u64().unwrap();
let task: TaskInfo;
match self.load_task_by_id(task_id) {
Ok(t) => task = t,
let task: TaskInfo = match self.load_task_by_id(task_id) {
Ok(t) => t,
Err(e) => return JsonResult::Err(jsonerr(InternalError, Some(e), id)),
}
};
JsonResult::Resp(jsonresp(json!(task.get_state()), id))
}
@@ -325,12 +316,10 @@ impl JsonRpcInterface {
let task_id = args[0].as_u64().unwrap();
let state = args[1].as_str().unwrap();
let mut task: TaskInfo;
match self.load_task_by_id(task_id) {
Ok(t) => task = t,
let mut task: TaskInfo = match self.load_task_by_id(task_id) {
Ok(t) => t,
Err(e) => return JsonResult::Err(jsonerr(InternalError, Some(e), id)),
}
};
task.set_state(state);
@@ -371,12 +360,10 @@ impl JsonRpcInterface {
let comment_author = args[1].as_str().unwrap();
let comment_content = args[2].as_str().unwrap();
let mut task: TaskInfo;
match self.load_task_by_id(task_id) {
Ok(t) => task = t,
let mut task: TaskInfo = match self.load_task_by_id(task_id) {
Ok(t) => t,
Err(e) => return JsonResult::Err(jsonerr(InternalError, Some(e), id)),
}
};
task.set_comment(Comment::new(comment_content, comment_author));
@@ -387,12 +374,10 @@ impl JsonRpcInterface {
}
fn load_task_by_id(&self, task_id: u64) -> std::result::Result<TaskInfo, String> {
let tasks: Vec<TaskInfo>;
match MonthTasks::load_current_open_tasks(&self.settings) {
Ok(tks) => tasks = tks,
let tasks: Vec<TaskInfo> = match MonthTasks::load_current_open_tasks(&self.settings) {
Ok(v) => v,
Err(e) => return Err(e.to_string()),
}
};
let task = tasks.into_iter().find(|t| (t.get_id() as u64) == task_id);

View File

@@ -1,4 +1,8 @@
use std::{fs::File, io::BufReader, path::PathBuf};
use std::{
fs::File,
io::BufReader,
path::{Path, PathBuf},
};
use chrono::Utc;
use clap::Parser;
@@ -17,7 +21,7 @@ pub fn get_current_time() -> Timestamp {
Timestamp(Utc::now().timestamp())
}
pub fn find_free_id(task_ids: &Vec<u32>) -> u32 {
pub fn find_free_id(task_ids: &[u32]) -> u32 {
for i in 1.. {
if !task_ids.contains(&i) {
return i
@@ -26,7 +30,7 @@ pub fn find_free_id(task_ids: &Vec<u32>) -> u32 {
1
}
pub fn load<T: DeserializeOwned>(path: &PathBuf) -> Result<T> {
pub fn load<T: DeserializeOwned>(path: &Path) -> Result<T> {
let file = File::open(path)?;
let reader = BufReader::new(file);
@@ -34,7 +38,7 @@ pub fn load<T: DeserializeOwned>(path: &PathBuf) -> Result<T> {
Ok(value)
}
pub fn save<T: Serialize>(path: &PathBuf, value: &T) -> Result<()> {
pub fn save<T: Serialize>(path: &Path, value: &T) -> Result<()> {
let file = File::create(path)?;
serde_json::to_writer_pretty(file, value)?;
Ok(())

View File

@@ -42,7 +42,7 @@ impl DrkAddr {
fn main() -> Result<()> {
let args = Args::parse();
if args.prefix.chars().next() != Some('1') {
if !args.prefix.starts_with('1') {
return Err(Error::ParseFailed("Address prefix must start with '1'"))
}

View File

@@ -8,10 +8,10 @@ pub fn gen_const_array<Output: Copy + Default, const LEN: usize>(
pub(crate) fn gen_const_array_with_default<Output: Copy, const LEN: usize>(
default_value: Output,
mut closure: impl FnMut(usize) -> Output,
closure: impl FnMut(usize) -> Output,
) -> [Output; LEN] {
let mut ret: [Output; LEN] = [default_value; LEN];
for (bit, val) in ret.iter_mut().zip((0..LEN).map(|idx| closure(idx))) {
for (bit, val) in ret.iter_mut().zip((0..LEN).map(closure)) {
*bit = val;
}
ret

View File

@@ -1,3 +1,3 @@
pub mod memory;
pub mod runtime;
pub mod util;
pub mod vm_runtime;

View File

@@ -1,6 +1,6 @@
use log::{error, warn};
use super::{memory::MemoryManipulation, runtime::Env};
use super::{memory::MemoryManipulation, vm_runtime::Env};
/// Serialize contract payload to format accepted by the runtime entrypoint.
/// We keep the same payload as a slice of bytes, and prepend it with a

View File

@@ -183,7 +183,7 @@ impl Circuit<pallas::Base> for MintContract {
let poseidon_output =
poseidon_hasher.hash(layouter.namespace(|| "Poseidon hash"), poseidon_message)?;
let poseidon_output: AssignedCell<Fp, Fp> = poseidon_output.into();
let poseidon_output: AssignedCell<Fp, Fp> = poseidon_output;
poseidon_output
};
@@ -206,7 +206,7 @@ impl Circuit<pallas::Base> for MintContract {
let value_commit_v = ValueCommitV;
let value_commit_v = FixedPointShort::from_inner(ecc_chip.clone(), value_commit_v);
value_commit_v
.mul(layouter.namespace(|| "[value] ValueCommitV"), (value.clone(), one.clone()))?
.mul(layouter.namespace(|| "[value] ValueCommitV"), (value, one.clone()))?
};
// r_V * G_2
@@ -239,8 +239,7 @@ impl Circuit<pallas::Base> for MintContract {
let (commitment, _) = {
let token_commit_v = ValueCommitV;
let token_commit_v = FixedPointShort::from_inner(ecc_chip.clone(), token_commit_v);
token_commit_v
.mul(layouter.namespace(|| "[token] ValueCommitV"), (token.clone(), one.clone()))?
token_commit_v.mul(layouter.namespace(|| "[token] ValueCommitV"), (token, one))?
};
// r_A * G_2

View File

@@ -171,12 +171,8 @@ impl Circuit<pallas::Base> for SpendContract {
// Configuration for curve point operations.
// This uses 10 advice columns and spans the whole circuit.
let ecc_config = EccChip::<OrchardFixedBases>::configure(
meta,
advices,
lagrange_coeffs,
range_check.clone(),
);
let ecc_config =
EccChip::<OrchardFixedBases>::configure(meta, advices, lagrange_coeffs, range_check);
// Configuration for the Poseidon hash
let poseidon_config = PoseidonChip::configure::<P128Pow5T3>(
@@ -198,7 +194,7 @@ impl Circuit<pallas::Base> for SpendContract {
advices[6],
lagrange_coeffs[0],
lookup,
range_check.clone(),
range_check,
);
let merkle_config_1 = MerkleChip::configure(meta, sinsemilla_config_1.clone());
(sinsemilla_config_1, merkle_config_1)
@@ -271,7 +267,7 @@ impl Circuit<pallas::Base> for SpendContract {
let poseidon_output =
poseidon_hasher.hash(layouter.namespace(|| "Poseidon hash"), poseidon_message)?;
let poseidon_output: AssignedCell<Fp, Fp> = poseidon_output.into();
let poseidon_output: AssignedCell<Fp, Fp> = poseidon_output;
poseidon_output
};
@@ -317,7 +313,7 @@ impl Circuit<pallas::Base> for SpendContract {
let poseidon_output =
poseidon_hasher.hash(layouter.namespace(|| "Poseidon hash"), poseidon_message)?;
let poseidon_output: AssignedCell<Fp, Fp> = poseidon_output.into();
let poseidon_output: AssignedCell<Fp, Fp> = poseidon_output;
poseidon_output
};

View File

@@ -171,12 +171,8 @@ impl Circuit<pallas::Base> for ZkCircuit {
// Configuration for curve point operations.
// This uses 10 advice columns and spans the whole circuit.
let ecc_config = EccChip::<OrchardFixedBases>::configure(
meta,
advices,
lagrange_coeffs,
range_check.clone(),
);
let ecc_config =
EccChip::<OrchardFixedBases>::configure(meta, advices, lagrange_coeffs, range_check);
// Configuration for the Poseidon hash
let poseidon_config = PoseidonChip::configure::<P128Pow5T3>(
@@ -201,7 +197,7 @@ impl Circuit<pallas::Base> for ZkCircuit {
advices[6],
lagrange_coeffs[0],
lookup,
range_check.clone(),
range_check,
);
let merkle_cfg1 = MerkleChip::configure(meta, sinsemilla_cfg1.clone());
(sinsemilla_cfg1, merkle_cfg1)

View File

@@ -31,7 +31,7 @@ impl Analyzer {
// For nice error reporting, we'll load everything into a string
// vector so we have references to lines.
let lines: Vec<String> = source.as_str().lines().map(|x| x.to_string()).collect();
let error = ErrorEmitter::new("Semantic", filename, lines.clone());
let error = ErrorEmitter::new("Semantic", filename, lines);
Analyzer { constants, witnesses, statements, stack: vec![], error }
}

View File

@@ -31,7 +31,7 @@ impl Compiler {
// For nice error reporting, we'll load everything into a string
// vector so we have references to lines.
let lines: Vec<String> = source.as_str().lines().map(|x| x.to_string()).collect();
let error = ErrorEmitter::new("Compiler", filename, lines.clone());
let error = ErrorEmitter::new("Compiler", filename, lines);
Compiler { constants, witnesses, statements, debug_info, error }
}

View File

@@ -42,7 +42,7 @@ impl<'a> Lexer<'a> {
// For nice error reporting, we'll load everything into a string
// vector so we have references to lines.
let lines: Vec<String> = source.as_str().lines().map(|x| x.to_string()).collect();
let error = ErrorEmitter::new("Lexer", filename, lines.clone());
let error = ErrorEmitter::new("Lexer", filename, lines);
Self { source, error }
}

View File

@@ -24,7 +24,7 @@ impl Parser {
// For nice error reporting, we'll load everything into a string
// vector so we have references to lines.
let lines: Vec<String> = source.as_str().lines().map(|x| x.to_string()).collect();
let error = ErrorEmitter::new("Parser", filename, lines.clone());
let error = ErrorEmitter::new("Parser", filename, lines);
Parser { tokens, error }
}