-
-
Save tansawit/f442a93531304a7410634ca5bbd4b3d4 to your computer and use it in GitHub Desktop.
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
use obi::{OBIDecode, OBIEncode, OBISchema}; | |
use owasm::{execute_entry_point, ext, oei, prepare_entry_point}; | |
// Input Parameters | |
#[derive(OBIDecode, OBISchema)] | |
struct Input { | |
symbol: String, | |
multiplier: u64, | |
} | |
// Output Parameters | |
#[derive(OBIEncode, OBISchema)] | |
struct Output { | |
volume: u64, | |
} | |
// Preparation Phase | |
#[no_mangle] | |
fn prepare_impl(input: Input) { | |
// Coingecko volume data source | |
oei::ask_external_data(1, 9, &input.symbol.as_bytes()); | |
} | |
// Execution Phase | |
#[no_mangle] | |
fn execute_impl(input: Input) -> Output { | |
let avg: f64 = ext::load_average(1); | |
Output { volume: (avg * input.multiplier as f64) as u64 } | |
} | |
prepare_entry_point!(prepare_impl); | |
execute_entry_point!(execute_impl); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment