Skip to content

Commit

Permalink
global fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
willemolding committed Mar 24, 2024
1 parent c88b89c commit 4804db1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 29 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cartezcash-proxy = { path = "cartezcash-proxy", optional = true }


[workspace]
members = [ "cartezcash-proxy", "tiny-cash", "tower-cartesi"]
members = [ "cartezcash-proxy", "tiny-cash"]

[workspace.dependencies]

Expand Down
4 changes: 2 additions & 2 deletions cartezcash-proxy/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::proto::service::compact_tx_streamer_server::CompactTxStreamerServer;
///
/// Runs a lightwalletd gRPC server that translates requests into HTTP requests to the /inspect API of a Cartesi machine running CarteZcash
/// Any ZCash wallet should be able to use this proxy to sync with the CarteZcash rollup
///
///
use std::env;
use crate::proto::service::compact_tx_streamer_server::CompactTxStreamerServer;
use tonic::transport::Server;
use tower::buffer::Buffer;

Expand Down
12 changes: 10 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,18 @@ async fn main() -> Result<(), anyhow::Error> {
client.request(report_request).await?;
}

if let (Request::AdvanceState(AdvanceStateRequest::Transact { withdraw_address, .. }), Response::Accept { ref burned }) = (&dapp_request, &status) {
if let (
Request::AdvanceState(AdvanceStateRequest::Transact {
withdraw_address, ..
}),
Response::Accept { ref burned },
) = (&dapp_request, &status)
{
if burned > &0 {
tracing::info!("Detected {} coins burned, sending withdraw voucher", burned);
if let Some(voucher_request) = status.voucher_request(&server_addr, *withdraw_address, (*burned).into()) {
if let Some(voucher_request) =
status.voucher_request(&server_addr, *withdraw_address, (*burned).into())
{
tracing::info!("Sending voucher: {:?}", voucher_request.body());
let res = client.request(voucher_request).await?;
tracing::info!("Voucher response: {:?}", res.status());
Expand Down
37 changes: 27 additions & 10 deletions src/service/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,21 @@ impl std::fmt::Debug for AdvanceStateRequest {
AdvanceStateRequest::Deposit { amount, to } => {
write!(f, "Deposit {} to {}", amount, to)
}
AdvanceStateRequest::Transact { withdraw_address, txn } => {
write!(f, "Transact hash {} with withdrawal address {}", txn.hash(), withdraw_address)
AdvanceStateRequest::Transact {
withdraw_address,
txn,
} => {
write!(
f,
"Transact hash {} with withdrawal address {}",
txn.hash(),
withdraw_address
)
}
}
}
}


const ETH_DEPOSIT_ADDR: &str = "0xffdbe43d4c855bf7e0f105c400a50857f53ab044";
const INBOX_CONTRACT_ADDR: &str = "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266";

Expand Down Expand Up @@ -100,7 +107,11 @@ impl TryFrom<JsonValue> for AdvanceStateRequest {
);
let amount = Amount::try_from(value.as_u64())?; // FIX: This is going to panic if too much eth is sent

tracing::info!("Received deposit request for {} to {}", value, dest_t_address);
tracing::info!(
"Received deposit request for {} to {}",
value,
dest_t_address
);

Ok(AdvanceStateRequest::Deposit {
amount,
Expand All @@ -116,15 +127,21 @@ impl TryFrom<JsonValue> for AdvanceStateRequest {
let hex = req["data"]["payload"].as_str().unwrap();
let bytes = hex::decode(hex.trim_start_matches("0x"))?;

let withdraw_address = ethereum_types::Address::from_slice(bytes[0..20].try_into().unwrap());
let withdraw_address =
ethereum_types::Address::from_slice(bytes[0..20].try_into().unwrap());

let txn = zebra_chain::transaction::Transaction::zcash_deserialize(
&bytes[20..],
)?;
let txn = zebra_chain::transaction::Transaction::zcash_deserialize(&bytes[20..])?;

tracing::info!("Received transaction request {} send burns to {}", txn.hash(), withdraw_address);
tracing::info!(
"Received transaction request {} send burns to {}",
txn.hash(),
withdraw_address
);

Ok(AdvanceStateRequest::Transact { withdraw_address, txn })
Ok(AdvanceStateRequest::Transact {
withdraw_address,
txn,
})
}
_ => anyhow::bail!("unrecognised sender"),
}
Expand Down
13 changes: 9 additions & 4 deletions src/service/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ use json::object;

#[derive(Clone, Debug)]
pub enum Response {
Accept { burned: u64 },
Report { payload: Vec<u8> },
Accept {
burned: u64,
},
Report {
payload: Vec<u8>,
},
#[allow(dead_code)]
Reject,
}
Expand Down Expand Up @@ -82,8 +86,9 @@ impl Response {
fn withdraw_ether_call(receiver: ethereum_types::Address, value: ethereum_types::U256) -> Vec<u8> {
let function = alloy_json_abi::Function::parse("withdrawEther(address,uint256)").unwrap();

let encoded_params = ethabi::encode(&[ethabi::Token::Address(receiver), ethabi::Token::Uint(value)]);

let encoded_params =
ethabi::encode(&[ethabi::Token::Address(receiver), ethabi::Token::Uint(value)]);

let mut encoded = Vec::new();
encoded.extend_from_slice(&function.selector().as_slice());
encoded.extend_from_slice(&encoded_params);
Expand Down

0 comments on commit 4804db1

Please sign in to comment.