Skip to content

Commit

Permalink
feat: add more logs for evmlib
Browse files Browse the repository at this point in the history
  • Loading branch information
ermineJose committed Nov 20, 2024
1 parent 54345a7 commit 4b0d60a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions evmlib/src/cryptography.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub fn sign_message(evm_secret_key_str: &str, message: &[u8]) -> Result<Vec<u8>,

let message_hash = to_eth_signed_message_hash(message);
let (signature, _) = sign_message_recoverable(&signer.into_credential(), message_hash)?;
debug!("Message signed with evm scret key successfully");
Ok(signature.to_vec())
}

Expand Down
10 changes: 7 additions & 3 deletions evmlib/src/external_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ pub fn approve_to_spend_tokens_calldata(
) -> (Calldata, Address) {
let provider = http_provider(network.rpc_url().clone());
let network_token = NetworkToken::new(*network.payment_token_address(), provider);
network_token.approve_calldata(spender, value)
let ret_value = network_token.approve_calldata(spender, value);
debug!("spend tokens calldata is approved");
ret_value
}

/// Transfer payment tokens from the supplied wallet to an address.
Expand Down Expand Up @@ -87,10 +89,12 @@ pub fn pay_for_quotes_calldata<T: IntoIterator<Item = QuotePayment>>(
calldata_map.insert(calldata, quote_hashes);
}

Ok(PayForQuotesCalldataReturnType {
let return_value = Ok(PayForQuotesCalldataReturnType {
batched_calldata_map: calldata_map,
to: *data_payments.contract.address(),
approve_spender,
approve_amount,
})
});
debug!("pay for quotes calldata is approved");
return_value
}
15 changes: 11 additions & 4 deletions evmlib/src/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use alloy::providers::fillers::{
use alloy::providers::{Identity, ProviderBuilder, ReqwestProvider};
use alloy::signers::local::PrivateKeySigner;
use alloy::transports::http::{Client, Http};
use serde::de;

pub struct Testnet {
anvil: AnvilInstance,
Expand All @@ -37,7 +38,7 @@ impl Testnet {
let data_payments =
deploy_data_payments_contract(&rpc_url, &anvil, *network_token.contract.address())
.await;

debug!("Instantiated a testnet");
Testnet {
anvil,
rpc_url,
Expand Down Expand Up @@ -80,7 +81,7 @@ pub fn start_node() -> (AnvilInstance, Url) {
.expect("Could not spawn Anvil node");

let url = Url::parse(&format!("http://{host}:{port}")).expect("Failed to parse URL");

debug!("Started Anvil node at {url}");
(anvil, url)
}

Expand Down Expand Up @@ -113,7 +114,10 @@ pub async fn deploy_network_token_contract(
.on_http(rpc_url.clone());

// Deploy the contract.
NetworkToken::deploy(provider).await
let deployed = NetworkToken::deploy(provider).await;
let address = *deployed.contract.address();
debug!("Deployed network token contract at {address}");
deployed
}

pub async fn deploy_data_payments_contract(
Expand Down Expand Up @@ -146,5 +150,8 @@ pub async fn deploy_data_payments_contract(
.on_http(rpc_url.clone());

// Deploy the contract.
DataPaymentsHandler::deploy(provider, token_address).await
let deployed = DataPaymentsHandler::deploy(provider, token_address).await;
let address = *deployed.contract.address();
debug!("Deployed data payments contract at {address}");
deployed
}
3 changes: 3 additions & 0 deletions evmlib/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub async fn get_transaction_receipt_by_hash(
.get_transaction_receipt(transaction_hash)
.await
.inspect_err(|err| error!("Error getting transaction receipt for transaction_hash: {transaction_hash:?} : {err:?}", ))?;
debug!("Transaction receipt for {transaction_hash:?} : {maybe_receipt:?}",);
Ok(maybe_receipt)
}

Expand All @@ -57,6 +58,7 @@ async fn get_block_by_number(network: &Network, block_number: u64) -> Result<Opt
.get_block_by_number(BlockNumberOrTag::Number(block_number), true)
.await
.inspect_err(|err| error!("Error getting block by number for {block_number} : {err:?}",))?;
debug!("Block for {block_number} : {block:?}",);
Ok(block)
}

Expand All @@ -69,6 +71,7 @@ async fn get_transaction_logs(network: &Network, filter: Filter) -> Result<Vec<L
.get_logs(&filter)
.await
.inspect_err(|err| error!("Error getting logs for filter: {filter:?} : {err:?}"))?;
debug!("Transaction logs is fetched");
Ok(logs)
}

Expand Down

0 comments on commit 4b0d60a

Please sign in to comment.