Add linter to CI (#823)

Co-authored-by: wiesche <wiesche89@googlemail.com>
This commit is contained in:
ardocrat
2026-10-07 20:48:38 +03:00
committed by GitHub
co-authored by wiesche
parent ec1e9910af
commit fe79256467
87 changed files with 1300 additions and 1639 deletions
+4 -4
View File
@@ -20,14 +20,14 @@ use super::owner::tx_lock_outputs;
use crate::api_impl::owner::{check_ttl, post_tx};
use crate::api_impl::types::update_tx_slate_state;
use crate::backend::WalletBackend;
use crate::grin_core::core::FeeFields;
use crate::grin_keychain::Keychain;
use crate::grin_util::secp::key::SecretKey;
use crate::internal::{selection, tx, updater};
use crate::slate_versions::SlateVersion;
use crate::{
address, BlockFees, CbData, Error, NodeClient, Slate, SlateState, TxLogEntryType, VersionInfo,
};
use grin_core::core::FeeFields;
use grin_keychain::Keychain;
use grin_util::secp::key::SecretKey;
const FOREIGN_API_VERSION: u16 = 2;
@@ -164,7 +164,7 @@ where
selection::repopulate_tx(w, keychain_mask, &mut sl, &temp_ctx, false)?;
tx::complete_tx(w, keychain_mask, &mut sl, &context)?;
tx::update_stored_tx(w, keychain_mask, &context, &mut sl, true)?;
tx::update_stored_tx(w, keychain_mask, &context, &sl, true)?;
{
let mut batch = w.batch(keychain_mask)?;
batch.delete_private_context(sl.id.as_bytes())?;
+52 -67
View File
@@ -18,18 +18,16 @@ use std::cmp;
use uuid::Uuid;
use crate::api_impl::foreign::finalize_tx as foreign_finalize;
use crate::grin_core::core::amount_to_hr_string;
use crate::grin_core::core::hash::Hashed;
use crate::grin_core::core::{FeeFields, Output, OutputFeatures, Transaction};
use crate::grin_core::libtx::proof;
use crate::grin_keychain::ViewKey;
use crate::grin_util::secp::{key::SecretKey, pedersen::Commitment};
use crate::grin_util::Mutex;
use crate::grin_util::ToHex;
use crate::util::OnionV3Address;
use grin_core::core::amount_to_hr_string;
use grin_core::core::hash::Hashed;
use grin_core::core::{FeeFields, Output, OutputFeatures, Transaction};
use grin_core::libtx::proof;
use grin_keychain::ViewKey;
use grin_util::secp::{key::SecretKey, pedersen::Commitment};
use grin_util::ToHex;
use crate::api_impl::owner_updater::StatusMessage;
use crate::grin_keychain::{BlindingFactor, Identifier, Keychain, SwitchCommitmentType};
use crate::internal::{keys, scan, selection, tx, updater};
use crate::slate::{PaymentInfo, Slate, SlateState};
use crate::types::{AcctPathMapping, NodeClient, TxLogEntry, WalletInfo};
@@ -39,8 +37,9 @@ use crate::{
wallet_lock, BuiltOutput, Error, InitTxArgs, IssueInvoiceTxArgs, NodeHeightResult,
OutputCommitMapping, PaymentProof, RetrieveTxQueryArgs, ScannedBlockInfo, Slatepack,
SlatepackAddress, Slatepacker, SlatepackerArgs, TxLogEntryType, ViewWallet, WalletBackend,
WalletInitStatus, WalletInst, WalletLCProvider,
WalletInitStatus, WalletLCProvider,
};
use grin_keychain::{BlindingFactor, Identifier, Keychain, SwitchCommitmentType};
use ed25519_dalek::SigningKey as DalekSecretKey;
use ed25519_dalek::Verifier;
@@ -49,7 +48,6 @@ use x25519_dalek::{PublicKey as xPublicKey, StaticSecret};
use std::convert::{TryFrom, TryInto};
use std::sync::mpsc::Sender;
use std::sync::Arc;
/// List of accounts
pub fn accounts<C, K>(
@@ -103,7 +101,7 @@ where
/// Hash of the wallet root public key
pub fn get_rewind_hash<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
) -> Result<String, Error>
where
@@ -121,7 +119,7 @@ where
/// Retrieve the slatepack address for the current parent key at
/// the given index
pub fn get_slatepack_address<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
index: u32,
) -> Result<SlatepackAddress, Error>
@@ -140,7 +138,7 @@ where
/// Retrieve the decryption key for the current parent key
/// the given index
pub fn get_slatepack_secret_key<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
index: u32,
) -> Result<DalekSecretKey, Error>
@@ -159,7 +157,7 @@ where
/// Create a slatepack message from the given slate
pub fn create_slatepack_message<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
slate: &Slate,
sender_index: Option<u32>,
@@ -186,7 +184,7 @@ where
/// Unpack a slate from the given slatepack message,
/// optionally decrypting
pub fn slate_from_slatepack_message<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
slatepack: String,
secret_indices: Vec<u32>,
@@ -214,7 +212,7 @@ where
let packer = Slatepacker::new(SlatepackerArgs {
sender: None,
recipients: vec![],
dec_key: (&dec_key).as_ref(),
dec_key: dec_key.as_ref(),
});
let res = packer.deser_slatepack(slatepack.as_bytes(), true);
let slatepack = match res {
@@ -228,8 +226,7 @@ where
Err(Error::SlatepackDecryption(
"Could not decrypt slatepack with any provided index on the address derivation path"
.to_owned(),
)
.into())
))
}
}
@@ -237,7 +234,7 @@ where
/// Will decrypt if possible, otherwise will return
/// undecrypted slatepack
pub fn decode_slatepack_message<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
slatepack: String,
secret_indices: Vec<u32>,
@@ -264,7 +261,7 @@ where
let packer = Slatepacker::new(SlatepackerArgs {
sender: None,
recipients: vec![],
dec_key: (&dec_key).as_ref(),
dec_key: dec_key.as_ref(),
});
let res = packer.deser_slatepack(slatepack.as_bytes(), true);
let slatepack = match res {
@@ -281,7 +278,7 @@ where
/// retrieve outputs
pub fn retrieve_outputs<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
status_send_channel: &Option<Sender<StatusMessage>>,
include_spent: bool,
@@ -315,7 +312,7 @@ where
/// Calculate max amount to send.
pub fn estimate_max_sendable<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
status_send_channel: &Option<Sender<StatusMessage>>,
refresh_from_node: bool,
@@ -374,7 +371,7 @@ where
/// Retrieve txs
pub fn retrieve_txs<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
status_send_channel: &Option<Sender<StatusMessage>>,
refresh_from_node: bool,
@@ -414,7 +411,7 @@ where
/// Retrieve summary info
pub fn retrieve_summary_info<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
status_send_channel: &Option<Sender<StatusMessage>>,
refresh_from_node: bool,
@@ -444,7 +441,7 @@ where
/// Retrieve payment proof
pub fn retrieve_payment_proof<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
status_send_channel: &Option<Sender<StatusMessage>>,
refresh_from_node: bool,
@@ -864,7 +861,7 @@ where
let mut sl = slate.clone();
if sl.tx == None {
if sl.tx.is_none() {
sl.tx = Some(Slate::empty_transaction());
selection::repopulate_tx(w, keychain_mask, &mut sl, &context, true)?;
}
@@ -893,7 +890,7 @@ where
/// cancel tx
pub fn cancel_tx<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
status_send_channel: &Option<Sender<StatusMessage>>,
tx_id: Option<u32>,
@@ -932,11 +929,7 @@ where
{
let mut uuid = None;
if let Some(i) = tx_id {
let tx = w
.tx_log_iter()?
.filter(|tx| tx.is_ok())
.map(|tx| tx.unwrap())
.find(|t| t.id == i);
let tx = w.tx_log_iter()?.flatten().find(|t| t.id == i);
if let Some(t) = tx {
uuid = t.tx_slate_id;
}
@@ -992,7 +985,7 @@ where
/// Scan outputs with the rewind hash of a third-party wallet.
/// Help to retrieve outputs information that belongs it
pub fn scan_rewind_hash<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
rewind_hash: String,
start_height: Option<u64>,
status_send_channel: &Option<Sender<StatusMessage>>,
@@ -1013,7 +1006,7 @@ where
w.w2n_client().get_chain_tip()?
};
let start_height = start_height.unwrap_or_else(|| 1);
let start_height = start_height.unwrap_or(1);
let info = scan::scan_rewind_hash(
wallet_inst,
@@ -1029,7 +1022,7 @@ where
/// Accepts a wallet inst instead of a raw wallet so it can
/// lock as little as possible
pub fn scan<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
start_height: Option<u64>,
delete_unconfirmed: bool,
@@ -1046,7 +1039,7 @@ where
w.w2n_client().get_chain_tip()?
};
let start_height = start_height.unwrap_or_else(|| 1);
let start_height = start_height.unwrap_or(1);
// Scan every 10k heights to save data between batches in case of interruption.
let mut total_pmmr_range = None;
@@ -1081,7 +1074,7 @@ where
/// node height
pub fn node_height<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
) -> Result<NodeHeightResult, Error>
where
@@ -1101,12 +1094,7 @@ where
}),
Err(_) => {
let outputs = retrieve_outputs(wallet_inst, keychain_mask, &None, true, false, None)?;
let height = outputs
.1
.iter()
.map(|m| m.output.height)
.max()
.unwrap_or_else(|| 0);
let height = outputs.1.iter().map(|m| m.output.height).max().unwrap_or(0);
Ok(NodeHeightResult {
height,
header_hash: "".to_owned(),
@@ -1121,7 +1109,7 @@ pub const REORG_RESCAN_WINDOW: u64 = 24 * 60 * 2;
/// Experimental, wrap the entire definition of how a wallet's state is updated
pub fn update_wallet_state<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
status_send_channel: &Option<Sender<StatusMessage>>,
update_all: bool,
@@ -1275,10 +1263,8 @@ where
{
// Refuse if TTL is expired
let last_confirmed_height = w.last_confirmed_height()?;
if slate.ttl_cutoff_height != 0 {
if last_confirmed_height >= slate.ttl_cutoff_height {
return Err(Error::TransactionExpired);
}
if slate.ttl_cutoff_height != 0 && last_confirmed_height >= slate.ttl_cutoff_height {
return Err(Error::TransactionExpired);
}
Ok(())
}
@@ -1286,7 +1272,7 @@ where
/// Verify/validate arbitrary payment proof
/// Returns (whether this wallet is the sender, whether this wallet is the recipient)
pub fn verify_payment_proof<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
proof: &PaymentProof,
) -> Result<(bool, bool), Error>
@@ -1350,7 +1336,7 @@ where
/// Attempt to update outputs in wallet, return whether it was successful
fn update_outputs<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
update_all: bool,
) -> Result<bool, Error>
@@ -1374,9 +1360,9 @@ where
/// Update transactions that need to be validated via kernel lookup
fn update_txs_via_kernel<'a, L, C, K>(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
keychain_mask: Option<&SecretKey>,
txs: &mut Vec<TxLogEntry>,
txs: &mut [TxLogEntry],
) -> Result<bool, Error>
where
L: WalletLCProvider<'a, C, K>,
@@ -1515,30 +1501,29 @@ where
let mut blind_sum = new_output
.blind
.split(&BlindingFactor::from_secret_key(input_blind.clone()), &secp)?;
.split(&BlindingFactor::from_secret_key(input_blind.clone()), secp)?;
let hops = server_pubkeys
let hops: Vec<Hop> = server_pubkeys
.iter()
.enumerate()
.map(|(i, &p)| {
if (i + 1) == server_pubkeys.len() {
Hop {
server_pubkey: p.clone(),
excess: blind_sum.secret_key(&secp).unwrap(),
server_pubkey: p,
excess: blind_sum.secret_key(secp).unwrap(),
fee: FeeFields::from(fee as u32),
rangeproof: Some(new_output.output.proof.clone()),
rangeproof: Some(new_output.output.proof),
}
} else {
let hop_excess;
if use_test_rng {
hop_excess = BlindingFactor::zero();
let hop_excess = if use_test_rng {
BlindingFactor::zero()
} else {
hop_excess = BlindingFactor::rand(&secp);
}
blind_sum = blind_sum.split(&hop_excess, &secp).unwrap();
BlindingFactor::rand(secp)
};
blind_sum = blind_sum.split(&hop_excess, secp).unwrap();
Hop {
server_pubkey: p.clone(),
excess: hop_excess.secret_key(&secp).unwrap(),
server_pubkey: p,
excess: hop_excess.secret_key(secp).unwrap(),
fee: FeeFields::from(fee as u32),
rangeproof: None,
}
@@ -1546,7 +1531,7 @@ where
})
.collect();
let onion = create_onion(&commitment, &hops, use_test_rng).unwrap();
let onion = create_onion(commitment, &hops, use_test_rng).unwrap();
let comsig = ComSignature::sign(
amount,
&input_blind,
+7 -10
View File
@@ -19,14 +19,14 @@ use std::sync::Arc;
use std::thread;
use std::time::Duration;
use crate::grin_keychain::Keychain;
use crate::grin_util::secp::key::SecretKey;
use crate::grin_util::Mutex;
use grin_keychain::Keychain;
use grin_util::secp::key::SecretKey;
use grin_util::Mutex;
use crate::api_impl::owner;
use crate::types::NodeClient;
use crate::Error;
use crate::{WalletInst, WalletLCProvider};
use crate::WalletLCProvider;
const MESSAGE_QUEUE_MAX_LEN: usize = 10_000;
@@ -101,7 +101,7 @@ where
C: NodeClient + 'a,
K: Keychain + 'a,
{
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
wallet_inst: crate::WalletHandle<'a, L, C, K>,
is_running: Arc<AtomicBool>,
}
@@ -112,10 +112,7 @@ where
K: Keychain + 'a,
{
/// create a new updater
pub fn new(
wallet_inst: Arc<Mutex<Box<dyn WalletInst<'a, L, C, K>>>>,
is_running: Arc<AtomicBool>,
) -> Self {
pub fn new(wallet_inst: crate::WalletHandle<'a, L, C, K>, is_running: Arc<AtomicBool>) -> Self {
is_running.store(false, Ordering::Relaxed);
Updater {
wallet_inst,
@@ -141,7 +138,7 @@ where
if wallet_opened {
owner::update_wallet_state(
self.wallet_inst.clone(),
(&keychain_mask).as_ref(),
keychain_mask.as_ref(),
status_send_channel,
false,
)?;
+5 -15
View File
@@ -14,14 +14,14 @@
//! Types specific to the wallet api, mostly argument serialization
use crate::grin_core::core::Output;
use crate::grin_core::libtx::secp_ser;
use crate::grin_keychain::{BlindingFactor, Identifier};
use crate::grin_util::secp::pedersen;
use crate::slate_versions::ser as dalek_ser;
use crate::slate_versions::SlateVersion;
use crate::types::OutputData;
use crate::{Error, NodeClient, Slate, SlatepackAddress, WalletBackend};
use grin_core::core::Output;
use grin_core::libtx::secp_ser;
use grin_keychain::{BlindingFactor, Identifier};
use grin_util::secp::pedersen;
use chrono::prelude::*;
use ed25519_dalek::Signature as DalekSignature;
@@ -132,7 +132,7 @@ impl Default for InitTxArgs {
}
/// V2 Issue Invoice Tx Args
#[derive(Clone, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize, Default)]
pub struct IssueInvoiceTxArgs {
/// The human readable account name to which the received funds should be added
/// overriding whatever the active account is as set via the
@@ -147,16 +147,6 @@ pub struct IssueInvoiceTxArgs {
pub target_slate_version: Option<u16>,
}
impl Default for IssueInvoiceTxArgs {
fn default() -> IssueInvoiceTxArgs {
IssueInvoiceTxArgs {
dest_acct_name: None,
amount: 0,
target_slate_version: None,
}
}
}
/// Sort tx retrieval order
#[derive(Clone, Serialize, Deserialize)]
pub enum RetrieveTxQuerySortOrder {