Skip to content

Commit 8db94d6

Browse files
dakomreecepbcups
authored andcommitted
fix exec
1 parent 32f7a0d commit 8db94d6

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ wasi-build:
2929
@mkdir -p ./compiled
3030
@cp ./target/wasm32-wasip1/release/*.wasm ./compiled/
3131

32+
wasi-exec:
33+
@$(WAVS_CMD) exec --log-level=info --data /data/.docker --home /data \
34+
--component "/data/compiled/${COMPONENT_FILENAME}" \
35+
--input `cast format-bytes32-string 1`
36+
3237
## update-submodules: update the git submodules
3338
update-submodules:
3439
@git submodule update --init --recursive

README.md

Lines changed: 6 additions & 4 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

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod trigger;
2+
use bindings::wavs::worker::layer_types::{TriggerData, TriggerSource};
23
use trigger::{decode_trigger_event, encode_trigger_output};
34
pub mod bindings;
45
use crate::bindings::{export, Guest, TriggerAction};
@@ -14,8 +15,21 @@ export!(Component with_types_in bindings);
1415

1516
impl Guest for Component {
1617
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())?;
18+
enum Destination {
19+
Ethereum,
20+
CliOutput
21+
}
22+
let ((trigger_id, req), dest) = match &trigger_action.data {
23+
// When the trigger comes from WAVS, it's from an ethereum contract event
24+
TriggerData::EthContractEvent(_) => {
25+
(decode_trigger_event(trigger_action.data).map_err(|e| e.to_string())?, Destination::Ethereum)
26+
},
27+
// When we test in a CLI exec command, it's just raw bytes (we can make-up the trigger_id)
28+
TriggerData::Raw(data) => ((0, data.clone()), Destination::CliOutput),
29+
TriggerData::CosmosContractEvent(_) => {
30+
return Err("Unsupported trigger data type".to_string());
31+
},
32+
};
1933

2034
// Convert bytes to string and parse first char as u64
2135
let input = std::str::from_utf8(&req).map_err(|e| e.to_string())?;
@@ -38,7 +52,12 @@ impl Guest for Component {
3852
});
3953

4054
match res {
41-
Ok(data) => Ok(encode_trigger_output(trigger_id, &data)),
55+
Ok(data) => match dest {
56+
Destination::Ethereum => {
57+
Ok(encode_trigger_output(trigger_id, &data))
58+
},
59+
Destination::CliOutput => Ok(data),
60+
},
4261
Err(e) => Err(e),
4362
}
4463
}

0 commit comments

Comments
 (0)