From 03b782267f578890858fc16a838b53e54a33f9e1 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Tue, 16 Apr 2024 16:23:33 -0400 Subject: [PATCH] fix: clippy and fmt --- .../src/commands/contract/invoke.rs | 4 +- cmd/soroban-cli/src/signer.rs | 38 +++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index 00d7383d7d..d297f9c547 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -21,7 +21,9 @@ use soroban_env_host::{ HostError, }; -use soroban_sdk::xdr::{AccountEntry, AccountEntryExt, AccountId, ContractDataEntry, DiagnosticEvent, Thresholds}; +use soroban_sdk::xdr::{ + AccountEntry, AccountEntryExt, AccountId, ContractDataEntry, DiagnosticEvent, Thresholds, +}; use soroban_spec::read::FromWasmError; use stellar_strkey::DecodeError; diff --git a/cmd/soroban-cli/src/signer.rs b/cmd/soroban-cli/src/signer.rs index 1f6ad84899..bd56055984 100644 --- a/cmd/soroban-cli/src/signer.rs +++ b/cmd/soroban-cli/src/signer.rs @@ -3,10 +3,11 @@ use sha2::{Digest, Sha256}; use soroban_env_host::xdr::{ self, AccountId, DecoratedSignature, Hash, HashIdPreimage, HashIdPreimageSorobanAuthorization, - Limits, OperationBody, PublicKey, ScAddress, ScMap, ScSymbol, ScVal, Signature, SignatureHint, - SorobanAddressCredentials, SorobanAuthorizationEntry, SorobanCredentials, Transaction, - TransactionEnvelope, TransactionSignaturePayload, TransactionSignaturePayloadTaggedTransaction, - TransactionV1Envelope, Uint256, WriteXdr, Operation, InvokeHostFunctionOp, SorobanAuthorizedFunction, + InvokeHostFunctionOp, Limits, Operation, OperationBody, PublicKey, ScAddress, ScMap, ScSymbol, + ScVal, Signature, SignatureHint, SorobanAddressCredentials, SorobanAuthorizationEntry, + SorobanAuthorizedFunction, SorobanCredentials, Transaction, TransactionEnvelope, + TransactionSignaturePayload, TransactionSignaturePayloadTaggedTransaction, + TransactionV1Envelope, Uint256, WriteXdr, }; #[derive(thiserror::Error, Debug)] @@ -18,18 +19,18 @@ pub enum Error { } fn requires_auth(txn: &Transaction) -> Option { - let [op @ Operation { - body: OperationBody::InvokeHostFunction(InvokeHostFunctionOp { auth, .. }), - .. - }] = txn.operations.as_slice() - else { - return None; - }; - matches!( - auth.first().map(|x| &x.root_invocation.function), - Some(&SorobanAuthorizedFunction::ContractFn(_)) - ) - .then(move || op.clone()) + let [op @ Operation { + body: OperationBody::InvokeHostFunction(InvokeHostFunctionOp { auth, .. }), + .. + }] = txn.operations.as_slice() + else { + return None; + }; + matches!( + auth.first().map(|x| &x.root_invocation.function), + Some(&SorobanAuthorizedFunction::ContractFn(_)) + ) + .then(move || op.clone()) } /// A trait for signing Stellar transactions and Soroban authorization entries @@ -74,7 +75,7 @@ pub trait Stellar { network_id: self.network_hash(), tagged_transaction: TransactionSignaturePayloadTaggedTransaction::Tx(txn.clone()), }; - let hash = Sha256::digest(&signature_payload.to_xdr(Limits::none())?).into(); + let hash = Sha256::digest(signature_payload.to_xdr(Limits::none())?).into(); let decorated_signature = self.sign_txn_hash(hash, source_account)?; Ok(TransactionEnvelope::Tx(TransactionV1Envelope { tx: txn, @@ -154,7 +155,6 @@ pub trait Stellar { } } - use std::fmt::Debug; #[derive(Debug)] pub struct InMemory { @@ -234,7 +234,7 @@ impl Stellar for InMemory { .to_xdr(Limits::none())?; let strkey = stellar_strkey::ed25519::PublicKey(*signer); - let payload = Sha256::digest(&preimage); + let payload = Sha256::digest(preimage); let signer = self.get_key(&stellar_strkey::Strkey::PublicKeyEd25519(strkey))?; let signature = signer.sign(&payload);