Skip to content

Commit 31d9360

Browse files
committed
bump, working woo!
1 parent d6ba0cd commit 31d9360

File tree

8 files changed

+114
-2045
lines changed

8 files changed

+114
-2045
lines changed

Cargo-component.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ version = 1
66
name = "wavs:worker"
77

88
[[package.version]]
9-
requirement = "^0.3.0-alpha1"
10-
version = "0.3.0-alpha1"
11-
digest = "sha256:980fca53013305edfa10643b98c8afbb11a8f8207f0c59aebec612a4b9254dd3"
9+
requirement = "^0.3.0-alpha2"
10+
version = "0.3.0-alpha2"
11+
digest = "sha256:b551fdb5109fc5fd9cc2e08f42331a84172b9813235b88c47ed770ce32b05d09"

components/eth-trigger-weather/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ lto = true
3333

3434
[package.metadata.component]
3535
package = "component:eth-trigger-weather"
36-
target = "wavs:worker/layer-trigger-world@0.3.0-alpha1"
36+
target = "wavs:worker/layer-trigger-world@0.3.0-alpha2"

components/eth-trigger-weather/src/bindings.rs

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,28 @@ pub mod wavs {
529529
.finish()
530530
}
531531
}
532+
#[derive(Clone, Copy)]
533+
pub enum LogLevel {
534+
Error,
535+
Warn,
536+
Info,
537+
Debug,
538+
Trace,
539+
}
540+
impl ::core::fmt::Debug for LogLevel {
541+
fn fmt(
542+
&self,
543+
f: &mut ::core::fmt::Formatter<'_>,
544+
) -> ::core::fmt::Result {
545+
match self {
546+
LogLevel::Error => f.debug_tuple("LogLevel::Error").finish(),
547+
LogLevel::Warn => f.debug_tuple("LogLevel::Warn").finish(),
548+
LogLevel::Info => f.debug_tuple("LogLevel::Info").finish(),
549+
LogLevel::Debug => f.debug_tuple("LogLevel::Debug").finish(),
550+
LogLevel::Trace => f.debug_tuple("LogLevel::Trace").finish(),
551+
}
552+
}
553+
}
532554
}
533555
}
534556
}
@@ -540,6 +562,7 @@ pub mod host {
540562
use super::_rt;
541563
pub type EthChainConfig = super::wavs::worker::layer_types::EthChainConfig;
542564
pub type CosmosChainConfig = super::wavs::worker::layer_types::CosmosChainConfig;
565+
pub type LogLevel = super::wavs::worker::layer_types::LogLevel;
543566
#[allow(unused_unsafe, clippy::all)]
544567
pub fn get_eth_chain_config(chain_name: &str) -> Option<EthChainConfig> {
545568
unsafe {
@@ -727,6 +750,33 @@ pub mod host {
727750
}
728751
}
729752
}
753+
#[allow(unused_unsafe, clippy::all)]
754+
pub fn log(level: LogLevel, message: &str) {
755+
unsafe {
756+
use super::wavs::worker::layer_types::LogLevel as V0;
757+
let result1 = match level {
758+
V0::Error => 0i32,
759+
V0::Warn => 1i32,
760+
V0::Info => 2i32,
761+
V0::Debug => 3i32,
762+
V0::Trace => 4i32,
763+
};
764+
let vec2 = message;
765+
let ptr2 = vec2.as_ptr().cast::<u8>();
766+
let len2 = vec2.len();
767+
#[cfg(target_arch = "wasm32")]
768+
#[link(wasm_import_module = "host")]
769+
extern "C" {
770+
#[link_name = "log"]
771+
fn wit_import(_: i32, _: *mut u8, _: usize);
772+
}
773+
#[cfg(not(target_arch = "wasm32"))]
774+
fn wit_import(_: i32, _: *mut u8, _: usize) {
775+
unreachable!()
776+
}
777+
wit_import(result1, ptr2.cast_mut(), len2);
778+
}
779+
}
730780
}
731781
mod _rt {
732782
pub use alloc_crate::string::String;
@@ -789,11 +839,11 @@ macro_rules! __export_layer_trigger_world_impl {
789839
#[doc(inline)]
790840
pub(crate) use __export_layer_trigger_world_impl as export;
791841
#[cfg(target_arch = "wasm32")]
792-
#[link_section = "component-type:wit-bindgen:0.35.0:wavs:worker@0.3.0-alpha1:layer-trigger-world:encoded world"]
842+
#[link_section = "component-type:wit-bindgen:0.35.0:wavs:worker@0.3.0-alpha2:layer-trigger-world:encoded world"]
793843
#[doc(hidden)]
794-
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1472] = *b"\
795-
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xb6\x0a\x01A\x02\x01\
796-
A\x0c\x01B!\x01r\x02\x0bbech32-addrs\x0aprefix-leny\x04\0\x0ecosmos-address\x03\0\
844+
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 1591] = *b"\
845+
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xad\x0b\x01A\x02\x01\
846+
A\x0d\x01B#\x01r\x02\x0bbech32-addrs\x0aprefix-leny\x04\0\x0ecosmos-address\x03\0\
797847
\0\x01o\x02ss\x01p\x02\x01r\x02\x02tys\x0aattributes\x03\x04\0\x0ccosmos-event\x03\
798848
\0\x04\x01ks\x01r\x07\x08chain-ids\x0crpc-endpoint\x06\x0dgrpc-endpoint\x06\x11g\
799849
rpc-web-endpoint\x06\x09gas-pricev\x09gas-denoms\x0dbech32-prefixs\x04\0\x13cosm\
@@ -811,16 +861,19 @@ ontract-event\x03\0\x19\x01r\x04\x10contract-address\x01\x0achain-names\x05event
811861
\x05\x0cblock-heightw\x04\0\"trigger-data-cosmos-contract-event\x03\0\x1b\x01q\x03\
812862
\x12eth-contract-event\x01\x1a\0\x15cosmos-contract-event\x01\x1c\0\x03raw\x01\x09\
813863
\0\x04\0\x0ctrigger-data\x03\0\x1d\x01r\x02\x06config\x18\x04data\x1e\x04\0\x0et\
814-
rigger-action\x03\0\x1f\x03\0$wavs:worker/layer-types@0.3.0-alpha1\x05\0\x02\x03\
815-
\0\0\x0etrigger-action\x03\0\x0etrigger-action\x03\0\x01\x02\x03\0\0\x10eth-chai\
816-
n-config\x02\x03\0\0\x13cosmos-chain-config\x01B\x0a\x02\x03\x02\x01\x03\x04\0\x10\
817-
eth-chain-config\x03\0\0\x02\x03\x02\x01\x04\x04\0\x13cosmos-chain-config\x03\0\x02\
818-
\x01k\x01\x01@\x01\x0achain-names\0\x04\x04\0\x14get-eth-chain-config\x01\x05\x01\
819-
k\x03\x01@\x01\x0achain-names\0\x06\x04\0\x17get-cosmos-chain-config\x01\x07\x03\
820-
\0\x04host\x05\x05\x01p}\x01j\x01\x06\x01s\x01@\x01\x0etrigger-action\x02\0\x07\x04\
821-
\0\x03run\x01\x08\x04\0,wavs:worker/layer-trigger-world@0.3.0-alpha1\x04\0\x0b\x19\
822-
\x01\0\x13layer-trigger-world\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0d\
823-
wit-component\x070.220.0\x10wit-bindgen-rust\x060.35.0";
864+
rigger-action\x03\0\x1f\x01q\x05\x05error\0\0\x04warn\0\0\x04info\0\0\x05debug\0\
865+
\0\x05trace\0\0\x04\0\x09log-level\x03\0!\x03\0$wavs:worker/layer-types@0.3.0-al\
866+
pha2\x05\0\x02\x03\0\0\x0etrigger-action\x03\0\x0etrigger-action\x03\0\x01\x02\x03\
867+
\0\0\x10eth-chain-config\x02\x03\0\0\x13cosmos-chain-config\x02\x03\0\0\x09log-l\
868+
evel\x01B\x0e\x02\x03\x02\x01\x03\x04\0\x10eth-chain-config\x03\0\0\x02\x03\x02\x01\
869+
\x04\x04\0\x13cosmos-chain-config\x03\0\x02\x02\x03\x02\x01\x05\x04\0\x09log-lev\
870+
el\x03\0\x04\x01k\x01\x01@\x01\x0achain-names\0\x06\x04\0\x14get-eth-chain-confi\
871+
g\x01\x07\x01k\x03\x01@\x01\x0achain-names\0\x08\x04\0\x17get-cosmos-chain-confi\
872+
g\x01\x09\x01@\x02\x05level\x05\x07messages\x01\0\x04\0\x03log\x01\x0a\x03\0\x04\
873+
host\x05\x06\x01p}\x01j\x01\x07\x01s\x01@\x01\x0etrigger-action\x02\0\x08\x04\0\x03\
874+
run\x01\x09\x04\0,wavs:worker/layer-trigger-world@0.3.0-alpha2\x04\0\x0b\x19\x01\
875+
\0\x13layer-trigger-world\x03\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit\
876+
-component\x070.220.0\x10wit-bindgen-rust\x060.35.0";
824877
#[inline(never)]
825878
#[doc(hidden)]
826879
pub fn __link_custom_section_describing_imports() {

components/eth-trigger-weather/src/lib.rs

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,45 @@ struct Component;
1313

1414
impl Guest for Component {
1515
fn run(trigger_action: TriggerAction) -> std::result::Result<Vec<u8>, String> {
16-
// let (trigger_id, req) =
17-
// decode_trigger_event(trigger_action.data).map_err(|e| e.to_string())?;
18-
19-
// if !req.contains(&b',') {
20-
// return Err("Input must be in the format of City,State".to_string());
21-
// }
22-
// let input = std::str::from_utf8(&req).unwrap();
23-
24-
// // open weather API, not wavs specific
25-
// let api_key = std::env::var("WAVS_ENV_OPEN_WEATHER_API_KEY")
26-
// .or(Err("missing env var `WAVS_ENV_OPEN_WEATHER_API_KEY`".to_string()))?;
27-
28-
let test = "just a test";
29-
let test_to_bytes = test.as_bytes();
30-
31-
Ok(encode_trigger_output(1, test_to_bytes))
32-
33-
// let res = block_on(async move {
34-
// let loc: Result<LocDataNested, String> = get_location(api_key.clone(), input).await;
35-
36-
// let location = match loc {
37-
// Ok(data) => data,
38-
// Err(e) => return Err(e),
39-
// };
40-
41-
// let weather_data = get_weather(location, api_key).await;
42-
43-
// match weather_data {
44-
// Ok(data) => {
45-
// let output: Vec<u8> = data.into();
46-
// Ok(output)
47-
// }
48-
// Err(e) => Err(e),
49-
// }
50-
// });
51-
52-
// match res {
53-
// Ok(data) => Ok(encode_trigger_output(trigger_id, &data)),
54-
// Err(e) => Err(e),
55-
// }
16+
let (trigger_id, req) =
17+
decode_trigger_event(trigger_action.data).map_err(|e| e.to_string())?;
18+
19+
if !req.contains(&b',') {
20+
return Err("Input must be in the format of City,State".to_string());
21+
}
22+
let input = std::str::from_utf8(&req).unwrap();
23+
24+
println!("input: {}", input);
25+
26+
// open weather API, not wavs specific
27+
let api_key = std::env::var("WAVS_ENV_OPEN_WEATHER_API_KEY")
28+
.or(Err("missing env var `WAVS_ENV_OPEN_WEATHER_API_KEY`".to_string()))?;
29+
30+
let res = block_on(async move {
31+
let loc: Result<LocDataNested, String> = get_location(api_key.clone(), input).await;
32+
println!("loc: {:?}", loc);
33+
34+
let location = match loc {
35+
Ok(data) => data,
36+
Err(e) => return Err(e),
37+
};
38+
39+
let weather_data = get_weather(location, api_key).await;
40+
println!("weather_data: {:?}", weather_data);
41+
42+
match weather_data {
43+
Ok(data) => {
44+
let output: Vec<u8> = data.into();
45+
Ok(output)
46+
}
47+
Err(e) => Err(e),
48+
}
49+
});
50+
51+
match res {
52+
Ok(data) => Ok(encode_trigger_output(trigger_id, &data)),
53+
Err(e) => Err(e),
54+
}
5655
}
5756
}
5857

0 commit comments

Comments
 (0)