Skip to main content

oracle_keylet

Function oracle_keylet 

Source
pub fn oracle_keylet(owner: &AccountID, document_id: u32) -> Result<KeyletBytes>
Expand description

Generates an oracle keylet for a given owner and document ID in the XRP Ledger.

Oracle keylets are used to reference oracle entries in the XRP Ledger’s state data. This function uses the generic create_keylet_from_host_call helper to manage the FFI interaction.

§Arguments

  • owner - Reference to an AccountID representing the oracle owner’s account
  • document_id - An integer identifier for the oracle document

§Returns

  • Result<KeyletBytes> - On success, returns a 32-byte oracle keylet. On failure, returns an Error with the corresponding error code.

§Safety

This function makes unsafe FFI calls to the host environment through the host::oracle_keylet function, though the unsafe code is contained within the closure passed to create_keylet_from_host_call.

§Example

use xrpl_wasm_stdlib::core::types::account_id::AccountID;
use xrpl_wasm_stdlib::core::keylets::oracle_keylet;
use xrpl_wasm_stdlib::host::trace::{DataRepr, trace_data, trace_num};

fn main() -> Result<(), Box<dyn std::error::Error>> {
  let owner: AccountID =
      AccountID::from(*b"\xd5\xb9\x84VP\x9f \xb5'\x9d\x1eJ.\xe8\xb2\xaa\x82\xaec\xe3");
  let document_id = 12345;
  match oracle_keylet(&owner, document_id) {
    xrpl_wasm_stdlib::host::Result::Ok(keylet) => {
      let _ = trace_data("Generated keylet", &keylet, DataRepr::AsHex);
    }
    xrpl_wasm_stdlib::host::Result::Err(e) => {
      let _ = trace_num("Error assembling keylet", e.code() as i64);
    }
  }
  Ok(())
}