Skip to content

Commit

Permalink
Merge pull request #37 from willemolding/willem/handle-dapp-address-r…
Browse files Browse the repository at this point in the history
…elay-messages

more explicitly handle relaying dapp address
  • Loading branch information
willemolding authored May 23, 2024
2 parents 077dcc0 + dac24eb commit e653daf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .env.local
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ROLLUP_HTTP_SERVER_URL=http://127.0.0.1:8080/host-runner
ROLLUP_HTTP_SERVER_URL=http://127.0.0.1:8080/graphql
GRPC_SERVER_URL="[::1]:50051"
ETH_RPC_URL="http://127.0.0.1:8545"
ETH_CHAIN_ID=31337
SIGNER_PK="ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
INPUTBOX_CONTRACT_ADDRESS="0x59b22D57D4f067708AB0c00552767405926dc768"
ETH_DEPOSIT_ADDR="0xFfdbe43d4c855BF7e0f105c400A50857f53AB044"
DAPP_ADDRESS="0xab7528bb862fB57E8A2BCd567a2e929a0Be56a5e"
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,25 @@ This cross-compiles for risvc using docker.

### Setup

#### Terminal 1 - Rollup Node

##### Local Mode
#### Option 1 - Local Mode

This runs CarteZcash locally rather than inside the Cartesi machine. This is a bit faster and easier to debug.

Start the Sunodo services (Anvil, cartesi node, subsquid, etc) with:

```shell
run-nobackend # or cartesi run --no-backend
just run-nobackend # or cartesi run --no-backend
```

in another shell run the dApp in local mode

```shell
just run-local
```

##### Cartesi Machine Mode
This command runs the program in fullnode mode so there is no need to run another process.

#### Option 1 - Cartesi Machine Mode

If you want to see it running in the Cartesi machine for real then build and run with

Expand All @@ -190,17 +195,17 @@ cartesi build
cartesi run
```

#### Terminal 2 - Proxy
We also need to run a fullnode process. The full node is required to cache blockchain state and serve data to wallets.

Start the proxy with service with
In another shell start the fullnode with service with:

```shell
just run-proxy
just run-fullnode
```

This is set up to work correctly with the default cartesi configuration of addresses and ports

#### Terminal 3 - Wallet
#### Terminal 2 - Wallet

Install and start a Zingo CLI wallet based off the Cartezcash fork with:

Expand All @@ -221,7 +226,12 @@ just start-wallet-2

#### Deposit into L2

First lets deposit some 1 Eth from the L1 anvil testnet into the L2. To do this get the hex encoded transparent address of the wallet by running `addresses` in zingo-wallet
First lets deposit some 1 Eth from the L1 anvil testnet into the L2. To do this get the hex encoded transparent address of the wallet by running

```shell
>> addresses
```
in zingo-wallet which should respond with something like:

```
(mainnet) Block:0 (type 'help') >> addresses
Expand Down Expand Up @@ -258,7 +268,7 @@ You should see the transparent balance update!
#### Shield funds

Now to shield these funds so they are private. From the Wallet CLI run
Now to shield these funds so they are private. From the Zingo Wallet CLI run

```shell
>> shield all
Expand Down
1 change: 1 addition & 0 deletions fly.fullnode.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ ETH_CHAIN_ID="11155111"
INPUTBOX_CONTRACT_ADDRESS="0x59b22D57D4f067708AB0c00552767405926dc768"
ETH_RPC_URL="https://eth-sepolia.g.alchemy.com/v2/demo"
DAPP_ADDRESS = "0x589DAc2C23C2bc1b60112eD66049ECba90e7AD3e"
ETH_DEPOSIT_ADDR="0xFfdbe43d4c855BF7e0f105c400A50857f53AB044"
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ start-wallet:
restart-wallet:
zingo-cli --data-dir ./walletdata --server localhost:50051

start-wallet-testnet:
zingo-cli --server https://cartezcash-fullnode.fly.dev:443 --birthday 0

start-wallet-2:
zingo-cli --data-dir ./walletdata2 --server localhost:50051 --from "february day pink knee nut struggle poem silver hawk voice stay rule food cabbage eight phrase parent spider forget laundry wagon dwarf improve flee" --birthday 0
restart-wallet-2:
Expand Down
10 changes: 8 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use tower_cartesi::{Request as RollAppRequest, Response};

use futures_util::future::FutureExt;

const DAPP_RELAY_CONTRACT_ADDRESS: &str = "f5de34d6bbc0446e2a45719e718efebaae179dae";

#[cfg(feature = "lightwalletd")]
use cartezcash_lightwalletd::{
proto::service::compact_tx_streamer_server::CompactTxStreamerServer,
Expand Down Expand Up @@ -146,8 +148,12 @@ impl Service<RollAppRequest> for CarteZcashApp {
fn call(&mut self, req: RollAppRequest) -> Self::Future {
match req {
RollAppRequest::AdvanceState { metadata, payload } => {
// if the payload is 20 bytes, it is the dapp address. Handle it then exit early
if payload.len() == 20 {
// if sent by this address the message is relaying the dApp address. Handle accordingly
if metadata.msg_sender
== ethereum_types::Address::from_slice(
&hex::decode(DAPP_RELAY_CONTRACT_ADDRESS).unwrap(),
)
{
let dapp_address = ethereum_types::Address::from_slice(&payload);
tracing::info!("Received dapp address: {:?}", dapp_address);
self.dapp_address = Some(dapp_address);
Expand Down
Binary file added wallets/zingo-wallet.dat
Binary file not shown.

0 comments on commit e653daf

Please sign in to comment.