Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter input #1056

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions src/components/abciapp/src/abci/server/callback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub fn check_tx(s: &mut ABCISubmissionServer, req: &RequestCheckTx) -> ResponseC
let mut body_signatures = op.body_signatures.clone();
body_signatures.dedup();
if body_signatures.len() > 1 {
resp.log = "too many body_signatures".to_owned();
"too many body_signatures".clone_into(&mut resp.log);
resp.code = 1;
return resp;
}
Expand All @@ -165,25 +165,25 @@ pub fn check_tx(s: &mut ABCISubmissionServer, req: &RequestCheckTx) -> ResponseC
let mut signatures = tx.signatures.clone();
signatures.dedup();
if signatures.len() > 1 {
resp.log = "Too many signatures".to_owned();
"Too many signatures".clone_into(&mut resp.log);
resp.code = 1;
return resp;
}

if tx.pubkey_sign_map.len() > 1 {
resp.log = "too many pubkey_sign_map".to_owned();
"too many pubkey_sign_map".clone_into(&mut resp.log);
resp.code = 1;
return resp;
}
} else if !tx.valid_in_abci() {
resp.log = "Should not appear in ABCI".to_owned();
"Should not appear in ABCI".clone_into(&mut resp.log);
resp.code = 1;
} else if TX_HISTORY.read().contains_key(&tx.hash_tm_rawbytes()) {
resp.log = "Historical transaction".to_owned();
"Historical transaction".clone_into(&mut resp.log);
resp.code = 1;
}
} else {
resp.log = "Invalid format".to_owned();
"Invalid format".clone_into(&mut resp.log);
resp.code = 1;
}
}
Expand All @@ -194,15 +194,15 @@ pub fn check_tx(s: &mut ABCISubmissionServer, req: &RequestCheckTx) -> ResponseC
&& td_height < CFG.checkpoint.enable_frc20_height
{
resp.code = 2;
resp.log = "EVM is disabled".to_owned();
"EVM is disabled".clone_into(&mut resp.log);
resp
} else {
s.account_base_app.read().check_tx(req)
}
}
TxCatalog::Unknown => {
resp.code = 1;
resp.log = "Unknown transaction".to_owned();
"Unknown transaction".clone_into(&mut resp.log);
resp
}
}
Expand Down Expand Up @@ -300,7 +300,7 @@ pub fn deliver_tx(
let mut body_signatures = op.body_signatures.clone();
body_signatures.dedup();
if body_signatures.len() > 1 {
resp.log = "too many body_signatures".to_owned();
"too many body_signatures".clone_into(&mut resp.log);
resp.code = 1;
return resp;
}
Expand All @@ -309,13 +309,13 @@ pub fn deliver_tx(
let mut signatures = tx.signatures.clone();
signatures.dedup();
if signatures.len() > 1 {
resp.log = "Too many signatures".to_owned();
"Too many signatures".clone_into(&mut resp.log);
resp.code = 1;
return resp;
}

if tx.pubkey_sign_map.len() > 1 {
resp.log = "too many pubkey_sign_map".to_owned();
"too many pubkey_sign_map".clone_into(&mut resp.log);
resp.code = 1;
return resp;
}
Expand Down Expand Up @@ -347,7 +347,7 @@ pub fn deliver_tx(
{
if is_convert_account(&tx) {
resp.code = 2;
resp.log = "EVM is disabled".to_owned();
"EVM is disabled".clone_into(&mut resp.log);
return resp;
} else if let Err(e) = s.la.write().cache_transaction(tx) {
resp.code = 1;
Expand Down Expand Up @@ -398,7 +398,7 @@ pub fn deliver_tx(
return resp;
} else if td_height > CFG.checkpoint.fix_exec_code {
resp.code = 1;
resp.log = "cache_transaction failed".to_owned();
"cache_transaction failed".clone_into(&mut resp.log);
}

s.account_base_app
Expand Down Expand Up @@ -432,11 +432,11 @@ pub fn deliver_tx(
}
} else {
resp.code = 1;
resp.log = "Should not appear in ABCI".to_owned();
"Should not appear in ABCI".clone_into(&mut resp.log);
}
} else {
resp.code = 1;
resp.log = "Invalid format".to_owned();
"Invalid format".clone_into(&mut resp.log);
}

resp
Expand All @@ -446,7 +446,7 @@ pub fn deliver_tx(
&& td_height < CFG.checkpoint.enable_frc20_height
{
resp.code = 2;
resp.log = "EVM is disabled".to_owned();
"EVM is disabled".clone_into(&mut resp.log);
resp
} else {
// Log print for monitor purpose
Expand Down Expand Up @@ -495,7 +495,7 @@ pub fn deliver_tx(
}
TxCatalog::Unknown => {
resp.code = 1;
resp.log = "Unknown transaction".to_owned();
"Unknown transaction".clone_into(&mut resp.log);
resp
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/components/config/src/abci/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,10 +1019,14 @@ pub mod global_cfg {
if let Some(sm) = m.value_of("snapshot-mode") {
res.mode = SnapMode::from_string(sm).c(d!())?;
if !matches!(res.mode, SnapMode::External) {
res.target = m.value_of("snapshot-target").c(d!())?.to_owned();
m.value_of("snapshot-target")
.c(d!())?
.clone_into(&mut res.target);
}
} else {
res.target = m.value_of("snapshot-target").c(d!())?.to_owned();
m.value_of("snapshot-target")
.c(d!())?
.clone_into(&mut res.target);
res.mode = res.guess_mode().c(d!())?;
}

Expand All @@ -1038,7 +1042,9 @@ pub mod global_cfg {
|| m.is_present("snapshot-rollback-to-exact")
{
// this field should be parsed at the top
res.target = m.value_of("snapshot-target").c(d!())?.to_owned();
m.value_of("snapshot-target")
.c(d!())?
.clone_into(&mut res.target);

// the guess should always success in this scene
res.mode = res.guess_mode().c(d!())?;
Expand Down
6 changes: 3 additions & 3 deletions src/components/contracts/baseapp/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl crate::BaseApp {
/// - Tendermint uses info to decide from which height/hash to continue
pub fn info(&mut self, _req: &RequestInfo) -> ResponseInfo {
let mut info: ResponseInfo = Default::default();
info.data = self.name.clone();
info.version = self.version.clone();
info.data.clone_from(&self.name);
info.version.clone_from(&self.version);
info.app_version = self.app_version;

let height = self.chain_state.read().height().unwrap();
Expand Down Expand Up @@ -166,7 +166,7 @@ impl crate::BaseApp {
/// init_chain implements the ABCI interface.
pub fn init_chain(&mut self, req: &RequestInitChain) -> ResponseInitChain {
let mut init_header: Header = Default::default();
init_header.chain_id = req.chain_id.clone();
init_header.chain_id.clone_from(&req.chain_id);
init_header.time = req.time.clone();

// initialize the deliver state and check state with a correct header
Expand Down
14 changes: 7 additions & 7 deletions src/components/contracts/primitives/types/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use primitive_types::{H160, H256};
use ruc::{d, eg, RucResult};
use serde::{Deserialize, Serialize};
use sha3::{Digest, Keccak256};
use std::fmt::Display;
use std::ops::{Deref, DerefMut};
use zei::serialization::ZeiFromToBytes;
use zei::xfr::sig::{XfrPublicKey, XfrSignature};
Expand Down Expand Up @@ -127,10 +128,9 @@ impl DerefMut for HA160 {
&mut self.0
}
}

impl ToString for HA160 {
fn to_string(&self) -> String {
hex::encode_upper(self.0)
impl Display for HA160 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", hex::encode_upper(self.0))
}
}

Expand Down Expand Up @@ -164,9 +164,9 @@ impl HA256 {
}
}

impl ToString for HA256 {
fn to_string(&self) -> String {
hex::encode_upper(self.0)
impl Display for HA256 {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", hex::encode_upper(self.0))
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/components/finutils/src/bins/fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,16 @@ fn run() -> Result<()> {
(name, desc, website, logo) => {
let mut memo = StakerMemo::default();
if let Some(n) = name {
memo.name = n.to_owned();
n.clone_into(&mut memo.name);
}
if let Some(d) = desc {
memo.desc = d.to_owned();
d.clone_into(&mut memo.desc);
}
if let Some(w) = website {
memo.website = w.to_owned();
w.clone_into(&mut memo.website);
}
if let Some(l) = logo {
memo.logo = l.to_owned();
l.clone_into(&mut memo.logo);
}
Some(memo)
}
Expand Down
23 changes: 3 additions & 20 deletions src/components/finutils/src/txn_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,9 @@ impl TransferOperationBuilder {
identity_commitment: Option<ACCommitment>,
amount: u64,
) -> Result<&mut Self> {
if amount == 0 {
return Ok(self);
}
if self.transfer.is_some() {
return Err(eg!(
("Cannot mutate a transfer that has been signed".to_string())
Expand Down Expand Up @@ -1215,26 +1218,6 @@ mod tests {
zei::xfr::sig::XfrKeyPair,
};

// Defines an asset type
#[derive(Clone, Debug, Eq, PartialEq)]
struct AssetType(pub u8);

#[derive(Clone, Debug, Eq, PartialEq)]
struct KeyPair(pub u8);

#[derive(Clone, Debug, Eq, PartialEq)]
struct TxoReference(pub u64);

// Defines an input record
// (type, amount, conf_type, conf_amount, traceable)
#[derive(Clone, Debug, Eq, PartialEq)]
struct InputRecord(pub u64, pub AssetType, pub bool, pub bool, pub bool);

// Defines an output record
// (amount, asset type, keypair)
#[derive(Clone, Debug, Eq, PartialEq)]
struct OutputRecord(pub u64, pub AssetType, pub KeyPair);

#[test]
fn test_transfer_op_builder() {
pnk!(test_transfer_op_builder_inner());
Expand Down
3 changes: 2 additions & 1 deletion src/ledger/src/staking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ pub const FF_ADDR_LIST: [&str; 8] = [
"fra1mjdr0mgn2e0670hxptpzu9tmf0ary8yj8nv90znjspwdupv9aacqwrg3dx",
"fra1whn756rtqt3gpsmdlw6pvns75xdh3ttqslvxaf7eefwa83pcnlhsree9gv",
];
///

#[allow(missing_docs)]
pub const FF_ADDR_EXTRA_120_0000: &str =
"fra1dkn9w5c674grdl6gmvj0s8zs0z2nf39zrmp3dpq5rqnnf9axwjrqexqnd6";

Expand Down
2 changes: 1 addition & 1 deletion src/ledger/src/staking/ops/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct ClaimOps {
pub(crate) body: Data,
pub(crate) pubkey: XfrPublicKey,
signature: XfrSignature,
///
#[allow(missing_docs)]
#[serde(skip_serializing_if = "Option::is_none")]
pub td_addr: Option<Vec<u8>>,
}
Expand Down
Loading