Skip to content

Commit

Permalink
fix: clippy and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Apr 16, 2024
1 parent ffeb702 commit 03b7822
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
4 changes: 3 additions & 1 deletion cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
38 changes: 19 additions & 19 deletions cmd/soroban-cli/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -18,18 +19,18 @@ pub enum Error {
}

fn requires_auth(txn: &Transaction) -> Option<xdr::Operation> {
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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -154,7 +155,6 @@ pub trait Stellar {
}
}


use std::fmt::Debug;
#[derive(Debug)]
pub struct InMemory {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 03b7822

Please sign in to comment.