Skip to content

Commit 1e9631f

Browse files
dakomreecepbcups
andauthored
Fix exec (#44)
* more updates / cleanup * fix exec * wasi-exec override CMC ID * simplify trigger matches --------- Co-authored-by: David Komer <6406986+dakom@users.noreply.github.com> Co-authored-by: Reece Williams <reecepbcups@gmail.com>
1 parent 2a963c8 commit 1e9631f

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ RPC_URL?=http://localhost:8545
1616
SERVICE_MANAGER_ADDR?=`jq -r '.eigen_service_managers.local | .[-1]' .docker/deployments.json`
1717
SERVICE_TRIGGER_ADDR?=`jq -r '.trigger' "./.docker/script_deploy.json"`
1818
SERVICE_SUBMISSION_ADDR?=`jq -r '.service_handler' "./.docker/script_deploy.json"`
19+
COIN_MARKET_CAP_ID?=1
1920

2021
## build: building the project
2122
build: _build_forge wasi-build
@@ -29,6 +30,12 @@ wasi-build:
2930
@mkdir -p ./compiled
3031
@cp ./target/wasm32-wasip1/release/*.wasm ./compiled/
3132

33+
## wasi-exec: executing the WAVS wasi component(s) | COMPONENT_FILENAME, COIN_MARKET_CAP_ID
34+
wasi-exec:
35+
@$(WAVS_CMD) exec --log-level=info --data /data/.docker --home /data \
36+
--component "/data/compiled/${COMPONENT_FILENAME}" \
37+
--input `cast format-bytes32-string $(COIN_MARKET_CAP_ID)`
38+
3239
## update-submodules: update the git submodules
3340
update-submodules:
3441
@git submodule update --init --recursive
@@ -95,7 +102,6 @@ deploy-service:
95102
--service-config ${SERVICE_CONFIG}
96103

97104
## trigger-service: triggering the service | SERVICE_TRIGGER_ADDR, COIN_MARKET_CAP_ID, RPC_URL
98-
COIN_MARKET_CAP_ID?=1
99105
trigger-service:
100106
@forge script ./script/Trigger.s.sol ${SERVICE_TRIGGER_ADDR} ${COIN_MARKET_CAP_ID} --sig "run(string,string)" --rpc-url $(RPC_URL) --broadcast -v 4
101107

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@ forge test
4040
4141
```bash
4242
make wasi-build
43-
44-
# TODO: currently broken upstream
45-
# Verify execution works as expected without deploying
46-
# wavs-cli exec --component $(pwd)/compiled/eth_price_oracle.wasm --input `cast format-bytes32-string 1`
4743
```
4844

4945
> You can also use `make build` to build the contracts and components in one command
5046
47+
### Execute WASI component directly
48+
49+
```bash
50+
make wasi-exec
51+
```
52+
5153
## WAVS
5254

5355
### Start Anvil, WAVS, and Deploy Eigenlayer
@@ -84,7 +86,7 @@ make deploy-service
8486
## Trigger the Service
8587

8688
```bash
87-
# Trigger contract via `script/Trigger.s.sol`
89+
# Trigger contract via `script/Trigger.s.sol` for BTC
8890
COIN_MARKET_CAP_ID=1 make trigger-service
8991
```
9092

components/eth-price-oracle/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mod trigger;
2-
use trigger::{decode_trigger_event, encode_trigger_output};
2+
use trigger::{decode_trigger_event, encode_trigger_output, Destination};
33
pub mod bindings;
44
use crate::bindings::{export, Guest, TriggerAction};
55
use serde::{Deserialize, Serialize};
@@ -13,9 +13,9 @@ struct Component;
1313
export!(Component with_types_in bindings);
1414

1515
impl Guest for Component {
16-
fn run(trigger_action: TriggerAction) -> std::result::Result<Vec<u8>, String> {
17-
let (trigger_id, req) =
18-
decode_trigger_event(trigger_action.data).map_err(|e| e.to_string())?;
16+
fn run(action: TriggerAction) -> std::result::Result<Vec<u8>, String> {
17+
let (trigger_id, req, dest) =
18+
decode_trigger_event(action.data).map_err(|e| e.to_string())?;
1919

2020
// Convert bytes to string and parse first char as u64
2121
let input = std::str::from_utf8(&req).map_err(|e| e.to_string())?;
@@ -38,7 +38,10 @@ impl Guest for Component {
3838
});
3939

4040
match res {
41-
Ok(data) => Ok(encode_trigger_output(trigger_id, &data)),
41+
Ok(data) => match dest {
42+
Destination::Ethereum => Ok(encode_trigger_output(trigger_id, &data)),
43+
Destination::CliOutput => Ok(data),
44+
},
4245
Err(e) => Err(e),
4346
}
4447
}

components/eth-price-oracle/src/trigger.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
// Helpers to work with "trigger id" flows - which our example components do
21
use crate::bindings::wavs::worker::layer_types::{TriggerData, TriggerDataEthContractEvent};
32
use alloy_sol_types::SolValue;
43
use anyhow::Result;
4+
use wavs_wasi_chain::decode_event_log_data;
55

6-
pub fn decode_trigger_event(trigger_data: TriggerData) -> Result<(u64, Vec<u8>)> {
6+
pub enum Destination {
7+
Ethereum,
8+
CliOutput,
9+
}
10+
11+
pub fn decode_trigger_event(trigger_data: TriggerData) -> Result<(u64, Vec<u8>, Destination)> {
712
match trigger_data {
813
TriggerData::EthContractEvent(TriggerDataEthContractEvent { log, .. }) => {
9-
let event: solidity::NewTrigger = wavs_wasi_chain::decode_event_log_data!(log)?;
14+
let event: solidity::NewTrigger = decode_event_log_data!(log)?;
1015
let trigger_info = solidity::TriggerInfo::abi_decode(&event._0, false)?;
11-
Ok((trigger_info.triggerId, trigger_info.data.to_vec()))
12-
}
13-
TriggerData::Raw(data) => {
14-
let trigger_info = solidity::TriggerInfo::abi_decode(&data, false)?;
15-
Ok((trigger_info.triggerId, data.to_vec()))
16+
Ok((trigger_info.triggerId, trigger_info.data.to_vec(), Destination::Ethereum))
1617
}
18+
TriggerData::Raw(data) => Ok((0, data.clone(), Destination::CliOutput)),
1719
_ => Err(anyhow::anyhow!("Unsupported trigger data type")),
1820
}
1921
}

0 commit comments

Comments
 (0)