xrpl_wasm_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_wasm_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.get_ledger_sqn(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 get_ledger_sqn(&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 get_parent_ledger_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 get_parent_ledger_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 get_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 keylet.
133 ///
134 /// This function uses the keylet 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 /// - `keylet_ptr`: A raw pointer to the keylet, which is a unique identifier used to
142 /// locate or store data in the ledger.
143 /// - `keylet_len`: The length of the keylet specified by `keylet_ptr`.
144 /// - `cache_num`: The cache number to which the keylet 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_ledger_obj(
155 &self,
156 keylet_ptr: *const u8,
157 keylet_len: usize,
158 cache_num: i32,
159 ) -> i32;
160
161 /// Retrieves a specific transaction field and writes it into the provided output buffer.
162 ///
163 /// # Parameters
164 ///
165 /// * `field` - An integer value representing the specific transaction field to retrieve.
166 /// * `out_buff_ptr` - A mutable pointer to a buffer where the output data will be written.
167 /// * `out_buff_len` - The size (in bytes) of the buffer pointed to by `out_buff_ptr`.
168 ///
169 /// # Returns
170 ///
171 /// - Returns a positive number of bytes wrote to an output buffer on success
172 /// - Returns a negative error code on failure. The list of error codes is defined in
173 /// `../core/error_codes.rs`
174 ///
175 /// # Safety
176 /// Caller must ensure all pointer parameters point to valid memory
177 unsafe fn get_tx_field(&self, field: i32, out_buff_ptr: *mut u8, out_buff_len: usize) -> i32;
178
179 /// Retrieves a specific field from the current ledger object and writes it into the provided buffer.
180 ///
181 /// # Parameters
182 /// - `field` (`i32`): The integer identifier for the desired field in the ledger object.
183 /// - `out_buff_ptr` (`*mut u8`): A mutable pointer to the memory location where the field data
184 /// will be written. This should point to a pre-allocated buffer.
185 /// - `out_buff_len` (`usize`): The size (in bytes) of the buffer provided by `out_buff_ptr`.
186 ///
187 /// # Returns
188 ///
189 /// - Returns a positive number of bytes wrote to an output buffer on success
190 /// - Returns a negative error code on failure. The list of error codes is defined in
191 /// `../core/error_codes.rs`
192 ///
193 /// # Safety
194 /// Caller must ensure all pointer parameters point to valid memory
195 unsafe fn get_current_ledger_obj_field(
196 &self,
197 field: i32,
198 out_buff_ptr: *mut u8,
199 out_buff_len: usize,
200 ) -> i32;
201
202 /// Retrieves a specific field from a ledger object based on the given parameters.
203 ///
204 /// # Parameters
205 ///
206 /// - `cache_num`: An integer representing the cache index of the ledger object.
207 /// - `field`: An integer representing the specific field to retrieve from the ledger object.
208 /// - `out_buff_ptr`: A mutable pointer to a buffer where the retrieved field data will be written.
209 /// - `out_buff_len`: The size of the output buffer in bytes.
210 ///
211 /// # Returns
212 ///
213 /// - Returns a positive number of bytes wrote to an output buffer on success
214 /// - Returns a negative error code on failure. The list of error codes is defined in
215 /// `../core/error_codes.rs`
216 ///
217 /// # Safety
218 /// Caller must ensure all pointer parameters point to valid memory
219 unsafe fn get_ledger_obj_field(
220 &self,
221 cache_num: i32,
222 field: i32,
223 out_buff_ptr: *mut u8,
224 out_buff_len: usize,
225 ) -> i32;
226
227 /// Retrieves a nested field from the current ledger object and writes it into the provided buffer.
228 ///
229 /// # Parameters
230 /// - `locator_ptr`: A pointer to a byte array containing the locator for the nested field.
231 /// - `locator_len`: The length of the locator data in bytes.
232 /// - `out_buff_ptr`: A pointer to a mutable byte array where the resulting field data will be written.
233 /// - `out_buff_len`: The size of the output buffer in bytes.
234 ///
235 /// # Returns
236 ///
237 /// - Returns a positive number of bytes wrote to an output buffer on success
238 /// - Returns a negative error code on failure. The list of error codes is defined in
239 /// `../core/error_codes.rs`
240 ///
241 /// # Safety
242 /// Caller must ensure all pointer parameters point to valid memory
243 unsafe fn get_tx_nested_field(
244 &self,
245 locator_ptr: *const u8,
246 locator_len: usize,
247 out_buff_ptr: *mut u8,
248 out_buff_len: usize,
249 ) -> i32;
250
251 /// Retrieves a specific nested field from the current ledger object.
252 ///
253 /// This function is designed to access a nested field within the ledger object
254 /// specified by the `locator`. The `locator` acts as a path or identifier to
255 /// the desired field. The resulting data is written to the `out_buff` buffer.
256 /// The function returns a status code indicating success or failure of the operation.
257 ///
258 /// # Parameters
259 /// - `locator_ptr`: A pointer to a byte array containing the locator for the nested field.
260 /// - `locator_len`: The length of the locator data in bytes.
261 /// - `out_buff_ptr`: A pointer to a mutable byte array where the resulting field data will be written.
262 /// - `out_buff_len`: The size of the output buffer in bytes.
263 ///
264 /// # Returns
265 ///
266 /// - Returns a positive number of bytes wrote to an output buffer on success
267 /// - Returns a negative error code on failure. The list of error codes is defined in
268 /// `../core/error_codes.rs`
269 ///
270 /// # Safety
271 /// Caller must ensure all pointer parameters point to valid memory
272 unsafe fn get_current_ledger_obj_nested_field(
273 &self,
274 locator_ptr: *const u8,
275 locator_len: usize,
276 out_buff_ptr: *mut u8,
277 out_buff_len: usize,
278 ) -> i32;
279
280 /// Retrieves a nested field from a ledger object in a specific cache_num and writes the result into an output buffer.
281 ///
282 /// # Parameters
283 /// - `cache_num`: The cache index of the ledger object to access.
284 /// - `locator_ptr`: A pointer to the memory location containing the locator string data
285 /// (used to identify the nested field in the ledger object).
286 /// - `locator_len`: The length of the locator string.
287 /// - `out_buff_ptr`: A pointer to the buffer where the retrieved nested field value will be written.
288 /// - `out_buff_len`: The size of the output buffer in bytes.
289 ///
290 /// # Returns
291 ///
292 /// - Returns a positive number of bytes wrote to an output buffer on success
293 /// - Returns a negative error code on failure. The list of error codes is defined in
294 /// `../core/error_codes.rs`
295 ///
296 /// # Safety
297 /// Caller must ensure all pointer parameters point to valid memory
298 unsafe fn get_ledger_obj_nested_field(
299 &self,
300 cache_num: i32,
301 locator_ptr: *const u8,
302 locator_len: usize,
303 out_buff_ptr: *mut u8,
304 out_buff_len: usize,
305 ) -> i32;
306
307 /// Retrieves the length of an array based on the provided field value.
308 ///
309 /// # Parameters
310 /// - `field` (i32): The integer identifier for the desired field.
311 ///
312 /// # Returns
313 ///
314 /// - Returns a positive number of array length on success
315 /// - Returns a negative error code on failure. The list of error codes is defined in
316 /// ../core/error_codes.rs
317 ///
318 /// # Safety
319 /// This function is safe to call from WASM context
320 unsafe fn get_tx_array_len(&self, field: i32) -> i32;
321
322 /// Retrieves the length of an array based on the provided field value.
323 ///
324 /// # Parameters
325 /// - `field` (i32): The integer identifier for the desired field.
326 ///
327 /// # Returns
328 ///
329 /// - Returns a positive number of array length on success
330 /// - Returns a negative error code on failure. The list of error codes is defined in
331 /// ../core/error_codes.rs
332 ///
333 /// # Safety
334 /// This function is safe to call from WASM context
335 unsafe fn get_current_ledger_obj_array_len(&self, field: i32) -> i32;
336
337 /// Retrieves the length of an array based on the provided cache number and field value.
338 ///
339 /// # Parameters
340 /// - `cache_num`: The cache index of the ledger object to access.
341 /// - `field` (i32): The integer identifier for the desired field.
342 ///
343 /// # Returns
344 ///
345 /// - Returns a positive number of array length on success
346 /// - Returns a negative error code on failure. The list of error codes is defined in
347 /// ../core/error_codes.rs
348 ///
349 /// # Safety
350 /// This function is safe to call from WASM context
351 unsafe fn get_ledger_obj_array_len(&self, cache_num: i32, field: i32) -> i32;
352
353 /// Retrieves the length of an array based on the provided locator.
354 ///
355 /// # Parameters
356 /// - `locator_ptr`: A pointer to a byte array containing the locator for the nested field.
357 /// - `locator_len`: The length of the locator data in bytes.
358 ///
359 /// # Returns
360 ///
361 /// - Returns a positive number of array length on success
362 /// - Returns a negative error code on failure. The list of error codes is defined in
363 /// ../core/error_codes.rs
364 ///
365 /// # Safety
366 /// Caller must ensure all pointer parameters point to valid memory
367 unsafe fn get_tx_nested_array_len(&self, locator_ptr: *const u8, locator_len: usize) -> i32;
368
369 /// Retrieves the length of an array based on the provided locator.
370 ///
371 /// # Parameters
372 /// - `locator_ptr`: A pointer to a byte array containing the locator for the nested field.
373 /// - `locator_len`: The length of the locator data in bytes.
374 ///
375 /// # Returns
376 ///
377 /// - Returns a positive number of array length on success
378 /// - Returns a negative error code on failure. The list of error codes is defined in
379 /// ../core/error_codes.rs
380 ///
381 /// # Safety
382 /// Caller must ensure all pointer parameters point to valid memory
383 unsafe fn get_current_ledger_obj_nested_array_len(
384 &self,
385 locator_ptr: *const u8,
386 locator_len: usize,
387 ) -> i32;
388
389 /// Retrieves the length of an array based on the provided locator.
390 ///
391 /// # Parameters
392 /// - `cache_num`: The cache index of the ledger object to access.
393 /// - `locator_ptr`: A pointer to a byte array containing the locator for the nested field.
394 /// - `locator_len`: The length of the locator data in bytes.
395 ///
396 /// # Returns
397 ///
398 /// - Returns a positive number of array length on success
399 /// - Returns a negative error code on failure. The list of error codes is defined in
400 /// ../core/error_codes.rs
401 ///
402 /// # Safety
403 /// Caller must ensure all pointer parameters point to valid memory
404 unsafe fn get_ledger_obj_nested_array_len(
405 &self,
406 cache_num: i32,
407 locator_ptr: *const u8,
408 locator_len: usize,
409 ) -> i32;
410
411 // ###################################################
412 // Host Function Category: update current ledger entry
413 // ###################################################
414
415 /// Updates a data field of the current ledger entry
416 ///
417 /// # Parameters
418 ///
419 /// - `data_ptr`: A pointer to the data to be written.
420 /// - `data_len`: The size of the data.
421 ///
422 /// # Returns
423 ///
424 /// - 0 on success
425 /// - negative for an error
426 ///
427 /// # Safety
428 /// Caller must ensure all pointer parameters point to valid memory
429 unsafe fn update_data(&self, data_ptr: *const u8, data_len: usize) -> i32;
430
431 // ###################################################
432 // Host Function Category: hash and keylet computation
433 // ###################################################
434
435 /// Computes the first 32 bytes (half) of the SHA-512 hash for the given input data.
436 ///
437 /// # Parameters
438 ///
439 /// - `data_ptr`: A pointer to the input data to be hashed.
440 /// - `data_len`: The length, in bytes, of the input data.
441 /// - `out_buff_ptr`: A pointer to the buffer where the resulting 32-byte hash will be written.
442 /// - `out_buff_len`: The length, in bytes, of the output buffer.
443 ///
444 /// # Returns
445 ///
446 /// - Returns a positive number of bytes wrote to an output buffer on success
447 /// - Returns a negative error code on failure. The list of error codes is defined in
448 /// ../core/error_codes.rs
449 ///
450 /// # Safety
451 /// Caller must ensure all pointer parameters point to valid memory
452 unsafe fn compute_sha512_half(
453 &self,
454 data_ptr: *const u8,
455 data_len: usize,
456 out_buff_ptr: *mut u8,
457 out_buff_len: usize,
458 ) -> i32;
459
460 /// Checks a key signature when provided the message and public key.
461 ///
462 /// # Parameters
463 /// - `message_ptr`: A pointer to the message data to be verified.
464 /// - `message_len`: The length, in bytes, of the message data.
465 /// - `signature_ptr`: A pointer to the signature data.
466 /// - `signature_len`: The length, in bytes, of the signature data.
467 /// - `pubkey_ptr`: A pointer to the public key data.
468 /// - `pubkey_len`: The length, in bytes, of the public key data.
469 ///
470 /// # Returns
471 ///
472 /// - Returns 1 if the signature is valid.
473 /// - Returns 0 if the signature is invalid.
474 /// - Returns a negative error code on failure. The list of error codes is defined in
475 /// ../core/error_codes.rs
476 ///
477 /// # Safety
478 /// Caller must ensure all pointer parameters point to valid memory
479 unsafe fn check_sig(
480 &self,
481 message_ptr: *const u8,
482 message_len: usize,
483 signature_ptr: *const u8,
484 signature_len: usize,
485 pubkey_ptr: *const u8,
486 pubkey_len: usize,
487 ) -> i32;
488
489 /// Generates the keylet (key identifier) for a specific account.
490 ///
491 /// This function is used to calculate the account keylet in a cryptographic or
492 /// blockchain-based system. A keylet is typically used to identify an account or entity
493 /// in a secure and deterministic way.
494 ///
495 /// # Parameters
496 ///
497 /// - `account_ptr`: A pointer to the memory of the account identifier.
498 /// - `account_len`: The size (in bytes) of the data pointed to by `account_ptr`.
499 /// - `out_buff_ptr`: A pointer to the memory where the generated keylet will be stored.
500 /// - `out_buff_len`: The length (in bytes) of the buffer pointed to by `out_buff_ptr`.
501 ///
502 /// # Returns
503 ///
504 /// - Returns a positive number of bytes wrote to an output buffer on success
505 /// - Returns a negative error code on failure. The list of error codes is defined in
506 /// `../core/error_codes.rs`
507 ///
508 /// # Safety
509 /// Caller must ensure all pointer parameters point to valid memory
510 unsafe fn account_keylet(
511 &self,
512 account_ptr: *const u8,
513 account_len: usize,
514 out_buff_ptr: *mut u8,
515 out_buff_len: usize,
516 ) -> i32;
517
518 /// Generates the keylet (key identifier) for a specific AMM.
519 ///
520 /// This function is used to calculate the AMM keylet in a cryptographic or
521 /// blockchain-based system. A keylet is typically used to identify an AMM or entity
522 /// in a secure and deterministic way.
523 ///
524 /// # Parameters
525 ///
526 /// - `issue1_ptr`: A pointer to the memory of the issue1 identifier.
527 /// - `issue1_len`: The size (in bytes) of the data pointed to by `issue1_ptr`.
528 /// - `issue2_ptr`: A pointer to the memory of the issue2 identifier.
529 /// - `issue2_len`: The size (in bytes) of the data pointed to by `issue2_ptr`.
530 /// - `out_buff_ptr`: A pointer to the memory where the generated keylet will be stored.
531 /// - `out_buff_len`: The length (in bytes) of the buffer pointed to by `out_buff_ptr`.
532 ///
533 /// # Returns
534 ///
535 /// - Returns a positive number of bytes wrote to an output buffer on success
536 /// - Returns a negative error code on failure. The list of error codes is defined in
537 /// `../core/error_codes.rs`
538 ///
539 /// # Safety
540 /// Caller must ensure all pointer parameters point to valid memory
541 unsafe fn amm_keylet(
542 &self,
543 issue1_ptr: *const u8,
544 issue1_len: usize,
545 issue2_ptr: *const u8,
546 issue2_len: usize,
547 out_buff_ptr: *mut u8,
548 out_buff_len: usize,
549 ) -> i32;
550
551 /// Computes the Keylet for a check entry in a ledger.
552 ///
553 /// # Parameters
554 ///
555 /// - `account_ptr`: A pointer to the memory location of the accountID.
556 /// - `account_len`: The length of the accountID.
557 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
558 /// - `sequence_len`: The length of the sequence data.
559 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
560 /// - `out_buff_len`: The length of the output buffer.
561 ///
562 /// # Returns
563 ///
564 /// - Returns a positive number of bytes wrote to an output buffer on success
565 /// - Returns a negative error code on failure. The list of error codes is defined in
566 /// ../core/error_codes.rs
567 ///
568 /// # Safety
569 /// Caller must ensure all pointer parameters point to valid memory
570 unsafe fn check_keylet(
571 &self,
572 account_ptr: *const u8,
573 account_len: usize,
574 sequence_ptr: *const u8,
575 sequence_len: usize,
576 out_buff_ptr: *mut u8,
577 out_buff_len: usize,
578 ) -> i32;
579
580 /// Generates a keylet for a credential.
581 ///
582 /// # Parameters
583 ///
584 /// * `subject_ptr`: A pointer to the memory location where the subject data begins.
585 /// * `subject_len`: The length of the subject data in bytes.
586 /// * `issuer_ptr`: A pointer to the memory location where the issuer data begins.
587 /// * `issuer_len`: The length of the issuer data in bytes.
588 /// * `cred_type_ptr`: A pointer to the memory location where the credential type data begins.
589 /// * `cred_type_len`: The length of the credential type data in bytes.
590 /// * `out_buff_ptr`: A pointer to the buffer where the generated keylet will be written.
591 /// * `out_buff_len`: The size of the output buffer in bytes.
592 ///
593 /// # Returns
594 ///
595 /// - Returns a positive number of bytes wrote to an output buffer on success
596 /// - Returns a negative error code on failure. The list of error codes is defined in
597 /// `../core/error_codes.rs`
598 ///
599 /// # Safety
600 /// Caller must ensure all pointer parameters point to valid memory
601 #[allow(clippy::too_many_arguments)]
602 unsafe fn credential_keylet(
603 &self,
604 subject_ptr: *const u8,
605 subject_len: usize,
606 issuer_ptr: *const u8,
607 issuer_len: usize,
608 cred_type_ptr: *const u8,
609 cred_type_len: usize,
610 out_buff_ptr: *mut u8,
611 out_buff_len: usize,
612 ) -> i32;
613
614 /// Computes the Keylet for a delegate entry in a ledger.
615 ///
616 /// # Parameters
617 ///
618 /// - `account_ptr`: A pointer to the memory location of the accountID.
619 /// - `account_len`: The length of the accountID.
620 /// - `authorize_ptr`: A pointer to the memory location of the authorized account.
621 /// - `authorize_len`: The length of the authorized account.
622 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
623 /// - `out_buff_len`: The length of the output buffer.
624 ///
625 /// # Returns
626 ///
627 /// - Returns a positive number of bytes wrote to an output buffer on success
628 /// - Returns a negative error code on failure. The list of error codes is defined in
629 /// ../core/error_codes.rs
630 ///
631 /// # Safety
632 /// Caller must ensure all pointer parameters point to valid memory
633 unsafe fn delegate_keylet(
634 &self,
635 account_ptr: *const u8,
636 account_len: usize,
637 authorize_ptr: *const u8,
638 authorize_len: usize,
639 out_buff_ptr: *mut u8,
640 out_buff_len: usize,
641 ) -> i32;
642
643 /// Computes the Keylet for a deposit preauth entry in a ledger.
644 ///
645 /// # Parameters
646 ///
647 /// - `account_ptr`: A pointer to the memory location of the accountID.
648 /// - `account_len`: The length of the accountID.
649 /// - `authorize_ptr`: A pointer to the memory location of the authorized account.
650 /// - `authorize_len`: The length of the authorized account.
651 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
652 /// - `out_buff_len`: The length of the output buffer.
653 ///
654 /// # Returns
655 ///
656 /// - Returns a positive number of bytes wrote to an output buffer on success
657 /// - Returns a negative error code on failure. The list of error codes is defined in
658 /// ../core/error_codes.rs
659 ///
660 /// # Safety
661 /// Caller must ensure all pointer parameters point to valid memory
662 unsafe fn deposit_preauth_keylet(
663 &self,
664 account_ptr: *const u8,
665 account_len: usize,
666 authorize_ptr: *const u8,
667 authorize_len: usize,
668 out_buff_ptr: *mut u8,
669 out_buff_len: usize,
670 ) -> i32;
671
672 /// Computes the Keylet for a DID entry in a ledger.
673 ///
674 /// # Parameters
675 ///
676 /// - `account_ptr`: A pointer to the memory location of the accountID.
677 /// - `account_len`: The length of the accountID.
678 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
679 /// - `out_buff_len`: The length of the output buffer.
680 ///
681 /// # Returns
682 ///
683 /// - Returns a positive number of bytes wrote to an output buffer on success
684 /// - Returns a negative error code on failure. The list of error codes is defined in
685 /// ../core/error_codes.rs
686 ///
687 /// # Safety
688 /// Caller must ensure all pointer parameters point to valid memory
689 unsafe fn did_keylet(
690 &self,
691 account_ptr: *const u8,
692 account_len: usize,
693 out_buff_ptr: *mut u8,
694 out_buff_len: usize,
695 ) -> i32;
696
697 /// Computes the Keylet for an escrow entry in a ledger.
698 ///
699 /// # Parameters
700 ///
701 /// - `account_ptr`: A pointer to the memory location of the accountID.
702 /// - `account_len`: The length of the accountID.
703 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
704 /// - `sequence_len`: The length of the sequence data.
705 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
706 /// - `out_buff_len`: The length of the output buffer.
707 ///
708 /// # Returns
709 ///
710 /// - Returns a positive number of bytes wrote to an output buffer on success
711 /// - Returns a negative error code on failure. The list of error codes is defined in
712 /// `../core/error_codes.rs`
713 ///
714 /// # Safety
715 /// Caller must ensure all pointer parameters point to valid memory
716 unsafe fn escrow_keylet(
717 &self,
718 account_ptr: *const u8,
719 account_len: usize,
720 sequence_ptr: *const u8,
721 sequence_len: usize,
722 out_buff_ptr: *mut u8,
723 out_buff_len: usize,
724 ) -> i32;
725
726 /// Computes the Keylet for a trustline entry in a ledger.
727 ///
728 /// # Parameters
729 ///
730 /// - `account1_ptr`: A pointer to the memory location of the first accountID.
731 /// - `account1_len`: The length of the first accountID.
732 /// - `account2_ptr`: A pointer to the memory location of the second accountID.
733 /// - `account2_len`: The length of the second accountID.
734 /// - `currency_ptr`: A pointer to the memory location of the currency.
735 /// - `currency_len`: The length of the currency.
736 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
737 /// - `out_buff_len`: The length of the output buffer.
738 ///
739 /// # Returns
740 ///
741 /// - Returns a positive number of bytes wrote to an output buffer on success
742 /// - Returns a negative error code on failure. The list of error codes is defined in
743 /// ../core/error_codes.rs
744 ///
745 /// # Safety
746 /// Caller must ensure all pointer parameters point to valid memory
747 #[allow(clippy::too_many_arguments)]
748 unsafe fn line_keylet(
749 &self,
750 account1_ptr: *const u8,
751 account1_len: usize,
752 account2_ptr: *const u8,
753 account2_len: usize,
754 currency_ptr: *const u8,
755 currency_len: usize,
756 out_buff_ptr: *mut u8,
757 out_buff_len: usize,
758 ) -> i32;
759
760 /// Computes the Keylet for an MPT issuance entry in a ledger.
761 ///
762 /// # Parameters
763 ///
764 /// - `issuer_ptr`: A pointer to the memory location of the accountID.
765 /// - `issuer_len`: The length of the accountID.
766 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
767 /// - `sequence_len`: The length of the sequence data.
768 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
769 /// - `out_buff_len`: The length of the output buffer.
770 ///
771 /// # Returns
772 ///
773 /// - Returns a positive number of bytes wrote to an output buffer on success
774 /// - Returns a negative error code on failure. The list of error codes is defined in
775 /// `../core/error_codes.rs`
776 ///
777 /// # Safety
778 /// Caller must ensure all pointer parameters point to valid memory
779 unsafe fn mpt_issuance_keylet(
780 &self,
781 issuer_ptr: *const u8,
782 issuer_len: usize,
783 sequence_ptr: *const u8,
784 sequence_len: usize,
785 out_buff_ptr: *mut u8,
786 out_buff_len: usize,
787 ) -> i32;
788
789 /// Computes the Keylet for an MPToken entry in a ledger.
790 ///
791 /// # Parameters
792 ///
793 /// - `mptid_ptr`: A pointer to the memory location of the MPTID.
794 /// - `mptid_len`: The length of the MPTID.
795 /// - `holder_ptr`: A pointer to the memory location of the holder account.
796 /// - `holder_len`: The length of the holder account.
797 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
798 /// - `out_buff_len`: The length of the output buffer.
799 ///
800 /// # Returns
801 ///
802 /// - Returns a positive number of bytes wrote to an output buffer on success
803 /// - Returns a negative error code on failure. The list of error codes is defined in
804 /// ../core/error_codes.rs
805 ///
806 /// # Safety
807 /// Caller must ensure all pointer parameters point to valid memory
808 unsafe fn mptoken_keylet(
809 &self,
810 mptid_ptr: *const u8,
811 mptid_len: usize,
812 holder_ptr: *const u8,
813 holder_len: usize,
814 out_buff_ptr: *mut u8,
815 out_buff_len: usize,
816 ) -> i32;
817
818 /// Computes the Keylet for an NFT offer entry in a ledger.
819 ///
820 /// # Parameters
821 ///
822 /// - `account_ptr`: A pointer to the memory location of the accountID.
823 /// - `account_len`: The length of the accountID.
824 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
825 /// - `sequence_len`: The length of the sequence data.
826 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
827 /// - `out_buff_len`: The length of the output buffer.
828 ///
829 /// # Returns
830 ///
831 /// - Returns a positive number of bytes wrote to an output buffer on success
832 /// - Returns a negative error code on failure. The list of error codes is defined in
833 /// ../core/error_codes.rs
834 ///
835 /// # Safety
836 /// Caller must ensure all pointer parameters point to valid memory
837 unsafe fn nft_offer_keylet(
838 &self,
839 account_ptr: *const u8,
840 account_len: usize,
841 sequence_ptr: *const u8,
842 sequence_len: usize,
843 out_buff_ptr: *mut u8,
844 out_buff_len: usize,
845 ) -> i32;
846
847 /// Computes the Keylet for an offer entry in a ledger.
848 ///
849 /// # Parameters
850 ///
851 /// - `account_ptr`: A pointer to the memory location of the accountID.
852 /// - `account_len`: The length of the accountID.
853 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
854 /// - `sequence_len`: The length of the sequence data.
855 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
856 /// - `out_buff_len`: The length of the output buffer.
857 ///
858 /// # Returns
859 ///
860 /// - Returns a positive number of bytes wrote to an output buffer on success
861 /// - Returns a negative error code on failure. The list of error codes is defined in
862 /// ../core/error_codes.rs
863 ///
864 /// # Safety
865 /// Caller must ensure all pointer parameters point to valid memory
866 unsafe fn offer_keylet(
867 &self,
868 account_ptr: *const u8,
869 account_len: usize,
870 sequence_ptr: *const u8,
871 sequence_len: usize,
872 out_buff_ptr: *mut u8,
873 out_buff_len: usize,
874 ) -> i32;
875
876 /// Generates a keylet associated with an oracle's account and document ID.
877 ///
878 /// # Parameters
879 ///
880 /// - `account_ptr`: A pointer to the memory location of the accountID.
881 /// - `account_len`: The length of the accountID.
882 /// - `document_id_ptr`: A pointer to the memory location of the document ID.
883 /// - `document_id_len`: The length of the document ID data.
884 /// - `out_buff_ptr`: A pointer to a pre-allocated buffer where the resulting keylet will be
885 /// written.
886 /// - `out_buff_len`: The size of the output buffer in bytes.
887 ///
888 /// # Returns
889 ///
890 /// - Returns a positive number of bytes wrote to an output buffer on success
891 /// - Returns a negative error code on failure. The list of error codes is defined in
892 /// `../core/error_codes.rs`
893 ///
894 /// # Safety
895 /// Caller must ensure all pointer parameters point to valid memory
896 unsafe fn oracle_keylet(
897 &self,
898 account_ptr: *const u8,
899 account_len: usize,
900 document_id_ptr: *const u8,
901 document_id_len: usize,
902 out_buff_ptr: *mut u8,
903 out_buff_len: usize,
904 ) -> i32;
905
906 /// Computes the Keylet for a payment channel entry in a ledger.
907 ///
908 /// # Parameters
909 ///
910 /// - `account_ptr`: A pointer to the memory location of the accountID.
911 /// - `account_len`: The length of the accountID.
912 /// - `destination_ptr`: A pointer to the memory location of the destination.
913 /// - `destination_len`: The length of the destination.
914 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
915 /// - `sequence_len`: The length of the sequence data.
916 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
917 /// - `out_buff_len`: The length of the output buffer.
918 ///
919 /// # Returns
920 ///
921 /// - Returns a positive number of bytes wrote to an output buffer on success
922 /// - Returns a negative error code on failure. The list of error codes is defined in
923 /// ../core/error_codes.rs
924 ///
925 /// # Safety
926 /// Caller must ensure all pointer parameters point to valid memory
927 #[allow(clippy::too_many_arguments)]
928 unsafe fn paychan_keylet(
929 &self,
930 account_ptr: *const u8,
931 account_len: usize,
932 destination_ptr: *const u8,
933 destination_len: usize,
934 sequence_ptr: *const u8,
935 sequence_len: usize,
936 out_buff_ptr: *mut u8,
937 out_buff_len: usize,
938 ) -> i32;
939
940 /// Computes the Keylet for a permissioned domain entry in a ledger.
941 ///
942 /// # Parameters
943 ///
944 /// - `account_ptr`: A pointer to the memory location of the accountID.
945 /// - `account_len`: The length of the accountID.
946 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
947 /// - `sequence_len`: The length of the sequence data.
948 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
949 /// - `out_buff_len`: The length of the output buffer.
950 ///
951 /// # Returns
952 ///
953 /// - Returns a positive number of bytes wrote to an output buffer on success
954 /// - Returns a negative error code on failure. The list of error codes is defined in
955 /// ../core/error_codes.rs
956 ///
957 /// # Safety
958 /// Caller must ensure all pointer parameters point to valid memory
959 unsafe fn permissioned_domain_keylet(
960 &self,
961 account_ptr: *const u8,
962 account_len: usize,
963 sequence_ptr: *const u8,
964 sequence_len: usize,
965 out_buff_ptr: *mut u8,
966 out_buff_len: usize,
967 ) -> i32;
968
969 /// Computes the Keylet for a signer entry in a ledger.
970 ///
971 /// # Parameters
972 ///
973 /// - `account_ptr`: A pointer to the memory location of the accountID.
974 /// - `account_len`: The length of the accountID.
975 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
976 /// - `out_buff_len`: The length of the output buffer.
977 ///
978 /// # Returns
979 ///
980 /// - Returns a positive number of bytes wrote to an output buffer on success
981 /// - Returns a negative error code on failure. The list of error codes is defined in
982 /// ../core/error_codes.rs
983 ///
984 /// # Safety
985 /// Caller must ensure all pointer parameters point to valid memory
986 unsafe fn signers_keylet(
987 &self,
988 account_ptr: *const u8,
989 account_len: usize,
990 out_buff_ptr: *mut u8,
991 out_buff_len: usize,
992 ) -> i32;
993
994 /// Computes the Keylet for a ticket entry in a ledger.
995 ///
996 /// # Parameters
997 ///
998 /// - `account_ptr`: A pointer to the memory location of the accountID.
999 /// - `account_len`: The length of the accountID.
1000 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
1001 /// - `sequence_len`: The length of the sequence data.
1002 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
1003 /// - `out_buff_len`: The length of the output buffer.
1004 ///
1005 /// # Returns
1006 ///
1007 /// - Returns a positive number of bytes wrote to an output buffer on success
1008 /// - Returns a negative error code on failure. The list of error codes is defined in
1009 /// ../core/error_codes.rs
1010 ///
1011 /// # Safety
1012 /// Caller must ensure all pointer parameters point to valid memory
1013 unsafe fn ticket_keylet(
1014 &self,
1015 account_ptr: *const u8,
1016 account_len: usize,
1017 sequence_ptr: *const u8,
1018 sequence_len: usize,
1019 out_buff_ptr: *mut u8,
1020 out_buff_len: usize,
1021 ) -> i32;
1022
1023 /// Computes the Keylet for a vault entry in a ledger.
1024 ///
1025 /// # Parameters
1026 ///
1027 /// - `account_ptr`: A pointer to the memory location of the accountID.
1028 /// - `account_len`: The length of the accountID.
1029 /// - `sequence_ptr`: A pointer to the memory location of the account sequence number.
1030 /// - `sequence_len`: The length of the sequence data.
1031 /// - `out_buff_ptr`: A pointer to the output buffer where the derived keylet will be stored.
1032 /// - `out_buff_len`: The length of the output buffer.
1033 ///
1034 /// # Returns
1035 ///
1036 /// - Returns a positive number of bytes wrote to an output buffer on success
1037 /// - Returns a negative error code on failure. The list of error codes is defined in
1038 /// ../core/error_codes.rs
1039 ///
1040 /// # Safety
1041 /// Caller must ensure all pointer parameters point to valid memory
1042 unsafe fn vault_keylet(
1043 &self,
1044 account_ptr: *const u8,
1045 account_len: usize,
1046 sequence_ptr: *const u8,
1047 sequence_len: usize,
1048 out_buff_ptr: *mut u8,
1049 out_buff_len: usize,
1050 ) -> i32;
1051
1052 // #############################
1053 // Host Function Category: NFT
1054 // #############################
1055
1056 /// Retrieves the URI details of a specific NFT (Non-Fungible Token) associated with a given account.
1057 ///
1058 /// # Parameters
1059 ///
1060 /// - `account_ptr`: A pointer to the memory location of the accountID.
1061 /// - `account_len`: The length of the accountID.
1062 /// - `nft_id_ptr`: A pointer to the memory location containing the NFT identifier.
1063 /// - `nft_id_len`: The length of the NFT identifier in bytes.
1064 /// - `out_buff_ptr`: A mutable pointer to the memory location where the retrieved NFT URI
1065 /// will be written.
1066 /// - `out_buff_len`: The maximum length of the output buffer.
1067 ///
1068 /// # Returns
1069 ///
1070 /// - Returns a positive number of bytes wrote to an output buffer on success
1071 /// - Returns a negative error code on failure. The list of error codes is defined in
1072 /// `../core/error_codes.rs`
1073 ///
1074 /// # Safety
1075 /// Caller must ensure all pointer parameters point to valid memory
1076 unsafe fn get_nft(
1077 &self,
1078 account_ptr: *const u8,
1079 account_len: usize,
1080 nft_id_ptr: *const u8,
1081 nft_id_len: usize,
1082 out_buff_ptr: *mut u8,
1083 out_buff_len: usize,
1084 ) -> i32;
1085
1086 /// Retrieves the issuer of a specific NFT (Non-Fungible Token).
1087 ///
1088 /// # Parameters
1089 ///
1090 /// - `nft_id_ptr`: A pointer to the memory location containing the NFT identifier.
1091 /// - `nft_id_len`: The length of the NFT identifier in bytes.
1092 /// - `out_buff_ptr`: A mutable pointer to the memory location where the retrieved issuer
1093 /// account will be written.
1094 /// - `out_buff_len`: The maximum length of the output buffer.
1095 ///
1096 /// # Returns
1097 ///
1098 /// - Returns a positive number of bytes wrote to an output buffer on success
1099 /// - Returns a negative error code on failure. The list of error codes is defined in
1100 /// ../core/error_codes.rs
1101 ///
1102 /// # Safety
1103 /// Caller must ensure all pointer parameters point to valid memory
1104 unsafe fn get_nft_issuer(
1105 &self,
1106 nft_id_ptr: *const u8,
1107 nft_id_len: usize,
1108 out_buff_ptr: *mut u8,
1109 out_buff_len: usize,
1110 ) -> i32;
1111
1112 /// Retrieves the taxon of a specific NFT (Non-Fungible Token).
1113 ///
1114 /// # Parameters
1115 ///
1116 /// - `nft_id_ptr`: A pointer to the memory location containing the NFT identifier.
1117 /// - `nft_id_len`: The length of the NFT identifier in bytes.
1118 /// - `out_buff_ptr`: A mutable pointer to the memory location where the retrieved taxon
1119 /// will be written.
1120 /// - `out_buff_len`: The maximum length of the output buffer.
1121 ///
1122 /// # Returns
1123 ///
1124 /// - Returns a positive number of bytes wrote to an output buffer on success
1125 /// - Returns a negative error code on failure. The list of error codes is defined in
1126 /// ../core/error_codes.rs
1127 ///
1128 /// # Safety
1129 /// Caller must ensure all pointer parameters point to valid memory
1130 unsafe fn get_nft_taxon(
1131 &self,
1132 nft_id_ptr: *const u8,
1133 nft_id_len: usize,
1134 out_buff_ptr: *mut u8,
1135 out_buff_len: usize,
1136 ) -> i32;
1137
1138 /// Retrieves the flags of a specific NFT (Non-Fungible Token).
1139 ///
1140 /// # Parameters
1141 ///
1142 /// - `nft_id_ptr`: A pointer to the memory location containing the NFT identifier.
1143 /// - `nft_id_len`: The length of the NFT identifier in bytes.
1144 ///
1145 /// # Returns
1146 ///
1147 /// - Returns a positive flags value on success, which is a bitmask representing the NFT's flags
1148 /// - Returns a negative error code on failure. The list of error codes is defined in
1149 /// ../core/error_codes.rs
1150 ///
1151 /// # Safety
1152 /// Caller must ensure all pointer parameters point to valid memory
1153 unsafe fn get_nft_flags(&self, nft_id_ptr: *const u8, nft_id_len: usize) -> i32;
1154
1155 /// Retrieves the transfer fee of a specific NFT (Non-Fungible Token).
1156 ///
1157 /// # Parameters
1158 ///
1159 /// - `nft_id_ptr`: A pointer to the memory location containing the NFT identifier.
1160 /// - `nft_id_len`: The length of the NFT identifier in bytes.
1161 ///
1162 /// # Returns
1163 ///
1164 /// - Returns a positive transfer fee value on success
1165 /// - Returns a negative error code on failure. The list of error codes is defined in
1166 /// ../core/error_codes.rs
1167 ///
1168 /// # Safety
1169 /// Caller must ensure all pointer parameters point to valid memory
1170 unsafe fn get_nft_transfer_fee(&self, nft_id_ptr: *const u8, nft_id_len: usize) -> i32;
1171
1172 /// Retrieves the serial number of a specific NFT (Non-Fungible Token).
1173 ///
1174 /// # Parameters
1175 ///
1176 /// - `nft_id_ptr`: A pointer to the memory location containing the NFT identifier.
1177 /// - `nft_id_len`: The length of the NFT identifier in bytes.
1178 /// - `out_buff_ptr`: A mutable pointer to the memory location where the retrieved serial
1179 /// number will be written.
1180 /// - `out_buff_len`: The maximum length of the output buffer.
1181 ///
1182 /// # Returns
1183 ///
1184 /// - Returns a positive number of bytes wrote to an output buffer on success
1185 /// - Returns a negative error code on failure. The list of error codes is defined in
1186 /// ../core/error_codes.rs
1187 ///
1188 /// # Safety
1189 /// Caller must ensure all pointer parameters point to valid memory
1190 unsafe fn get_nft_serial(
1191 &self,
1192 nft_id_ptr: *const u8,
1193 nft_id_len: usize,
1194 out_buff_ptr: *mut u8,
1195 out_buff_len: usize,
1196 ) -> i32;
1197
1198 // #############################
1199 // Host Function Category: FLOAT
1200 // #############################
1201
1202 /// Converts a signed 64-bit integer to an opaque float representation
1203 /// # Parameters
1204 /// * `in_int` - The input integer to convert
1205 /// * `out_buff` - Pointer to output buffer where the float will be written
1206 /// * `out_buff_len` - The length of the output buffer in bytes
1207 /// * `rounding_mode` - Rounding mode to use for the conversion
1208 /// # Returns
1209 /// 8 on success, error code otherwise
1210 ///
1211 /// # Safety
1212 /// Caller must ensure all pointer parameters point to valid memory
1213 unsafe fn float_from_int(
1214 &self,
1215 in_int: i64,
1216 out_buff: *mut u8,
1217 out_buff_len: usize,
1218 rounding_mode: i32,
1219 ) -> i32;
1220
1221 /// Converts an unsigned integer to an opaque float representation
1222 /// # Parameters
1223 /// * `in_uint_ptr` - Pointer to the input unsigned integer
1224 /// * `in_uint_len` - The length of the input unsigned integer in bytes
1225 /// * `out_buff` - Pointer to output buffer where the float will be written
1226 /// * `out_buff_len` - The length of the output buffer in bytes
1227 /// * `rounding_mode` - Rounding mode to use for the conversion
1228 /// # Returns
1229 /// 8 on success, error code otherwise
1230 ///
1231 /// # Safety
1232 /// Caller must ensure all pointer parameters point to valid memory
1233 unsafe fn float_from_uint(
1234 &self,
1235 in_uint_ptr: *const u8,
1236 in_uint_len: usize,
1237 out_buff: *mut u8,
1238 out_buff_len: usize,
1239 rounding_mode: i32,
1240 ) -> i32;
1241
1242 /// Creates a float from explicit exponent and mantissa values
1243 /// # Parameters
1244 /// * `exponent` - The exponent value
1245 /// * `mantissa` - The mantissa value
1246 /// * `out_buff` - Pointer to output buffer where the float will be written
1247 /// * `out_buff_len` - The length of the output buffer in bytes
1248 /// * `rounding_mode` - Rounding mode to use for the operation
1249 /// # Returns
1250 /// 8 on success, error code otherwise
1251 ///
1252 /// # Safety
1253 /// Caller must ensure all pointer parameters point to valid memory
1254 unsafe fn float_set(
1255 &self,
1256 exponent: i32,
1257 mantissa: i64,
1258 out_buff: *mut u8,
1259 out_buff_len: usize,
1260 rounding_mode: i32,
1261 ) -> i32;
1262
1263 /// Compares two opaque float values
1264 /// # Parameters
1265 /// * `in_buff1` - Pointer to first float value
1266 /// * `in_buff1_len` - The length of the first float value in bytes
1267 /// * `in_buff2` - Pointer to second float value
1268 /// * `in_buff2_len` - The length of the second float value in bytes
1269 /// # Returns
1270 /// 0 if equal, 1 if first > second, 2 if first < second,
1271 ///
1272 /// # Safety
1273 /// Caller must ensure all pointer parameters point to valid memory
1274 unsafe fn float_compare(
1275 &self,
1276 in_buff1: *const u8,
1277 in_buff1_len: usize,
1278 in_buff2: *const u8,
1279 in_buff2_len: usize,
1280 ) -> i32;
1281
1282 /// Adds two opaque float values
1283 /// # Parameters
1284 /// * `in_buff1` - Pointer to first float value
1285 /// * `in_buff1_len` - The length of the first float value in bytes
1286 /// * `in_buff2` - Pointer to second float value
1287 /// * `in_buff2_len` - The length of the second float value in bytes
1288 /// * `out_buff` - Pointer to output buffer where result will be written
1289 /// * `out_buff_len` - The length of the output buffer in bytes
1290 /// * `rounding_mode` - Rounding mode to use for the addition
1291 /// # Returns
1292 /// 8 on success, error code otherwise
1293 ///
1294 /// # Safety
1295 /// Caller must ensure all pointer parameters point to valid memory
1296 #[allow(clippy::too_many_arguments)]
1297 unsafe fn float_add(
1298 &self,
1299 in_buff1: *const u8,
1300 in_buff1_len: usize,
1301 in_buff2: *const u8,
1302 in_buff2_len: usize,
1303 out_buff: *mut u8,
1304 out_buff_len: usize,
1305 rounding_mode: i32,
1306 ) -> i32;
1307
1308 /// Subtracts two opaque float values
1309 /// # Parameters
1310 /// * `in_buff1` - Pointer to first float value
1311 /// * `in_buff1_len` - The length of the first float value in bytes
1312 /// * `in_buff2` - Pointer to second float value
1313 /// * `in_buff2_len` - The length of the second float value in bytes
1314 /// * `out_buff` - Pointer to output buffer where result will be written
1315 /// * `out_buff_len` - The length of the output buffer in bytes
1316 /// * `rounding_mode` - Rounding mode to use for the subtraction
1317 /// # Returns
1318 /// 8 on success, error code otherwise
1319 ///
1320 /// # Safety
1321 /// Caller must ensure all pointer parameters point to valid memory
1322 #[allow(clippy::too_many_arguments)]
1323 unsafe fn float_subtract(
1324 &self,
1325 in_buff1: *const u8,
1326 in_buff1_len: usize,
1327 in_buff2: *const u8,
1328 in_buff2_len: usize,
1329 out_buff: *mut u8,
1330 out_buff_len: usize,
1331 rounding_mode: i32,
1332 ) -> i32;
1333
1334 /// Multiplies two opaque float values
1335 /// # Parameters
1336 /// * `in_buff1` - Pointer to first float value
1337 /// * `in_buff1_len` - The length of the first float value in bytes
1338 /// * `in_buff2` - Pointer to second float value
1339 /// * `in_buff2_len` - The length of the second float value in bytes
1340 /// * `out_buff` - Pointer to output buffer where result will be written
1341 /// * `out_buff_len` - The length of the output buffer in bytes
1342 /// * `rounding_mode` - Rounding mode to use for the multiplication
1343 /// # Returns
1344 /// 8 on success, error code otherwise
1345 ///
1346 /// # Safety
1347 /// Caller must ensure all pointer parameters point to valid memory
1348 #[allow(clippy::too_many_arguments)]
1349 unsafe fn float_multiply(
1350 &self,
1351 in_buff1: *const u8,
1352 in_buff1_len: usize,
1353 in_buff2: *const u8,
1354 in_buff2_len: usize,
1355 out_buff: *mut u8,
1356 out_buff_len: usize,
1357 rounding_mode: i32,
1358 ) -> i32;
1359
1360 /// Divides two opaque float values
1361 /// # Parameters
1362 /// * `in_buff1` - Pointer to dividend float value
1363 /// * `in_buff1_len` - The length of the dividend float value in bytes
1364 /// * `in_buff2` - Pointer to divisor float value
1365 /// * `in_buff2_len` - The length of the divisor float value in bytes
1366 /// * `out_buff` - Pointer to output buffer where result will be written
1367 /// * `out_buff_len` - The length of the output buffer in bytes
1368 /// * `rounding_mode` - Rounding mode to use for the division
1369 /// # Returns
1370 /// 8 on success, error code otherwise
1371 ///
1372 /// # Safety
1373 /// Caller must ensure all pointer parameters point to valid memory
1374 #[allow(clippy::too_many_arguments)]
1375 unsafe fn float_divide(
1376 &self,
1377 in_buff1: *const u8,
1378 in_buff1_len: usize,
1379 in_buff2: *const u8,
1380 in_buff2_len: usize,
1381 out_buff: *mut u8,
1382 out_buff_len: usize,
1383 rounding_mode: i32,
1384 ) -> i32;
1385
1386 /// Calculates the nth power of an opaque float value
1387 /// # Parameters
1388 /// * `in_buff` - Pointer to input float value
1389 /// * `in_buff_len` - The length of the input float value in bytes
1390 /// * `pow` - The power to calculate (e.g., 2 for square)
1391 /// * `out_buff` - Pointer to output buffer where result will be written
1392 /// * `out_buff_len` - The length of the output buffer in bytes
1393 /// * `rounding_mode` - Rounding mode to use for the operation
1394 /// # Returns
1395 /// 8 on success, error code otherwise
1396 ///
1397 /// # Safety
1398 /// Caller must ensure all pointer parameters point to valid memory
1399 unsafe fn float_pow(
1400 &self,
1401 in_buff: *const u8,
1402 in_buff_len: usize,
1403 pow: i32,
1404 out_buff: *mut u8,
1405 out_buff_len: usize,
1406 rounding_mode: i32,
1407 ) -> i32;
1408
1409 /// Calculates the nth root of an opaque float value
1410 /// # Parameters
1411 /// * `in_buff` - Pointer to input float value
1412 /// * `in_buff_len` - The length of the input float value in bytes
1413 /// * `root` - The root to calculate (e.g., 2 for square root)
1414 /// * `out_buff` - Pointer to output buffer where result will be written
1415 /// * `out_buff_len` - The length of the output buffer in bytes
1416 /// * `rounding_mode` - Rounding mode to use for the operation
1417 /// # Returns
1418 /// 8 on success, error code otherwise
1419 ///
1420 /// # Safety
1421 /// Caller must ensure all pointer parameters point to valid memory
1422 unsafe fn float_root(
1423 &self,
1424 in_buff: *const u8,
1425 in_buff_len: usize,
1426 root: i32,
1427 out_buff: *mut u8,
1428 out_buff_len: usize,
1429 rounding_mode: i32,
1430 ) -> i32;
1431
1432 /// Calculates the natural logarithm of an opaque float value
1433 /// # Parameters
1434 /// * `in_buff` - Pointer to input float value
1435 /// * `in_buff_len` - The length of the input float value in bytes
1436 /// * `out_buff` - Pointer to output buffer where result will be written
1437 /// * `out_buff_len` - The length of the output buffer in bytes
1438 /// * `rounding_mode` - Rounding mode to use for the operation
1439 /// # Returns
1440 /// 8 on success, error code otherwise
1441 ///
1442 /// # Safety
1443 /// Caller must ensure all pointer parameters point to valid memory
1444 unsafe fn float_log(
1445 &self,
1446 in_buff: *const u8,
1447 in_buff_len: usize,
1448 out_buff: *mut u8,
1449 out_buff_len: usize,
1450 rounding_mode: i32,
1451 ) -> i32;
1452
1453 // #############################
1454 // Host Function Category: TRACE
1455 // #############################
1456
1457 /// Print to the trace log on XRPLd. Any XRPLd instance set to \"trace\" log level will see this.
1458 ///
1459 /// # Parameters
1460 /// - `msg_read_ptr`: A pointer to an array containing text characters (in either utf8).
1461 /// - `msg_read_len`: The byte length of the text to send to the trace log.
1462 /// - `data_read_ptr`: A pointer to an array of bytes containing arbitrary data.
1463 /// - `data_read_len`: The byte length of the data to send to the trace log.
1464 /// - `as_hex`: If 0 treat the data_read_ptr as pointing at a string of text, otherwise treat it
1465 /// as data and print hex.
1466 ///
1467 /// # Returns
1468 ///
1469 /// Returns an integer representing the result of the operation. A value of `0` or higher
1470 /// signifies the number of message bytes that were written to the trace function. Non-zero
1471 /// values indicate an error that corresponds to a known error code (e.g., incorrect buffer
1472 /// sizes).
1473 ///
1474 /// # Safety
1475 /// Caller must ensure all pointer parameters point to valid memory
1476 unsafe fn trace(
1477 &self,
1478 msg_read_ptr: *const u8,
1479 msg_read_len: usize,
1480 data_read_ptr: *const u8,
1481 data_read_len: usize,
1482 as_hex: i32,
1483 ) -> i32;
1484
1485 /// Print a number to the trace log on XRPLd. Any XRPLd instance set to \"trace\" log level will
1486 /// see this.
1487 ///
1488 /// # Parameters
1489 /// * `msg_read_ptr`: A pointer to an array containing text characters (in either utf8).
1490 /// * `msg_read_len`: The byte length of the text to send to the trace log.
1491 /// * `number`: Any integer you wish to display after the text.
1492 ///
1493 /// # Returns
1494 ///
1495 /// Returns an integer representing the result of the operation. A value of `0` or higher
1496 /// signifies the number of message bytes that were written to the trace function. Non-zero
1497 /// values indicate an error that corresponds to a known error code (e.g., incorrect buffer
1498 /// sizes).
1499 ///
1500 /// # Safety
1501 /// Caller must ensure all pointer parameters point to valid memory
1502 unsafe fn trace_num(&self, msg_read_ptr: *const u8, msg_read_len: usize, number: i64) -> i32;
1503
1504 /// Print an account to the trace log on XRPLd. Any XRPLd instance set to \"trace\" log level will
1505 /// see this.
1506 ///
1507 /// # Parameters
1508 /// * `msg_read_ptr`: A pointer to an array containing text characters (in either utf8).
1509 /// * `msg_read_len`: The byte length of the text to send to the trace log.
1510 /// * `account_ptr`: A pointer to an account.
1511 /// * `account_len`: The byte length of the account.
1512 ///
1513 /// # Returns
1514 ///
1515 /// Returns an integer representing the result of the operation. A value of `0` or higher
1516 /// signifies the number of message bytes that were written to the trace function. Non-zero
1517 /// values indicate an error that corresponds to a known error code (e.g., incorrect buffer
1518 /// sizes).
1519 ///
1520 /// # Safety
1521 /// Caller must ensure all pointer parameters point to valid memory
1522 unsafe fn trace_account(
1523 &self,
1524 msg_read_ptr: *const u8,
1525 msg_read_len: usize,
1526 account_ptr: *const u8,
1527 account_len: usize,
1528 ) -> i32;
1529
1530 /// Print an OpaqueFloat number to the trace log on XRPLd. Any XRPLd instance set to \"trace\"
1531 /// log level will see this.
1532 ///
1533 /// # Parameters
1534 /// * `msg_read_ptr`: A pointer to an array containing text characters (in either utf8).
1535 /// * `msg_read_len`: The byte length of the text to send to the trace log.
1536 /// * `opaque_float_ptr`: A pointer to an array of 8 bytes containing the u64 opaque pointer value.
1537 /// * `opaque_float_len`: The byte length of the opaque float data.
1538 ///
1539 /// # Returns
1540 ///
1541 /// Returns an integer representing the result of the operation. A value of `0` or higher
1542 /// signifies the number of message bytes that were written to the trace function. Non-zero
1543 /// values indicate an error that corresponds to a known error code (e.g., incorrect buffer
1544 /// sizes).
1545 ///
1546 /// # Safety
1547 /// Caller must ensure all pointer parameters point to valid memory
1548 unsafe fn trace_opaque_float(
1549 &self,
1550 msg_read_ptr: *const u8,
1551 msg_read_len: usize,
1552 opaque_float_ptr: *const u8,
1553 opaque_float_len: usize,
1554 ) -> i32;
1555
1556 /// Print an amount to the trace log on XRPLd. Any XRPLd instance set to \"trace\" log level will
1557 /// see this.
1558 ///
1559 /// # Parameters
1560 /// * `msg_read_ptr`: A pointer to an array containing text characters (in either utf8).
1561 /// * `msg_read_len`: The byte length of the text to send to the trace log.
1562 /// * `amount_ptr`: A pointer to an amount.
1563 /// * `amount_len`: The byte length of the amount.
1564 ///
1565 /// # Returns
1566 ///
1567 /// Returns an integer representing the result of the operation. A value of `0` or higher
1568 /// signifies the number of message bytes that were written to the trace function. Non-zero
1569 /// values indicate an error that corresponds to a known error code (e.g., incorrect buffer
1570 /// sizes).
1571 ///
1572 /// # Safety
1573 /// Caller must ensure all pointer parameters point to valid memory
1574 unsafe fn trace_amount(
1575 &self,
1576 msg_read_ptr: *const u8,
1577 msg_read_len: usize,
1578 amount_ptr: *const u8,
1579 amount_len: usize,
1580 ) -> i32;
1581}