We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show how EVM queries to Sapphire can be used in ROFL.
Taken from the ROFL example, sth like this may work to fetch the last submitted observation:
let res = env.client().query( 0, "evm.SimulateCall", module_evm::types::SimulateCallQuery { gas_price: 10_000.into(), gas_limit: 100_000, caller: module_evm::derive_caller::from_sigspec(&SignatureAddressSpec::Secp256k1Eth(sdk_pub_key)).unwrap(), address: Some(ORACLE_CONTRACT_ADDRESS.parse().unwrap()), value: 0.into(), data: [ ethabi::short_signature("getLastObservation", &[]).to_vec(), ethabi::encode(&[]), ].concat(), }, ).await?; println!("{:?}", res);
Based on this code https://github.com/oasisprotocol/oasis-sdk/blob/main/runtime-sdk/modules/evm/src/mock.rs#L168-L179
Related oasisprotocol/oasis-web3-gateway#625
The text was updated successfully, but these errors were encountered:
This is the working code snippet to read the getLastObservation view function from the ROFL oracle example.
getLastObservation
async fn get_last_observation(self: Arc<Self>, env: Environment<Self>) -> Result<(u128, u64)> { let data: Vec<u8> = [ ethabi::short_signature("getLastObservation", &[]).to_vec(), ethabi::encode(&[]), ] .concat(); let sdk_pub_key = secp256k1::PublicKey::from_bytes(env.signer().public_key().as_bytes()).unwrap(); let caller = module_evm::derive_caller::from_sigspec(&SignatureAddressSpec::Secp256k1Eth( sdk_pub_key, )) .unwrap(); let res: Vec<u8> = env .client() .query( env.client().latest_round().await?.into(), "evm.SimulateCall", module_evm::types::SimulateCallQuery { gas_price: 10_000.into(), gas_limit: 100_000, caller, address: Some(ORACLE_CONTRACT_ADDRESS.parse().unwrap()), value: 0.into(), data, }, ) .await?; let decoded = ethabi::decode( &[ ethabi::ParamType::Uint(128), // _value ethabi::ParamType::Uint(256), // _block ], &res, ) .map_err(|e| anyhow::anyhow!("Failed to decode response: {}", e))?; let value = decoded[0].clone().into_uint().unwrap().as_u128(); let block = decoded[1].clone().into_uint().unwrap().as_u64(); Ok((value, block)) }
match self.get_last_observation(env).await { Ok((value, block)) => { let price = value as f64 / 1_000_000.0; println!( "Last observation: ${:.6} ROSE/USDT at block {}", price, block ); } Err(err) => println!("Failed to get last observation: {:?}", err), }
Sorry, something went wrong.
kostko
No branches or pull requests
Show how EVM queries to Sapphire can be used in ROFL.
Taken from the ROFL example, sth like this may work to fetch the last submitted observation:
Based on this code https://github.com/oasisprotocol/oasis-sdk/blob/main/runtime-sdk/modules/evm/src/mock.rs#L168-L179
Related oasisprotocol/oasis-web3-gateway#625
The text was updated successfully, but these errors were encountered: