Created
October 10, 2023 16:32
-
-
Save gallynaut/32fd418504cf455e205609a18b719773 to your computer and use it in GitHub Desktop.
Solana Weather Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub use switchboard_solana::get_ixn_discriminator; | |
pub use switchboard_solana::prelude::*; | |
pub use switchboard_utils::protos::http::http_task; | |
pub use switchboard_utils::reqwest; | |
#[tokio::main(worker_threads = 12)] | |
async fn main() { | |
println!("Hello, world!"); | |
let runner = FunctionRunner::from_env(None).unwrap(); | |
let result = http_task( | |
"https://api.weather.gov/gridpoints/MFL/111,50/forecast", | |
Some("$.properties.periods.0.temperature"), | |
) | |
.await | |
.unwrap(); | |
// Here, serialize the result into your ixn params. You may need to add the ixn discriminator | |
// to the front of the serialized bytes. | |
let mut ixn_data = get_ixn_discriminator("your_ixn_name").to_vec(); | |
ixn_data.extend(result.as_f64().unwrap().try_to_vec().unwrap()); | |
let ixn: Instruction = Instruction { | |
program_id: Pubkey::default(), | |
accounts: vec![AccountMeta::new(Pubkey::default(), false)], | |
data: ixn_data, | |
}; | |
runner.emit(vec![ixn]).await.unwrap(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment