pub fn create_numeric_event(
secp: &Secp256k1<All>,
key_pair: &Keypair,
event_id: &str,
base: u16,
num_digits: u16,
is_signed: bool,
precision: i32,
unit: &str,
event_maturity_epoch: u32,
nonces: &[XOnlyPublicKey],
) -> Result<OracleAnnouncement, Error>Expand description
Creates a numeric event announcement for oracle events with numeric outcomes.
This function creates an OracleAnnouncement for events where the outcome is a numeric
value that can be decomposed into digits. The value is represented in a specified base
(currently only base 2 is supported) and can be signed or unsigned.
§Arguments
secp- Secp256k1 context for cryptographic operationskey_pair- Oracle’s key pair for signing the announcementevent_id- Unique identifier for this eventbase- Numeric base for digit decomposition (must be 2)num_digits- Number of digits in the numeric representationis_signed- Whether the numeric value can be negativeprecision- Decimal precision for the numeric valueunit- Unit of measurement for the numeric valueevent_maturity_epoch- Unix timestamp when the event maturesnonces- Vector of public keys for nonces (length must match required nonces)
§Returns
Ok(OracleAnnouncement)- The signed announcement if successfulErr(Error::InvalidEventId)- If the event_id is emptyErr(Error::InvalidBase)- If base is not 2Err(Error::InvalidNumberOfDigits)- If num_digits is 0 or more than 63Err(Error::InvalidNonces)- If the number of nonces doesn’t match the required countErr(Error::Internal)- If cryptographic operations fail
§Example
use kormir::*;
use bitcoin::secp256k1::{rand, Secp256k1, SecretKey};
use secp256k1_zkp::Keypair;
let secp = Secp256k1::new();
let key_pair = Keypair::new(&secp, &mut rand::thread_rng());
let nonce_keys: Vec<SecretKey> = (0..6)
.map(|_| SecretKey::from_keypair(&Keypair::new(&secp, &mut rand::thread_rng())))
.collect();
let nonces = nonce_keys.iter().map(|k| k.x_only_public_key(&secp).0).collect::<Vec<bitcoin::XOnlyPublicKey>>();
let announcement = create_numeric_event(
&secp,
&key_pair,
&"temperature".to_string(),
2, // base 2
5, // 5 digits
true, // signed
1, // 1 decimal place
&"°C".to_string(),
1640995200, // 2022-01-01 00:00:00 UTC
&nonces,
).unwrap();