xrpl_common_stdlib/host/host_bindings_trait.rs
1/// Trait defining all host functions available to WASM smart contracts.
2///
3/// This trait serves as the source of truth for host function signatures and is implemented by:
4/// - `WasmHostBindings`: The production implementation that calls actual host functions via FFI
5/// - `EmptyHostBindings`: Stub implementations for non-WASM builds (panics if called)
6/// - `MockHostBindings`: Generated by `mockall` for unit testing (via `#[automock]`)
7///
8/// # Example
9///
10/// ```rust,ignore
11/// use xrpl_common_stdlib::host::{HostBindings, WasmHostBindings};
12///
13/// fn my_function<H: HostBindings>(host: &H) {
14/// unsafe {
15/// let mut buffer = [0u8; 8];
16/// let result = host.ldgr_index(buffer.as_mut_ptr(), buffer.len());
17/// // ... use result
18/// }
19/// }
20///
21/// // In production code:
22/// let host = WasmHostBindings;
23/// my_function(&host);
24/// ```
25#[allow(unused)] // To remove warn when compiled for non-WASM targets
26#[cfg_attr(
27 all(any(test, feature = "test-host-bindings"), not(target_arch = "wasm32")),
28 mockall::automock
29)]
30pub trait HostBindings {
31 // ###############################
32 // Host Function Category: getters
33 // ###############################
34
35 /// Retrieves the current ledger sequence number.
36 ///
37 /// This function populates a provided buffer with the ledger sequence number.
38 ///
39 /// # Parameters
40 ///
41 /// - `out_buff_ptr`: A mutable pointer to a buffer where the ledger sequence number will be written.
42 /// - `out_buff_len`: The maximum length of the buffer in bytes.
43 ///
44 /// # Returns
45 ///
46 /// - Returns a positive number of bytes written to the output buffer on success
47 /// - Returns a negative error code on failure. The list of error codes is defined in
48 /// `../core/error_codes.rs`
49 ///
50 /// # Safety
51 /// Caller must ensure all pointer parameters point to valid memory
52 unsafe fn ldgr_index(&self, out_buff_ptr: *mut u8, out_buff_len: usize) -> i32;
53
54 /// Retrieves the parent ledger time.
55 ///
56 /// This function is used to obtain the parent ledger's timestamp as a byte array.
57 /// The timestamp is written into a provided output buffer.
58 ///
59 /// # Parameters
60 ///
61 /// - `out_buff_ptr`: A mutable pointer to a buffer where the parent ledger time will be written.
62 /// - `out_buff_len`: The maximum length of the buffer in bytes.
63 ///
64 /// # Returns
65 ///
66 /// - Returns a positive number of bytes written to the output buffer on success
67 /// - Returns a negative error code on failure. The list of error codes is defined in
68 /// `../core/error_codes.rs`
69 ///
70 /// # Safety
71 /// Caller must ensure all pointer parameters point to valid memory
72 unsafe fn parent_ldgr_time(&self, out_buff_ptr: *mut u8, out_buff_len: usize) -> i32;
73
74 /// Retrieves the hash of the parent ledger.
75 ///
76 /// This function fetches the hash of the parent ledger and stores it in the buffer provided.
77 /// The hash is expected to be written to the memory location pointed by `out_buff_ptr`,
78 /// and its length should not exceed the `out_buff_len`.
79 ///
80 /// # Parameters
81 /// - `out_buff_ptr`: A mutable pointer to a buffer where the parent ledger hash will be written.
82 /// The buffer must be allocated and managed by the caller.
83 /// - `out_buff_len`: The maximum length of the buffer in bytes. This indicates the size of the
84 /// buffer and ensures that the function does not write beyond the allowed length.
85 ///
86 /// # Returns
87 ///
88 /// - Returns a positive number of bytes wrote to an output buffer on success
89 /// - Returns a negative error code on failure. The list of error codes is defined in
90 /// `../core/error_codes.rs`
91 ///
92 /// # Safety
93 /// Caller must ensure all pointer parameters point to valid memory
94 unsafe fn parent_ldgr_hash(&self, out_buff_ptr: *mut u8, out_buff_len: usize) -> i32;
95
96 /// Retrieves the current transaction base fee.
97 ///
98 /// # Parameters
99 ///
100 /// - `out_buff_ptr`: A mutable pointer to a buffer where the base fee will be written.
101 /// - `out_buff_len`: The maximum length of the buffer in bytes.
102 ///
103 /// # Returns
104 ///
105 /// - Returns a positive number of bytes written to the output buffer on success
106 /// - Returns a negative error code on failure. The list of error codes is defined in
107 /// ../core/error_codes.rs
108 ///
109 /// # Safety
110 /// Caller must ensure all pointer parameters point to valid memory
111 unsafe fn base_fee(&self, out_buff_ptr: *mut u8, out_buff_len: usize) -> i32;
112
113 /// Retrieves the state of an amendment and whether it's enabled or not.
114 ///
115 /// # Parameters
116 ///
117 /// - `amendment_ptr`: A raw pointer to the amendment. This can be either the uint256 that
118 /// represents the hash of an amendment, or the string name of the
119 /// amendment.
120 /// - `amendment_len`: The length of the amendment specified by `amendment_ptr`.
121 ///
122 /// # Returns
123 ///
124 /// - Returns a boolean 0 or 1 (whether the amendment is enabled or not) on success.
125 /// - Returns a negative error code on failure. The list of error codes is defined in
126 /// ../core/error_codes.rs
127 ///
128 /// # Safety
129 /// Caller must ensure all pointer parameters point to valid memory
130 unsafe fn amendment_enabled(&self, amendment_ptr: *const u8, amendment_len: usize) -> i32;
131
132 /// Fetch a ledger entry pointed by the given ledger entry ID.
133 ///
134 /// This function uses the ledger entry ID to locate a ledger entry. If found, add it to the
135 /// cache. The cache can have up to 255 ledger entries. If `cache_num` is 0, the
136 /// new ledger entry will put in the next available cache space. If `cache_num` is not 0,
137 /// the new ledger entry will replace an existing ledger entry in the catch.
138 ///
139 /// # Parameters
140 ///
141 /// - `id_ptr`: A raw pointer to the ledger entry ID, which is a unique identifier used to
142 /// locate or store data in the ledger.
143 /// - `id_len`: The length of the ledger entry ID specified by `id_ptr`.
144 /// - `cache_num`: The cache number to which the ledger entry ID will be placed in.
145 /// If 0, the host will assign a new cache space.
146 ///
147 /// # Returns
148 ///
149 /// - Returns a positive cache number
150 /// - Returns a negative error code on failure
151 ///
152 /// # Safety
153 /// Caller must ensure all pointer parameters point to valid memory
154 unsafe fn cache_le(&self, id_ptr: *const u8, id_len: usize, cache_num: i32) -> i32;
155
156 /// Retrieves a specific transaction field and writes it into the provided output buffer.
157 ///
158 /// # Parameters
159 ///
160 /// * `field` - An integer value representing the specific transaction field to retrieve.
161 /// * `out_buff_ptr` - A mutable pointer to a buffer where the output data will be written.
162 /// * `out_buff_len` - The size (in bytes) of the buffer pointed to by `out_buff_ptr`.
163 ///
164 /// # Returns
165 ///
166 /// - Returns a positive number of bytes wrote to an output buffer on success
167 /// - Returns a negative error code on failure. The list of error codes is defined in
168 /// `../core/error_codes.rs`
169 ///
170 /// # Safety
171 /// Caller must ensure all pointer parameters point to valid memory
172 unsafe fn tx_field(&self, field: i32, out_buff_ptr: *mut u8, out_buff_len: usize) -> i32;
173
174 /// Retrieves a specific field from the current ledger object and writes it into the provided buffer.
175 ///
176 /// # Parameters
177 /// - `field` (`i32`): The integer identifier for the desired field in the ledger object.
178 /// - `out_buff_ptr` (`*mut u8`): A mutable pointer to the memory location where the field data
179 /// will be written. This should point to a pre-allocated buffer.
180 /// - `out_buff_len` (`usize`): The size (in bytes) of the buffer provided by `out_buff_ptr`.
181 ///
182 /// # Returns
183 ///
184 /// - Returns a positive number of bytes wrote to an output buffer on success
185 /// - Returns a negative error code on failure. The list of error codes is defined in
186 /// `../core/error_codes.rs`
187 ///
188 /// # Safety
189 /// Caller must ensure all pointer parameters point to valid memory
190 unsafe fn home_le_field(&self, field: i32, out_buff_ptr: *mut u8, out_buff_len: usize) -> i32;
191
192 /// Retrieves a specific field from a ledger object based on the given parameters.
193 ///
194 /// # Parameters
195 ///
196 /// - `cache_num`: An integer representing the cache index of the ledger object.
197 /// - `field`: An integer representing the specific field to retrieve from the ledger object.
198 /// - `out_buff_ptr`: A mutable pointer to a buffer where the retrieved field data will be written.
199 /// - `out_buff_len`: The size of the output buffer in bytes.
200 ///
201 /// # Returns
202 ///
203 /// - Returns a positive number of bytes wrote to an output buffer on success
204 /// - Returns a negative error code on failure. The list of error codes is defined in
205 /// `../core/error_codes.rs`
206 ///
207 /// # Safety
208 /// Caller must ensure all pointer parameters point to valid memory
209 unsafe fn le_field(
210 &self,
211 cache_num: i32,
212 field: i32,
213 out_buff_ptr: *mut u8,
214 out_buff_len: usize,
215 ) -> i32;
216
217 /// Retrieves an inner field from the current ledger object and writes it into the provided buffer.
218 ///
219 /// # Parameters
220 /// - `locator_ptr`: A pointer to a byte array containing the locator for the inner field.
221 /// - `locator_len`: The length of the locator data in bytes.
222 /// - `out_buff_ptr`: A pointer to a mutable byte array where the resulting field data will be written.
223 /// - `out_buff_len`: The size of the output buffer in bytes.
224 ///
225 /// # Returns
226 ///
227 /// - Returns a positive number of bytes wrote to an output buffer on success
228 /// - Returns a negative error code on failure. The list of error codes is defined in
229 /// `../core/error_codes.rs`
230 ///
231 /// # Safety
232 /// Caller must ensure all pointer parameters point to valid memory
233 unsafe fn tx_inner(
234 &self,
235 locator_ptr: *const u8,
236 locator_len: usize,
237 out_buff_ptr: *mut u8,
238 out_buff_len: usize,
239 ) -> i32;
240
241 /// Retrieves a specific inner field from the current ledger object.
242 ///
243 /// This function is designed to access an inner field within the ledger object
244 /// specified by the `locator`. The `locator` acts as a path or identifier to
245 /// the desired field. The resulting data is written to the `out_buff` buffer.
246 /// The function returns a status code indicating success or failure of the operation.
247 ///
248 /// # Parameters
249 /// - `locator_ptr`: A pointer to a byte array containing the locator for the inner field.
250 /// - `locator_len`: The length of the locator data in bytes.
251 /// - `out_buff_ptr`: A pointer to a mutable byte array where the resulting field data will be written.
252 /// - `out_buff_len`: The size of the output buffer in bytes.
253 ///
254 /// # Returns
255 ///
256 /// - Returns a positive number of bytes wrote to an output buffer on success
257 /// - Returns a negative error code on failure. The list of error codes is defined in
258 /// `../core/error_codes.rs`
259 ///
260 /// # Safety
261 /// Caller must ensure all pointer parameters point to valid memory
262 unsafe fn home_le_inner(
263 &self,
264 locator_ptr: *const u8,
265 locator_len: usize,
266 out_buff_ptr: *mut u8,
267 out_buff_len: usize,
268 ) -> i32;
269
270 /// Retrieves an inner field from a ledger object in a specific cache_num and writes the result into an output buffer.
271 ///
272 /// # Parameters
273 /// - `cache_num`: The cache index of the ledger object to access.
274 /// - `locator_ptr`: A pointer to the memory location containing the locator string data
275 /// (used to identify the inner field in the ledger object).
276 /// - `locator_len`: The length of the locator string.
277 /// - `out_buff_ptr`: A pointer to the buffer where the retrieved inner field value will be written.
278 /// - `out_buff_len`: The size of the output buffer in bytes.
279 ///
280 /// # Returns
281 ///
282 /// - Returns a positive number of bytes wrote to an output buffer on success
283 /// - Returns a negative error code on failure. The list of error codes is defined in
284 /// `../core/error_codes.rs`
285 ///
286 /// # Safety
287 /// Caller must ensure all pointer parameters point to valid memory
288 unsafe fn le_inner(
289 &self,
290 cache_num: i32,
291 locator_ptr: *const u8,
292 locator_len: usize,
293 out_buff_ptr: *mut u8,
294 out_buff_len: usize,
295 ) -> i32;
296
297 /// Retrieves the length of an array based on the provided field value.
298 ///
299 /// # Parameters
300 /// - `field` (i32): The integer identifier for the desired field.
301 ///
302 /// # Returns
303 ///
304 /// - Returns a positive number of array length on success
305 /// - Returns a negative error code on failure. The list of error codes is defined in
306 /// ../core/error_codes.rs
307 ///
308 /// # Safety
309 /// This function is safe to call from WASM context
310 unsafe fn tx_arr_len(&self, field: i32) -> i32;
311
312 /// Retrieves the length of an array based on the provided field value.
313 ///
314 /// # Parameters
315 /// - `field` (i32): The integer identifier for the desired field.
316 ///
317 /// # Returns
318 ///
319 /// - Returns a positive number of array length on success
320 /// - Returns a negative error code on failure. The list of error codes is defined in
321 /// ../core/error_codes.rs
322 ///
323 /// # Safety
324 /// This function is safe to call from WASM context
325 unsafe fn home_le_arr_len(&self, field: i32) -> i32;
326
327 /// Retrieves the length of an array based on the provided cache number and field value.
328 ///
329 /// # Parameters
330 /// - `cache_num`: The cache index of the ledger object to access.
331 /// - `field` (i32): The integer identifier for the desired field.
332 ///
333 /// # Returns
334 ///
335 /// - Returns a positive number of array length on success
336 /// - Returns a negative error code on failure. The list of error codes is defined in
337 /// ../core/error_codes.rs
338 ///
339 /// # Safety
340 /// This function is safe to call from WASM context
341 unsafe fn le_arr_len(&self, cache_num: i32, field: i32) -> i32;
342
343 /// Retrieves the length of an array based on the provided locator.
344 ///
345 /// # Parameters
346 /// - `locator_ptr`: A pointer to a byte array containing the locator for the inner field.
347 /// - `locator_len`: The length of the locator data in bytes.
348 ///
349 /// # Returns
350 ///
351 /// - Returns a positive number of array length on success
352 /// - Returns a negative error code on failure. The list of error codes is defined in
353 /// ../core/error_codes.rs
354 ///
355 /// # Safety
356 /// Caller must ensure all pointer parameters point to valid memory
357 unsafe fn tx_inner_arr_len(&self, locator_ptr: *const u8, locator_len: usize) -> i32;
358
359 /// Retrieves the length of an array based on the provided locator.
360 ///
361 /// # Parameters
362 /// - `locator_ptr`: A pointer to a byte array containing the locator for the inner field.
363 /// - `locator_len`: The length of the locator data in bytes.
364 ///
365 /// # Returns
366 ///
367 /// - Returns a positive number of array length on success
368 /// - Returns a negative error code on failure. The list of error codes is defined in
369 /// ../core/error_codes.rs
370 ///
371 /// # Safety
372 /// Caller must ensure all pointer parameters point to valid memory
373 unsafe fn home_le_inner_arr_len(&self, locator_ptr: *const u8, locator_len: usize) -> i32;
374
375 /// Retrieves the length of an array based on the provided locator.
376 ///
377 /// # Parameters
378 /// - `cache_num`: The cache index of the ledger object to access.
379 /// - `locator_ptr`: A pointer to a byte array containing the locator for the inner field.
380 /// - `locator_len`: The length of the locator data in bytes.
381 ///
382 /// # Returns
383 ///
384 /// - Returns a positive number of array length on success
385 /// - Returns a negative error code on failure. The list of error codes is defined in
386 /// ../core/error_codes.rs
387 ///
388 /// # Safety
389 /// Caller must ensure all pointer parameters point to valid memory
390 unsafe fn le_inner_arr_len(
391 &self,
392 cache_num: i32,
393 locator_ptr: *const u8,
394 locator_len: usize,
395 ) -> i32;
396
397 // ###################################################
398 // Host Function Category: update current ledger entry
399 // ###################################################
400
401 /// Updates a data field of the current ledger entry
402 ///
403 /// # Parameters
404 ///
405 /// - `data_ptr`: A pointer to the data to be written.
406 /// - `data_len`: The size of the data.
407 ///
408 /// # Returns
409 ///
410 /// - 0 on success
411 /// - negative for an error
412 ///
413 /// # Safety
414 /// Caller must ensure all pointer parameters point to valid memory
415 unsafe fn set_data(&self, data_ptr: *const u8, data_len: usize) -> i32;
416
417 // ###################################################
418 // Host Function Category: hash and ledger entry ID computation
419 // ###################################################
420
421 /// Computes the first 32 bytes (half) of the SHA-512 hash for the given input data.
422 ///
423 /// # Parameters
424 ///
425 /// - `data_ptr`: A pointer to the input data to be hashed.
426 /// - `data_len`: The length, in bytes, of the input data.
427 /// - `out_buff_ptr`: A pointer to the buffer where the resulting 32-byte hash will be written.
428 /// - `out_buff_len`: The length, in bytes, of the output buffer.
429 ///
430 /// # Returns
431 ///
432 /// - Returns a positive number of bytes wrote to an output buffer on success
433 /// - Returns a negative error code on failure. The list of error codes is defined in
434 /// ../core/error_codes.rs
435 ///
436 /// # Safety
437 /// Caller must ensure all pointer parameters point to valid memory
438 unsafe fn sha512_half(
439 &self,
440 data_ptr: *const u8,
441 data_len: usize,
442 out_buff_ptr: *mut u8,
443 out_buff_len: usize,
444 ) -> i32;
445
446 /// Checks a key signature when provided the message and public key.
447 ///
448 /// # Parameters
449 /// - `message_ptr`: A pointer to the message data to be verified.
450 /// - `message_len`: The length, in bytes, of the message data.
451 /// - `signature_ptr`: A pointer to the signature data.
452 /// - `signature_len`: The length, in bytes, of the signature data.
453 /// - `pubkey_ptr`: A pointer to the public key data.
454 /// - `pubkey_len`: The length, in bytes, of the public key data.
455 ///
456 /// # Returns
457 ///
458 /// - Returns 1 if the signature is valid.
459 /// - Returns 0 if the signature is invalid.
460 /// - Returns a negative error code on failure. The list of error codes is defined in
461 /// ../core/error_codes.rs
462 ///
463 /// # Safety
464 /// Caller must ensure all pointer parameters point to valid memory
465 unsafe fn check_sig(
466 &self,
467 message_ptr: *const u8,
468 message_len: usize,
469 signature_ptr: *const u8,
470 signature_len: usize,
471 pubkey_ptr: *const u8,
472 pubkey_len: usize,
473 ) -> i32;
474
475 /// Generates the ledger entry ID (key identifier) for a specific account.
476 ///
477 /// This function is used to calculate the account ledger entry ID in a cryptographic or
478 /// blockchain-based system. A ledger entry ID is typically used to identify an account or entity
479 /// in a secure and deterministic way.
480 ///
481 /// # Parameters
482 ///
483 /// - `account_ptr`: A pointer to the memory of the account identifier.
484 /// - `account_len`: The size (in bytes) of the data pointed to by `account_ptr`.
485 /// - `out_buff_ptr`: A pointer to the memory where the generated ledger entry ID will be stored.
486 /// - `out_buff_len`: The length (in bytes) of the buffer pointed to by `out_buff_ptr`.
487 ///
488 /// # Returns
489 ///
490 /// - Returns a positive number of bytes wrote to an output buffer on success
491 /// - Returns a negative error code on failure. The list of error codes is defined in
492 /// `../core/error_codes.rs`
493 ///
494 /// # Safety
495 /// Caller must ensure all pointer parameters point to valid memory
496 unsafe fn accountroot_id(
497 &self,
498 account_ptr: *const u8,
499 account_len: usize,
500 out_buff_ptr: *mut u8,
501 out_buff_len: usize,
502 ) -> i32;
503
504 /// Generates the ledger entry ID (key identifier) for a specific AMM.
505 ///
506 /// This function is used to calculate the AMM ledger entry ID in a cryptographic or
507 /// blockchain-based system. A ledger entry ID is typically used to identify an AMM or entity
508 /// in a secure and deterministic way.
509 ///
510 /// # Parameters
511 ///
512 /// - `issue1_ptr`: A pointer to the memory of the issue1 identifier.
513 /// - `issue1_len`: The size (in bytes) of the data pointed to by `issue1_ptr`.
514 /// - `issue2_ptr`: A pointer to the memory of the issue2 identifier.
515 /// - `issue2_len`: The size (in bytes) of the data pointed to by `issue2_ptr`.
516 /// - `out_buff_ptr`: A pointer to the memory where the generated ledger entry ID will be stored.
517 /// - `out_buff_len`: The length (in bytes) of the buffer pointed to by `out_buff_ptr`.
518 ///
519 /// # Returns
520 ///
521 /// - Returns a positive number of bytes wrote to an output buffer on success
522 /// - Returns a negative error code on failure. The list of error codes is defined in
523 /// `../core/error_codes.rs`
524 ///
525 /// # Safety
526 /// Caller must ensure all pointer parameters point to valid memory
527 unsafe fn amm_id(
528 &self,
529 issue1_ptr: *const u8,
530 issue1_len: usize,
531 issue2_ptr: *const u8,
532 issue2_len: usize,
533 out_buff_ptr: *mut u8,
534 out_buff_len: usize,
535 ) -> i32;
536
537 /// Computes the Ledger entry ID for a check entry in a ledger.
538 ///
539 /// # Parameters
540 ///
541 /// - `account_ptr`: A pointer to the memory location of the accountID.
542 /// - `account_len`: The length of the accountID.
543 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
544 /// - `sequence_len`: The length of the sequence data.
545 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
546 /// - `out_buff_len`: The length of the output buffer.
547 ///
548 /// # Returns
549 ///
550 /// - Returns a positive number of bytes wrote to an output buffer on success
551 /// - Returns a negative error code on failure. The list of error codes is defined in
552 /// ../core/error_codes.rs
553 ///
554 /// # Safety
555 /// Caller must ensure all pointer parameters point to valid memory
556 unsafe fn check_id(
557 &self,
558 account_ptr: *const u8,
559 account_len: usize,
560 sequence_ptr: *const u8,
561 sequence_len: usize,
562 out_buff_ptr: *mut u8,
563 out_buff_len: usize,
564 ) -> i32;
565
566 /// Generates a ledger entry ID for a credential.
567 ///
568 /// # Parameters
569 ///
570 /// * `subject_ptr`: A pointer to the memory location where the subject data begins.
571 /// * `subject_len`: The length of the subject data in bytes.
572 /// * `issuer_ptr`: A pointer to the memory location where the issuer data begins.
573 /// * `issuer_len`: The length of the issuer data in bytes.
574 /// * `cred_type_ptr`: A pointer to the memory location where the credential type data begins.
575 /// * `cred_type_len`: The length of the credential type data in bytes.
576 /// * `out_buff_ptr`: A pointer to the buffer where the generated ledger entry ID will be written.
577 /// * `out_buff_len`: The size of the output buffer in bytes.
578 ///
579 /// # Returns
580 ///
581 /// - Returns a positive number of bytes wrote to an output buffer on success
582 /// - Returns a negative error code on failure. The list of error codes is defined in
583 /// `../core/error_codes.rs`
584 ///
585 /// # Safety
586 /// Caller must ensure all pointer parameters point to valid memory
587 #[allow(clippy::too_many_arguments)]
588 unsafe fn credential_id(
589 &self,
590 subject_ptr: *const u8,
591 subject_len: usize,
592 issuer_ptr: *const u8,
593 issuer_len: usize,
594 cred_type_ptr: *const u8,
595 cred_type_len: usize,
596 out_buff_ptr: *mut u8,
597 out_buff_len: usize,
598 ) -> i32;
599
600 /// Computes the Ledger entry ID for a delegate entry in a ledger.
601 ///
602 /// # Parameters
603 ///
604 /// - `account_ptr`: A pointer to the memory location of the accountID.
605 /// - `account_len`: The length of the accountID.
606 /// - `authorize_ptr`: A pointer to the memory location of the authorized account.
607 /// - `authorize_len`: The length of the authorized account.
608 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
609 /// - `out_buff_len`: The length of the output buffer.
610 ///
611 /// # Returns
612 ///
613 /// - Returns a positive number of bytes wrote to an output buffer on success
614 /// - Returns a negative error code on failure. The list of error codes is defined in
615 /// ../core/error_codes.rs
616 ///
617 /// # Safety
618 /// Caller must ensure all pointer parameters point to valid memory
619 unsafe fn delegate_id(
620 &self,
621 account_ptr: *const u8,
622 account_len: usize,
623 authorize_ptr: *const u8,
624 authorize_len: usize,
625 out_buff_ptr: *mut u8,
626 out_buff_len: usize,
627 ) -> i32;
628
629 /// Computes the Ledger entry ID for a deposit preauth entry in a ledger.
630 ///
631 /// # Parameters
632 ///
633 /// - `account_ptr`: A pointer to the memory location of the accountID.
634 /// - `account_len`: The length of the accountID.
635 /// - `authorize_ptr`: A pointer to the memory location of the authorized account.
636 /// - `authorize_len`: The length of the authorized account.
637 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
638 /// - `out_buff_len`: The length of the output buffer.
639 ///
640 /// # Returns
641 ///
642 /// - Returns a positive number of bytes wrote to an output buffer on success
643 /// - Returns a negative error code on failure. The list of error codes is defined in
644 /// ../core/error_codes.rs
645 ///
646 /// # Safety
647 /// Caller must ensure all pointer parameters point to valid memory
648 unsafe fn deposit_preauth_id(
649 &self,
650 account_ptr: *const u8,
651 account_len: usize,
652 authorize_ptr: *const u8,
653 authorize_len: usize,
654 out_buff_ptr: *mut u8,
655 out_buff_len: usize,
656 ) -> i32;
657
658 /// Computes the Ledger entry ID for a DID entry in a ledger.
659 ///
660 /// # Parameters
661 ///
662 /// - `account_ptr`: A pointer to the memory location of the accountID.
663 /// - `account_len`: The length of the accountID.
664 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
665 /// - `out_buff_len`: The length of the output buffer.
666 ///
667 /// # Returns
668 ///
669 /// - Returns a positive number of bytes wrote to an output buffer on success
670 /// - Returns a negative error code on failure. The list of error codes is defined in
671 /// ../core/error_codes.rs
672 ///
673 /// # Safety
674 /// Caller must ensure all pointer parameters point to valid memory
675 unsafe fn did_id(
676 &self,
677 account_ptr: *const u8,
678 account_len: usize,
679 out_buff_ptr: *mut u8,
680 out_buff_len: usize,
681 ) -> i32;
682
683 /// Computes the Ledger entry ID for an escrow entry in a ledger.
684 ///
685 /// # Parameters
686 ///
687 /// - `account_ptr`: A pointer to the memory location of the accountID.
688 /// - `account_len`: The length of the accountID.
689 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
690 /// - `sequence_len`: The length of the sequence data.
691 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
692 /// - `out_buff_len`: The length of the output buffer.
693 ///
694 /// # Returns
695 ///
696 /// - Returns a positive number of bytes wrote to an output buffer on success
697 /// - Returns a negative error code on failure. The list of error codes is defined in
698 /// `../core/error_codes.rs`
699 ///
700 /// # Safety
701 /// Caller must ensure all pointer parameters point to valid memory
702 unsafe fn escrow_id(
703 &self,
704 account_ptr: *const u8,
705 account_len: usize,
706 sequence_ptr: *const u8,
707 sequence_len: usize,
708 out_buff_ptr: *mut u8,
709 out_buff_len: usize,
710 ) -> i32;
711
712 /// Computes the Ledger entry ID for a trustline entry in a ledger.
713 ///
714 /// # Parameters
715 ///
716 /// - `account1_ptr`: A pointer to the memory location of the first accountID.
717 /// - `account1_len`: The length of the first accountID.
718 /// - `account2_ptr`: A pointer to the memory location of the second accountID.
719 /// - `account2_len`: The length of the second accountID.
720 /// - `currency_ptr`: A pointer to the memory location of the currency.
721 /// - `currency_len`: The length of the currency.
722 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
723 /// - `out_buff_len`: The length of the output buffer.
724 ///
725 /// # Returns
726 ///
727 /// - Returns a positive number of bytes wrote to an output buffer on success
728 /// - Returns a negative error code on failure. The list of error codes is defined in
729 /// ../core/error_codes.rs
730 ///
731 /// # Safety
732 /// Caller must ensure all pointer parameters point to valid memory
733 #[allow(clippy::too_many_arguments)]
734 unsafe fn trustline_id(
735 &self,
736 account1_ptr: *const u8,
737 account1_len: usize,
738 account2_ptr: *const u8,
739 account2_len: usize,
740 currency_ptr: *const u8,
741 currency_len: usize,
742 out_buff_ptr: *mut u8,
743 out_buff_len: usize,
744 ) -> i32;
745
746 /// Computes the Ledger entry ID for an MPT issuance entry in a ledger.
747 ///
748 /// # Parameters
749 ///
750 /// - `issuer_ptr`: A pointer to the memory location of the accountID.
751 /// - `issuer_len`: The length of the accountID.
752 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
753 /// - `sequence_len`: The length of the sequence data.
754 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
755 /// - `out_buff_len`: The length of the output buffer.
756 ///
757 /// # Returns
758 ///
759 /// - Returns a positive number of bytes wrote to an output buffer on success
760 /// - Returns a negative error code on failure. The list of error codes is defined in
761 /// `../core/error_codes.rs`
762 ///
763 /// # Safety
764 /// Caller must ensure all pointer parameters point to valid memory
765 unsafe fn mpt_issuance_id(
766 &self,
767 issuer_ptr: *const u8,
768 issuer_len: usize,
769 sequence_ptr: *const u8,
770 sequence_len: usize,
771 out_buff_ptr: *mut u8,
772 out_buff_len: usize,
773 ) -> i32;
774
775 /// Computes the Ledger entry ID for an MPToken entry in a ledger.
776 ///
777 /// # Parameters
778 ///
779 /// - `mptid_ptr`: A pointer to the memory location of the MPTID.
780 /// - `mptid_len`: The length of the MPTID.
781 /// - `holder_ptr`: A pointer to the memory location of the holder account.
782 /// - `holder_len`: The length of the holder account.
783 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
784 /// - `out_buff_len`: The length of the output buffer.
785 ///
786 /// # Returns
787 ///
788 /// - Returns a positive number of bytes wrote to an output buffer on success
789 /// - Returns a negative error code on failure. The list of error codes is defined in
790 /// ../core/error_codes.rs
791 ///
792 /// # Safety
793 /// Caller must ensure all pointer parameters point to valid memory
794 unsafe fn mptoken_id(
795 &self,
796 mptid_ptr: *const u8,
797 mptid_len: usize,
798 holder_ptr: *const u8,
799 holder_len: usize,
800 out_buff_ptr: *mut u8,
801 out_buff_len: usize,
802 ) -> i32;
803
804 /// Computes the Ledger entry ID for an NFT offer entry in a ledger.
805 ///
806 /// # Parameters
807 ///
808 /// - `account_ptr`: A pointer to the memory location of the accountID.
809 /// - `account_len`: The length of the accountID.
810 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
811 /// - `sequence_len`: The length of the sequence data.
812 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
813 /// - `out_buff_len`: The length of the output buffer.
814 ///
815 /// # Returns
816 ///
817 /// - Returns a positive number of bytes wrote to an output buffer on success
818 /// - Returns a negative error code on failure. The list of error codes is defined in
819 /// ../core/error_codes.rs
820 ///
821 /// # Safety
822 /// Caller must ensure all pointer parameters point to valid memory
823 unsafe fn nft_offer_id(
824 &self,
825 account_ptr: *const u8,
826 account_len: usize,
827 sequence_ptr: *const u8,
828 sequence_len: usize,
829 out_buff_ptr: *mut u8,
830 out_buff_len: usize,
831 ) -> i32;
832
833 /// Computes the Ledger entry ID for an offer entry in a ledger.
834 ///
835 /// # Parameters
836 ///
837 /// - `account_ptr`: A pointer to the memory location of the accountID.
838 /// - `account_len`: The length of the accountID.
839 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
840 /// - `sequence_len`: The length of the sequence data.
841 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
842 /// - `out_buff_len`: The length of the output buffer.
843 ///
844 /// # Returns
845 ///
846 /// - Returns a positive number of bytes wrote to an output buffer on success
847 /// - Returns a negative error code on failure. The list of error codes is defined in
848 /// ../core/error_codes.rs
849 ///
850 /// # Safety
851 /// Caller must ensure all pointer parameters point to valid memory
852 unsafe fn offer_id(
853 &self,
854 account_ptr: *const u8,
855 account_len: usize,
856 sequence_ptr: *const u8,
857 sequence_len: usize,
858 out_buff_ptr: *mut u8,
859 out_buff_len: usize,
860 ) -> i32;
861
862 /// Generates a ledger entry ID associated with an oracle's account and document ID.
863 ///
864 /// # Parameters
865 ///
866 /// - `account_ptr`: A pointer to the memory location of the accountID.
867 /// - `account_len`: The length of the accountID.
868 /// - `document_id_ptr`: A pointer to the memory location of the document ID.
869 /// - `document_id_len`: The length of the document ID data.
870 /// - `out_buff_ptr`: A pointer to a pre-allocated buffer where the resulting ledger entry ID will be
871 /// written.
872 /// - `out_buff_len`: The size of the output buffer in bytes.
873 ///
874 /// # Returns
875 ///
876 /// - Returns a positive number of bytes wrote to an output buffer on success
877 /// - Returns a negative error code on failure. The list of error codes is defined in
878 /// `../core/error_codes.rs`
879 ///
880 /// # Safety
881 /// Caller must ensure all pointer parameters point to valid memory
882 unsafe fn oracle_id(
883 &self,
884 account_ptr: *const u8,
885 account_len: usize,
886 document_id_ptr: *const u8,
887 document_id_len: usize,
888 out_buff_ptr: *mut u8,
889 out_buff_len: usize,
890 ) -> i32;
891
892 /// Computes the Ledger entry ID for a payment channel entry in a ledger.
893 ///
894 /// # Parameters
895 ///
896 /// - `account_ptr`: A pointer to the memory location of the accountID.
897 /// - `account_len`: The length of the accountID.
898 /// - `destination_ptr`: A pointer to the memory location of the destination.
899 /// - `destination_len`: The length of the destination.
900 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
901 /// - `sequence_len`: The length of the sequence data.
902 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
903 /// - `out_buff_len`: The length of the output buffer.
904 ///
905 /// # Returns
906 ///
907 /// - Returns a positive number of bytes wrote to an output buffer on success
908 /// - Returns a negative error code on failure. The list of error codes is defined in
909 /// ../core/error_codes.rs
910 ///
911 /// # Safety
912 /// Caller must ensure all pointer parameters point to valid memory
913 #[allow(clippy::too_many_arguments)]
914 unsafe fn paychan_id(
915 &self,
916 account_ptr: *const u8,
917 account_len: usize,
918 destination_ptr: *const u8,
919 destination_len: usize,
920 sequence_ptr: *const u8,
921 sequence_len: usize,
922 out_buff_ptr: *mut u8,
923 out_buff_len: usize,
924 ) -> i32;
925
926 /// Computes the Ledger entry ID for a permissioned domain entry in a ledger.
927 ///
928 /// # Parameters
929 ///
930 /// - `account_ptr`: A pointer to the memory location of the accountID.
931 /// - `account_len`: The length of the accountID.
932 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
933 /// - `sequence_len`: The length of the sequence data.
934 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
935 /// - `out_buff_len`: The length of the output buffer.
936 ///
937 /// # Returns
938 ///
939 /// - Returns a positive number of bytes wrote to an output buffer on success
940 /// - Returns a negative error code on failure. The list of error codes is defined in
941 /// ../core/error_codes.rs
942 ///
943 /// # Safety
944 /// Caller must ensure all pointer parameters point to valid memory
945 unsafe fn permissioned_domain_id(
946 &self,
947 account_ptr: *const u8,
948 account_len: usize,
949 sequence_ptr: *const u8,
950 sequence_len: usize,
951 out_buff_ptr: *mut u8,
952 out_buff_len: usize,
953 ) -> i32;
954
955 /// Computes the Ledger entry ID for a signer entry in a ledger.
956 ///
957 /// # Parameters
958 ///
959 /// - `account_ptr`: A pointer to the memory location of the accountID.
960 /// - `account_len`: The length of the accountID.
961 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
962 /// - `out_buff_len`: The length of the output buffer.
963 ///
964 /// # Returns
965 ///
966 /// - Returns a positive number of bytes wrote to an output buffer on success
967 /// - Returns a negative error code on failure. The list of error codes is defined in
968 /// ../core/error_codes.rs
969 ///
970 /// # Safety
971 /// Caller must ensure all pointer parameters point to valid memory
972 unsafe fn signers_id(
973 &self,
974 account_ptr: *const u8,
975 account_len: usize,
976 out_buff_ptr: *mut u8,
977 out_buff_len: usize,
978 ) -> i32;
979
980 /// Computes the Ledger entry ID for a ticket entry in a ledger.
981 ///
982 /// # Parameters
983 ///
984 /// - `account_ptr`: A pointer to the memory location of the accountID.
985 /// - `account_len`: The length of the accountID.
986 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
987 /// - `sequence_len`: The length of the sequence data.
988 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
989 /// - `out_buff_len`: The length of the output buffer.
990 ///
991 /// # Returns
992 ///
993 /// - Returns a positive number of bytes wrote to an output buffer on success
994 /// - Returns a negative error code on failure. The list of error codes is defined in
995 /// ../core/error_codes.rs
996 ///
997 /// # Safety
998 /// Caller must ensure all pointer parameters point to valid memory
999 unsafe fn ticket_id(
1000 &self,
1001 account_ptr: *const u8,
1002 account_len: usize,
1003 sequence_ptr: *const u8,
1004 sequence_len: usize,
1005 out_buff_ptr: *mut u8,
1006 out_buff_len: usize,
1007 ) -> i32;
1008
1009 /// Computes the Ledger entry ID for a vault entry in a ledger.
1010 ///
1011 /// # Parameters
1012 ///
1013 /// - `account_ptr`: A pointer to the memory location of the accountID.
1014 /// - `account_len`: The length of the accountID.
1015 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
1016 /// - `sequence_len`: The length of the sequence data.
1017 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
1018 /// - `out_buff_len`: The length of the output buffer.
1019 ///
1020 /// # Returns
1021 ///
1022 /// - Returns a positive number of bytes wrote to an output buffer on success
1023 /// - Returns a negative error code on failure. The list of error codes is defined in
1024 /// ../core/error_codes.rs
1025 ///
1026 /// # Safety
1027 /// Caller must ensure all pointer parameters point to valid memory
1028 unsafe fn vault_id(
1029 &self,
1030 account_ptr: *const u8,
1031 account_len: usize,
1032 sequence_ptr: *const u8,
1033 sequence_len: usize,
1034 out_buff_ptr: *mut u8,
1035 out_buff_len: usize,
1036 ) -> i32;
1037
1038 /// Computes the Ledger entry ID for a sponsorship entry in a ledger.
1039 ///
1040 /// # Parameters
1041 ///
1042 /// - `sponsor_ptr`: A pointer to the memory location of the sponsor accountID.
1043 /// - `sponsor_len`: The length of the sponsor accountID.
1044 /// - `sponsee_ptr`: A pointer to the memory location of the sponsee accountID.
1045 /// - `sponsee_len`: The length of the sponsee accountID.
1046 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
1047 /// - `out_buff_len`: The length of the output buffer.
1048 ///
1049 /// # Returns
1050 ///
1051 /// - Returns a positive number of bytes wrote to an output buffer on success
1052 /// - Returns a negative error code on failure. The list of error codes is defined in
1053 /// ../core/error_codes.rs
1054 ///
1055 /// # Safety
1056 /// Caller must ensure all pointer parameters point to valid memory
1057 unsafe fn sponsorship_id(
1058 &self,
1059 sponsor_ptr: *const u8,
1060 sponsor_len: usize,
1061 sponsee_ptr: *const u8,
1062 sponsee_len: usize,
1063 out_buff_ptr: *mut u8,
1064 out_buff_len: usize,
1065 ) -> i32;
1066
1067 /// Computes the Ledger entry ID for a loan broker entry in a ledger.
1068 ///
1069 /// # Parameters
1070 ///
1071 /// - `owner_ptr`: A pointer to the memory location of the owner accountID.
1072 /// - `owner_len`: The length of the owner accountID.
1073 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
1074 /// - `sequence_len`: The length of the sequence data.
1075 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
1076 /// - `out_buff_len`: The length of the output buffer.
1077 ///
1078 /// # Returns
1079 ///
1080 /// - Returns a positive number of bytes wrote to an output buffer on success
1081 /// - Returns a negative error code on failure. The list of error codes is defined in
1082 /// ../core/error_codes.rs
1083 ///
1084 /// # Safety
1085 /// Caller must ensure all pointer parameters point to valid memory
1086 unsafe fn loan_broker_id(
1087 &self,
1088 owner_ptr: *const u8,
1089 owner_len: usize,
1090 sequence_ptr: *const u8,
1091 sequence_len: usize,
1092 out_buff_ptr: *mut u8,
1093 out_buff_len: usize,
1094 ) -> i32;
1095
1096 /// Computes the Ledger entry ID for a loan entry in a ledger.
1097 ///
1098 /// # Parameters
1099 ///
1100 /// - `loan_broker_id_ptr`: A pointer to the memory location of the 32-byte loan broker id.
1101 /// - `loan_broker_id_len`: The length of the loan broker id.
1102 /// - `sequence_ptr`: A pointer to the memory location of the loan sequence number.
1103 /// - `sequence_len`: The length of the sequence data.
1104 /// - `out_buff_ptr`: A pointer to the output buffer where the derived ledger entry ID will be stored.
1105 /// - `out_buff_len`: The length of the output buffer.
1106 ///
1107 /// # Returns
1108 ///
1109 /// - Returns a positive number of bytes wrote to an output buffer on success
1110 /// - Returns a negative error code on failure. The list of error codes is defined in
1111 /// ../core/error_codes.rs
1112 ///
1113 /// # Safety
1114 /// Caller must ensure all pointer parameters point to valid memory
1115 unsafe fn loan_id(
1116 &self,
1117 loan_broker_id_ptr: *const u8,
1118 loan_broker_id_len: usize,
1119 sequence_ptr: *const u8,
1120 sequence_len: usize,
1121 out_buff_ptr: *mut u8,
1122 out_buff_len: usize,
1123 ) -> i32;
1124
1125 // #############################
1126 // Host Function Category: NFT
1127 // #############################
1128
1129 /// Retrieves the URI details of a specific NFT (Non-Fungible Token) associated with a given account.
1130 ///
1131 /// # Parameters
1132 ///
1133 /// - `account_ptr`: A pointer to the memory location of the accountID.
1134 /// - `account_len`: The length of the accountID.
1135 /// - `nft_id_ptr`: A pointer to the memory location containing the NFT identifier.
1136 /// - `nft_id_len`: The length of the NFT identifier in bytes.
1137 /// - `out_buff_ptr`: A mutable pointer to the memory location where the retrieved NFT URI
1138 /// will be written.
1139 /// - `out_buff_len`: The maximum length of the output buffer.
1140 ///
1141 /// # Returns
1142 ///
1143 /// - Returns a positive number of bytes wrote to an output buffer on success
1144 /// - Returns a negative error code on failure. The list of error codes is defined in
1145 /// `../core/error_codes.rs`
1146 ///
1147 /// # Safety
1148 /// Caller must ensure all pointer parameters point to valid memory
1149 unsafe fn nft_uri(
1150 &self,
1151 account_ptr: *const u8,
1152 account_len: usize,
1153 nft_id_ptr: *const u8,
1154 nft_id_len: usize,
1155 out_buff_ptr: *mut u8,
1156 out_buff_len: usize,
1157 ) -> i32;
1158
1159 /// Retrieves the issuer of a specific NFT (Non-Fungible Token).
1160 ///
1161 /// # Parameters
1162 ///
1163 /// - `nft_id_ptr`: A pointer to the memory location containing the NFT identifier.
1164 /// - `nft_id_len`: The length of the NFT identifier in bytes.
1165 /// - `out_buff_ptr`: A mutable pointer to the memory location where the retrieved issuer
1166 /// account will be written.
1167 /// - `out_buff_len`: The maximum length of the output buffer.
1168 ///
1169 /// # Returns
1170 ///
1171 /// - Returns a positive number of bytes wrote to an output buffer on success
1172 /// - Returns a negative error code on failure. The list of error codes is defined in
1173 /// ../core/error_codes.rs
1174 ///
1175 /// # Safety
1176 /// Caller must ensure all pointer parameters point to valid memory
1177 unsafe fn nft_issuer(
1178 &self,
1179 nft_id_ptr: *const u8,
1180 nft_id_len: usize,
1181 out_buff_ptr: *mut u8,
1182 out_buff_len: usize,
1183 ) -> i32;
1184
1185 /// Retrieves the taxon of a specific NFT (Non-Fungible Token).
1186 ///
1187 /// # Parameters
1188 ///
1189 /// - `nft_id_ptr`: A pointer to the memory location containing the NFT identifier.
1190 /// - `nft_id_len`: The length of the NFT identifier in bytes.
1191 /// - `out_buff_ptr`: A mutable pointer to the memory location where the retrieved taxon
1192 /// will be written.
1193 /// - `out_buff_len`: The maximum length of the output buffer.
1194 ///
1195 /// # Returns
1196 ///
1197 /// - Returns a positive number of bytes wrote to an output buffer on success
1198 /// - Returns a negative error code on failure. The list of error codes is defined in
1199 /// ../core/error_codes.rs
1200 ///
1201 /// # Safety
1202 /// Caller must ensure all pointer parameters point to valid memory
1203 unsafe fn nft_taxon(
1204 &self,
1205 nft_id_ptr: *const u8,
1206 nft_id_len: usize,
1207 out_buff_ptr: *mut u8,
1208 out_buff_len: usize,
1209 ) -> i32;
1210
1211 /// Retrieves the flags of a specific NFT (Non-Fungible Token).
1212 ///
1213 /// # Parameters
1214 ///
1215 /// - `nft_id_ptr`: A pointer to the memory location containing the NFT identifier.
1216 /// - `nft_id_len`: The length of the NFT identifier in bytes.
1217 ///
1218 /// # Returns
1219 ///
1220 /// - Returns a positive flags value on success, which is a bitmask representing the NFT's flags
1221 /// - Returns a negative error code on failure. The list of error codes is defined in
1222 /// ../core/error_codes.rs
1223 ///
1224 /// # Safety
1225 /// Caller must ensure all pointer parameters point to valid memory
1226 unsafe fn nft_flags(&self, nft_id_ptr: *const u8, nft_id_len: usize) -> i32;
1227
1228 /// Retrieves the transfer fee of a specific NFT (Non-Fungible Token).
1229 ///
1230 /// # Parameters
1231 ///
1232 /// - `nft_id_ptr`: A pointer to the memory location containing the NFT identifier.
1233 /// - `nft_id_len`: The length of the NFT identifier in bytes.
1234 ///
1235 /// # Returns
1236 ///
1237 /// - Returns a positive transfer fee value on success
1238 /// - Returns a negative error code on failure. The list of error codes is defined in
1239 /// ../core/error_codes.rs
1240 ///
1241 /// # Safety
1242 /// Caller must ensure all pointer parameters point to valid memory
1243 unsafe fn nft_xfer_fee(&self, nft_id_ptr: *const u8, nft_id_len: usize) -> i32;
1244
1245 /// Retrieves the serial number of a specific NFT (Non-Fungible Token).
1246 ///
1247 /// # Parameters
1248 ///
1249 /// - `nft_id_ptr`: A pointer to the memory location containing the NFT identifier.
1250 /// - `nft_id_len`: The length of the NFT identifier in bytes.
1251 /// - `out_buff_ptr`: A mutable pointer to the memory location where the retrieved serial
1252 /// number will be written.
1253 /// - `out_buff_len`: The maximum length of the output buffer.
1254 ///
1255 /// # Returns
1256 ///
1257 /// - Returns a positive number of bytes wrote to an output buffer on success
1258 /// - Returns a negative error code on failure. The list of error codes is defined in
1259 /// ../core/error_codes.rs
1260 ///
1261 /// # Safety
1262 /// Caller must ensure all pointer parameters point to valid memory
1263 unsafe fn nft_serial(
1264 &self,
1265 nft_id_ptr: *const u8,
1266 nft_id_len: usize,
1267 out_buff_ptr: *mut u8,
1268 out_buff_len: usize,
1269 ) -> i32;
1270
1271 // #############################
1272 // Host Function Category: FLOAT
1273 // #############################
1274
1275 /// Converts a signed 64-bit integer to an opaque float representation
1276 /// # Parameters
1277 /// * `in_int` - The input integer to convert
1278 /// * `out_buff` - Pointer to output buffer where the float will be written
1279 /// * `out_buff_len` - The length of the output buffer in bytes
1280 /// * `rounding_mode` - Rounding mode to use for the conversion
1281 /// # Returns
1282 /// 8 on success, error code otherwise
1283 ///
1284 /// # Safety
1285 /// Caller must ensure all pointer parameters point to valid memory
1286 unsafe fn float_from_int(
1287 &self,
1288 in_int: i64,
1289 out_buff: *mut u8,
1290 out_buff_len: usize,
1291 rounding_mode: i32,
1292 ) -> i32;
1293
1294 /// Converts an unsigned integer to an opaque float representation
1295 /// # Parameters
1296 /// * `in_uint_ptr` - Pointer to the input unsigned integer
1297 /// * `in_uint_len` - The length of the input unsigned integer in bytes
1298 /// * `out_buff` - Pointer to output buffer where the float will be written
1299 /// * `out_buff_len` - The length of the output buffer in bytes
1300 /// * `rounding_mode` - Rounding mode to use for the conversion
1301 /// # Returns
1302 /// 8 on success, error code otherwise
1303 ///
1304 /// # Safety
1305 /// Caller must ensure all pointer parameters point to valid memory
1306 unsafe fn float_from_uint(
1307 &self,
1308 in_uint_ptr: *const u8,
1309 in_uint_len: usize,
1310 out_buff: *mut u8,
1311 out_buff_len: usize,
1312 rounding_mode: i32,
1313 ) -> i32;
1314
1315 /// Creates a float from explicit mantissa and exponent values
1316 /// # Parameters
1317 /// * `mantissa` - The mantissa value
1318 /// * `exponent` - The exponent value
1319 /// * `out_buff` - Pointer to output buffer where the float will be written
1320 /// * `out_buff_len` - The length of the output buffer in bytes
1321 /// * `rounding_mode` - Rounding mode to use for the operation
1322 /// # Returns
1323 /// 8 on success, error code otherwise
1324 ///
1325 /// # Safety
1326 /// Caller must ensure all pointer parameters point to valid memory
1327 unsafe fn float_from_mant_exp(
1328 &self,
1329 mantissa: i64,
1330 exponent: i32,
1331 out_buff: *mut u8,
1332 out_buff_len: usize,
1333 rounding_mode: i32,
1334 ) -> i32;
1335
1336 /// Creates a float from an STAmount serialized value
1337 /// # Parameters
1338 /// * `in_buff` - Pointer to input STAmount buffer
1339 /// * `in_buff_len` - The length of the input buffer in bytes
1340 /// * `out_buff` - Pointer to output buffer where the float will be written
1341 /// * `out_buff_len` - The length of the output buffer in bytes
1342 /// * `rounding_mode` - Rounding mode to use for the operation
1343 /// # Returns
1344 /// 8 on success, error code otherwise
1345 ///
1346 /// # Safety
1347 /// Caller must ensure all pointer parameters point to valid memory
1348 unsafe fn float_from_stamount(
1349 &self,
1350 in_buff: *const u8,
1351 in_buff_len: usize,
1352 out_buff: *mut u8,
1353 out_buff_len: usize,
1354 rounding_mode: i32,
1355 ) -> i32;
1356
1357 /// Creates a float from an STNumber serialized value
1358 /// # Parameters
1359 /// * `in_buff` - Pointer to input STNumber buffer
1360 /// * `in_buff_len` - The length of the input buffer in bytes
1361 /// * `out_buff` - Pointer to output buffer where the float will be written
1362 /// * `out_buff_len` - The length of the output buffer in bytes
1363 /// * `rounding_mode` - Rounding mode to use for the operation
1364 /// # Returns
1365 /// 8 on success, error code otherwise
1366 ///
1367 /// # Safety
1368 /// Caller must ensure all pointer parameters point to valid memory
1369 unsafe fn float_from_stnumber(
1370 &self,
1371 in_buff: *const u8,
1372 in_buff_len: usize,
1373 out_buff: *mut u8,
1374 out_buff_len: usize,
1375 rounding_mode: i32,
1376 ) -> i32;
1377
1378 /// Converts a float to a signed integer
1379 /// # Parameters
1380 /// * `in_buff` - Pointer to input float value
1381 /// * `in_buff_len` - The length of the input float value in bytes
1382 /// * `out_buff` - Pointer to output buffer where the integer will be written
1383 /// * `out_buff_len` - The length of the output buffer in bytes
1384 /// * `rounding_mode` - Rounding mode to use for the operation
1385 /// # Returns
1386 /// 8 on success, error code otherwise
1387 ///
1388 /// # Safety
1389 /// Caller must ensure all pointer parameters point to valid memory
1390 unsafe fn float_to_int(
1391 &self,
1392 in_buff: *const u8,
1393 in_buff_len: usize,
1394 out_buff: *mut u8,
1395 out_buff_len: usize,
1396 rounding_mode: i32,
1397 ) -> i32;
1398
1399 /// Decomposes a float into its mantissa and exponent components
1400 /// # Parameters
1401 /// * `in_buff` - Pointer to input float value
1402 /// * `in_buff_len` - The length of the input float value in bytes
1403 /// * `mant_buff` - Pointer to output buffer where the mantissa will be written
1404 /// * `mant_buff_len` - The length of the mantissa output buffer in bytes
1405 /// * `exp_buff` - Pointer to output buffer where the exponent will be written
1406 /// * `exp_buff_len` - The length of the exponent output buffer in bytes
1407 /// # Returns
1408 /// 8 on success, error code otherwise
1409 ///
1410 /// # Safety
1411 /// Caller must ensure all pointer parameters point to valid memory
1412 unsafe fn float_to_mant_exp(
1413 &self,
1414 in_buff: *const u8,
1415 in_buff_len: usize,
1416 mant_buff: *mut u8,
1417 mant_buff_len: usize,
1418 exp_buff: *mut u8,
1419 exp_buff_len: usize,
1420 ) -> i32;
1421
1422 /// Compares two opaque float values
1423 /// # Parameters
1424 /// * `in_buff1` - Pointer to first float value
1425 /// * `in_buff1_len` - The length of the first float value in bytes
1426 /// * `in_buff2` - Pointer to second float value
1427 /// * `in_buff2_len` - The length of the second float value in bytes
1428 /// # Returns
1429 /// 0 if equal, 1 if first > second, 2 if first < second,
1430 ///
1431 /// # Safety
1432 /// Caller must ensure all pointer parameters point to valid memory
1433 unsafe fn float_cmp(
1434 &self,
1435 in_buff1: *const u8,
1436 in_buff1_len: usize,
1437 in_buff2: *const u8,
1438 in_buff2_len: usize,
1439 ) -> i32;
1440
1441 /// Adds two opaque float values
1442 /// # Parameters
1443 /// * `in_buff1` - Pointer to first float value
1444 /// * `in_buff1_len` - The length of the first float value in bytes
1445 /// * `in_buff2` - Pointer to second float value
1446 /// * `in_buff2_len` - The length of the second float value in bytes
1447 /// * `out_buff` - Pointer to output buffer where result will be written
1448 /// * `out_buff_len` - The length of the output buffer in bytes
1449 /// * `rounding_mode` - Rounding mode to use for the addition
1450 /// # Returns
1451 /// 8 on success, error code otherwise
1452 ///
1453 /// # Safety
1454 /// Caller must ensure all pointer parameters point to valid memory
1455 #[allow(clippy::too_many_arguments)]
1456 unsafe fn float_add(
1457 &self,
1458 in_buff1: *const u8,
1459 in_buff1_len: usize,
1460 in_buff2: *const u8,
1461 in_buff2_len: usize,
1462 out_buff: *mut u8,
1463 out_buff_len: usize,
1464 rounding_mode: i32,
1465 ) -> i32;
1466
1467 /// Subtracts two opaque float values
1468 /// # Parameters
1469 /// * `in_buff1` - Pointer to first float value
1470 /// * `in_buff1_len` - The length of the first float value in bytes
1471 /// * `in_buff2` - Pointer to second float value
1472 /// * `in_buff2_len` - The length of the second float value in bytes
1473 /// * `out_buff` - Pointer to output buffer where result will be written
1474 /// * `out_buff_len` - The length of the output buffer in bytes
1475 /// * `rounding_mode` - Rounding mode to use for the subtraction
1476 /// # Returns
1477 /// 8 on success, error code otherwise
1478 ///
1479 /// # Safety
1480 /// Caller must ensure all pointer parameters point to valid memory
1481 #[allow(clippy::too_many_arguments)]
1482 unsafe fn float_sub(
1483 &self,
1484 in_buff1: *const u8,
1485 in_buff1_len: usize,
1486 in_buff2: *const u8,
1487 in_buff2_len: usize,
1488 out_buff: *mut u8,
1489 out_buff_len: usize,
1490 rounding_mode: i32,
1491 ) -> i32;
1492
1493 /// Multiplies two opaque float values
1494 /// # Parameters
1495 /// * `in_buff1` - Pointer to first float value
1496 /// * `in_buff1_len` - The length of the first float value in bytes
1497 /// * `in_buff2` - Pointer to second float value
1498 /// * `in_buff2_len` - The length of the second float value in bytes
1499 /// * `out_buff` - Pointer to output buffer where result will be written
1500 /// * `out_buff_len` - The length of the output buffer in bytes
1501 /// * `rounding_mode` - Rounding mode to use for the multiplication
1502 /// # Returns
1503 /// 8 on success, error code otherwise
1504 ///
1505 /// # Safety
1506 /// Caller must ensure all pointer parameters point to valid memory
1507 #[allow(clippy::too_many_arguments)]
1508 unsafe fn float_mult(
1509 &self,
1510 in_buff1: *const u8,
1511 in_buff1_len: usize,
1512 in_buff2: *const u8,
1513 in_buff2_len: usize,
1514 out_buff: *mut u8,
1515 out_buff_len: usize,
1516 rounding_mode: i32,
1517 ) -> i32;
1518
1519 /// Divides two opaque float values
1520 /// # Parameters
1521 /// * `in_buff1` - Pointer to dividend float value
1522 /// * `in_buff1_len` - The length of the dividend float value in bytes
1523 /// * `in_buff2` - Pointer to divisor float value
1524 /// * `in_buff2_len` - The length of the divisor float value in bytes
1525 /// * `out_buff` - Pointer to output buffer where result will be written
1526 /// * `out_buff_len` - The length of the output buffer in bytes
1527 /// * `rounding_mode` - Rounding mode to use for the division
1528 /// # Returns
1529 /// 8 on success, error code otherwise
1530 ///
1531 /// # Safety
1532 /// Caller must ensure all pointer parameters point to valid memory
1533 #[allow(clippy::too_many_arguments)]
1534 unsafe fn float_div(
1535 &self,
1536 in_buff1: *const u8,
1537 in_buff1_len: usize,
1538 in_buff2: *const u8,
1539 in_buff2_len: usize,
1540 out_buff: *mut u8,
1541 out_buff_len: usize,
1542 rounding_mode: i32,
1543 ) -> i32;
1544
1545 /// Calculates the nth power of an opaque float value
1546 /// # Parameters
1547 /// * `in_buff` - Pointer to input float value
1548 /// * `in_buff_len` - The length of the input float value in bytes
1549 /// * `pow` - The power to calculate (e.g., 2 for square)
1550 /// * `out_buff` - Pointer to output buffer where result will be written
1551 /// * `out_buff_len` - The length of the output buffer in bytes
1552 /// * `rounding_mode` - Rounding mode to use for the operation
1553 /// # Returns
1554 /// 8 on success, error code otherwise
1555 ///
1556 /// # Safety
1557 /// Caller must ensure all pointer parameters point to valid memory
1558 unsafe fn float_pow(
1559 &self,
1560 in_buff: *const u8,
1561 in_buff_len: usize,
1562 pow: i32,
1563 out_buff: *mut u8,
1564 out_buff_len: usize,
1565 rounding_mode: i32,
1566 ) -> i32;
1567
1568 // #############################
1569 // Host Function Category: TRACE
1570 // #############################
1571
1572 /// Print to the trace log on XRPLd. Any XRPLd instance set to \"trace\" log level will see this.
1573 ///
1574 /// # Parameters
1575 /// - `msg_read_ptr`: A pointer to an array containing text characters (in utf8).
1576 /// - `msg_read_len`: The byte length of the text to send to the trace log.
1577 /// - `data_type`: A [`crate::host::trace::TraceDataType`] discriminant selecting how the host
1578 /// reads the data buffer. Note that it sits between the message pair and the data pair.
1579 /// - `data_read_ptr`: A pointer to an array of bytes containing the data to print.
1580 /// - `data_read_len`: The byte length of that data. Numeric types require an exact width,
1581 /// little-endian.
1582 ///
1583 /// Fire-and-forget: returns nothing and cannot fail from the guest's perspective.
1584 ///
1585 /// # Safety
1586 /// Caller must ensure all pointer parameters point to valid memory
1587 unsafe fn trace(
1588 &self,
1589 msg_read_ptr: *const u8,
1590 msg_read_len: usize,
1591 data_type: i32,
1592 data_read_ptr: *const u8,
1593 data_read_len: usize,
1594 );
1595}