Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
gfusee committed May 31, 2024
1 parent ce498ce commit 4417151
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion caching/src/date/get_current_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod implementation {
use core::time::Duration;

thread_local! {
static MOCK_TIME: RefCell<Duration> = RefCell::new(Duration::from_secs(0));
static MOCK_TIME: RefCell<Duration> = const { RefCell::new(Duration::from_secs(0)) };
}

pub(crate) fn get_current_timestamp() -> Result<Duration, NovaXError> {
Expand Down
4 changes: 1 addition & 3 deletions core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ fn main() {
//
// In a few versions of the Rust SDK, the upgrade function was an endpoint in the ABI.
// It is now under the field upgradeConstructor.
abi.endpoints = abi.endpoints.into_iter()
.filter(|endpoint| endpoint.name != "upgrade")
.collect();
abi.endpoints.retain(|endpoint| endpoint.name != "upgrade");

let abi_generated_file = generate_from_abi(&abi).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion executor/src/dummy/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl TransactionExecutor for DummyExecutor<SendableTransaction> {
esdt_transfers,
}.normalize()?;

self.tx = Some(normalized.to_sendable_transaction(gas_limit));
self.tx = Some(normalized.into_sendable_transaction(gas_limit));

let dummy_result = CallResult {
response: Default::default(),
Expand Down
4 changes: 2 additions & 2 deletions executor/src/network/query/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl QueryExecutor for String {

fn encode_arguments(arguments: &[Vec<u8>]) -> Vec<String> {
arguments.iter()
.map(|arg| hex::encode(arg))
.map(hex::encode)
.collect()
}

Expand All @@ -162,7 +162,7 @@ mod tests {

#[test]
fn test_encode_arguments_empty() {
let result = encode_arguments(&vec![]);
let result = encode_arguments(&[]);
let expected: Vec<String> = vec![];

assert_eq!(result, expected);
Expand Down
5 changes: 3 additions & 2 deletions executor/src/network/transaction/interactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub enum TransactionRefreshStrategy {

impl Interactor {
async fn get_account_info(&self) -> Result<AddressGatewayInfoAccount, ExecutorError> {
let address = Address::from(self.wallet.get_address());
let address = self.wallet.get_address();

Ok(get_address_info(&self.gateway_url, address).await?.account)
}
Expand Down Expand Up @@ -85,7 +85,8 @@ impl Interactor {
}
}
}


#[allow(clippy::too_many_arguments)]
fn get_sendable_transaction(
&self,
nonce: u64,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ impl TransactionOnNetwork {
return true
};

if let Ok(None) = find_sc_error(logs) {
true
} else {
false
}
matches!(find_sc_error(logs), Ok(None))
}
}

Expand Down
2 changes: 1 addition & 1 deletion executor/src/utils/date/get_current_timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod implementation {
use crate::ExecutorError;

thread_local! {
static MOCK_TIME: RefCell<Duration> = RefCell::new(Duration::from_secs(0));
static MOCK_TIME: RefCell<Duration> = const { RefCell::new(Duration::from_secs(0)) };
}

pub(crate) fn get_current_timestamp() -> Result<Duration, ExecutorError> {
Expand Down
2 changes: 1 addition & 1 deletion executor/src/utils/transaction/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn get_deploy_call_input(
gas_limit: u64
) -> DeployCallInput {
let mut encoded_metadata: ManagedBuffer<StaticApi> = ManagedBuffer::new();
_ = code_metadata.top_encode(&mut encoded_metadata).unwrap();
code_metadata.top_encode(&mut encoded_metadata).unwrap();

let built_in_arguments: Vec<Vec<u8>> = vec![
bytes,
Expand Down
38 changes: 25 additions & 13 deletions executor/src/utils/transaction/normalization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ pub struct NormalizationInOut {
pub esdt_transfers: Vec<TokenTransfer>
}

struct TokenPaymentBytes {
token_identifier: Vec<u8>,
nonce: Vec<u8>,
amount: Vec<u8>
}

impl NormalizationInOut {
pub fn normalize(mut self) -> Result<NormalizationInOut, ExecutorError> {
let esdt_transfers_len = self.esdt_transfers.len();
Expand All @@ -26,23 +32,23 @@ impl NormalizationInOut {
} else if esdt_transfers_len == 1 {
let transfer = self.esdt_transfers.remove(0);
let is_fungible = transfer.nonce == 0;
let (encoded_identifier, encoded_nonce, encoded_amount) = encode_transfer(transfer)?;
let encoded_token_payment = encode_transfer(transfer)?;


let (receiver, function_name, mut built_in_args) = if is_fungible {
let function_name = "ESDTTransfer".to_string();
let built_in_args = vec![
encoded_identifier,
encoded_amount
encoded_token_payment.token_identifier,
encoded_token_payment.amount
];

(self.receiver, Some(function_name), built_in_args)
} else {
let function_name = "ESDTNFTTransfer".to_string();
let built_in_args = vec![
encoded_identifier,
encoded_nonce,
encoded_amount,
encoded_token_payment.token_identifier,
encoded_token_payment.nonce,
encoded_token_payment.amount,
Address::from_bech32_string(&self.receiver)?.to_bytes().to_vec(),
];

Expand Down Expand Up @@ -74,11 +80,11 @@ impl NormalizationInOut {
];

for transfer in self.esdt_transfers {
let (encoded_identifier, encoded_nonce, encoded_amount) = encode_transfer(transfer)?;
let encoded_token_payment = encode_transfer(transfer)?;

built_in_args.push(encoded_identifier);
built_in_args.push(encoded_nonce);
built_in_args.push(encoded_amount);
built_in_args.push(encoded_token_payment.token_identifier);
built_in_args.push(encoded_token_payment.nonce);
built_in_args.push(encoded_token_payment.amount);
}

if let Some(function_name) = self.function_name {
Expand Down Expand Up @@ -117,7 +123,7 @@ impl NormalizationInOut {
args_string.join("@")
}

pub fn to_sendable_transaction(self, gas_limit: u64) -> SendableTransaction {
pub fn into_sendable_transaction(self, gas_limit: u64) -> SendableTransaction {
SendableTransaction {
receiver: self.receiver.clone(),
egld_value: self.egld_value.clone(),
Expand All @@ -142,7 +148,7 @@ fn encode_u64(value: u64) -> Vec<u8> {
bytes
}

fn encode_transfer(token_transfer: TokenTransfer) -> Result<(Vec<u8>, Vec<u8>, Vec<u8>), ExecutorError> {
fn encode_transfer(token_transfer: TokenTransfer) -> Result<TokenPaymentBytes, ExecutorError> {
let encoded_identifier = encode_string(&token_transfer.identifier)
.map_err(|_| TransactionError::CannotEncodeTransfer)?;

Expand All @@ -151,7 +157,13 @@ fn encode_transfer(token_transfer: TokenTransfer) -> Result<(Vec<u8>, Vec<u8>, V
let encoded_amount = hex::decode(hex::encode(token_transfer.amount.to_bytes_be()))
.map_err(|_| TransactionError::CannotEncodeTransfer)?;

Ok((encoded_identifier, encoded_nonce, encoded_amount))
let result = TokenPaymentBytes {
token_identifier: encoded_identifier,
nonce: encoded_nonce,
amount: encoded_amount,
};

Ok(result)
}

#[cfg(test)]
Expand Down
1 change: 1 addition & 0 deletions tester/core/tests/network_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ async fn get_executor() -> Arc<Mutex<BaseTransactionNetworkExecutor<MockInteract
}

// The below test is a success if it compiles
#[allow(clippy::map_clone)]
#[tokio::test]
async fn test_clone_network_executor() -> Result<(), NovaXError> {
let wallet = Wallet::from_private_key(CALLER_PRIVATE_KEY).unwrap();
Expand Down

0 comments on commit 4417151

Please sign in to comment.