Skip to main content

loan_id

Function loan_id 

Source
pub fn loan_id(
    loan_broker_id: &LedgerEntryIdBytes,
    seq: u32,
) -> Result<LedgerEntryIdBytes>
Expand description

Generates a loan ledger entry ID for a given loan broker id and sequence in the XRP Ledger.

Loan ledger entry IDs are used to reference loan entries in the XRP Ledger’s state data. This function uses the generic create_id_from_host_call helper to manage the FFI interaction.

§Arguments

  • loan_broker_id - The 32-byte ledger entry ID of the loan’s LoanBroker
  • seq - The sequence number associated with the loan entry

§Returns

  • Result<LedgerEntryIdBytes> - On success, returns a 32-byte loan ledger entry ID. On failure, returns an Error with the corresponding error code.

§Safety

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

§Example

use xrpl_common_stdlib::types::account_id::AccountID;
use xrpl_common_stdlib::ledger_entry_ids::{loan_broker_id, loan_id};
use xrpl_common_stdlib::host::trace::{ trace_hex, trace_num };

fn main() -> Result<(), Box<dyn std::error::Error>> {
  let account: AccountID =
      AccountID::from(*b"\xd5\xb9\x84VP\x9f \xb5'\x9d\x1eJ.\xe8\xb2\xaa\x82\xaec\xe3");
  match loan_broker_id(&account, 12345) {
    xrpl_common_stdlib::host::Result::Ok(broker_id) => {
      match loan_id(&broker_id, 1) {
        xrpl_common_stdlib::host::Result::Ok(id) => {
          trace_hex("Generated ledger entry ID", &id);
        }
        xrpl_common_stdlib::host::Result::Err(e) => {
          trace_num("Error assembling ledger entry ID", e.code() as i64);
        }
      }
    }
    xrpl_common_stdlib::host::Result::Err(e) => {
      trace_num("Error assembling loan broker ledger entry ID", e.code() as i64);
    }
  }
  Ok(())
}