xrpl_wasm_stdlib/host/
host_bindings_for_testing.rs

1// This file exists as a host_binding stand-in for non-WASM targets. For example, this file will
2// be used during unit tests.
3
4// Float rounding mode constants (same as in host_bindings.rs)
5#[allow(unused)]
6pub const FLOAT_ROUNDING_MODES_TO_NEAREST: i32 = 0;
7#[allow(unused)]
8pub const FLOAT_ROUNDING_MODES_TOWARDS_ZERO: i32 = 1;
9#[allow(unused)]
10pub const FLOAT_ROUNDING_MODES_DOWNWARD: i32 = 2;
11#[allow(unused)]
12pub const FLOAT_ROUNDING_MODES_UPWARD: i32 = 3;
13
14#[allow(unused)]
15#[allow(clippy::missing_safety_doc)]
16pub unsafe fn get_ledger_sqn() -> i32 {
17    1
18}
19
20#[allow(unused)]
21#[allow(clippy::missing_safety_doc)]
22pub unsafe fn get_parent_ledger_time() -> i32 {
23    1
24}
25
26#[allow(unused)]
27#[allow(clippy::missing_safety_doc)]
28pub unsafe fn get_parent_ledger_hash(_out_buff_ptr: *mut u8, _out_buff_len: usize) -> i32 {
29    _out_buff_len as i32
30}
31
32#[allow(unused)]
33#[allow(clippy::missing_safety_doc)]
34pub unsafe fn get_base_fee() -> i32 {
35    1
36}
37
38#[allow(unused)]
39#[allow(clippy::missing_safety_doc)]
40pub unsafe fn amendment_enabled(_amendment_ptr: *const u8, _amendment_len: usize) -> i32 {
41    _amendment_len as i32
42}
43
44#[allow(unused)]
45#[allow(clippy::missing_safety_doc)]
46pub unsafe fn cache_ledger_obj(_keylet_ptr: *const u8, _keylet_len: usize, _cache_num: i32) -> i32 {
47    _keylet_len as i32
48}
49
50#[allow(unused)]
51#[allow(clippy::missing_safety_doc)]
52pub unsafe fn get_tx_field(_field: i32, _out_buff_ptr: *mut u8, _out_buff_len: usize) -> i32 {
53    _out_buff_len as i32
54}
55
56#[allow(unused)]
57#[allow(clippy::missing_safety_doc)]
58pub unsafe fn get_current_ledger_obj_field(
59    _field: i32,
60    _out_buff_ptr: *mut u8,
61    _out_buff_len: usize,
62) -> i32 {
63    _out_buff_len as i32
64}
65
66#[allow(unused)]
67#[allow(clippy::missing_safety_doc)]
68pub unsafe fn get_ledger_obj_field(
69    _cache_num: i32,
70    _field: i32,
71    _out_buff_ptr: *mut u8,
72    _out_buff_len: usize,
73) -> i32 {
74    _out_buff_len as i32
75}
76
77#[allow(unused)]
78#[allow(clippy::missing_safety_doc)]
79pub unsafe fn get_tx_nested_field(
80    _locator_ptr: *const u8,
81    _locator_len: usize,
82    _out_buff_ptr: *mut u8,
83    _out_buff_len: usize,
84) -> i32 {
85    _out_buff_len as i32
86}
87
88#[allow(unused)]
89#[allow(clippy::missing_safety_doc)]
90pub unsafe fn get_current_ledger_obj_nested_field(
91    _locator_ptr: *const u8,
92    _locator_len: usize,
93    _out_buff_ptr: *mut u8,
94    _out_buff_len: usize,
95) -> i32 {
96    _out_buff_len as i32
97}
98
99#[allow(unused)]
100#[allow(clippy::missing_safety_doc)]
101pub unsafe fn get_ledger_obj_nested_field(
102    _cache_num: i32,
103    _locator_ptr: *const u8,
104    _locator_len: usize,
105    _out_buff_ptr: *mut u8,
106    _out_buff_len: usize,
107) -> i32 {
108    _out_buff_len as i32
109}
110
111#[allow(unused)]
112#[allow(clippy::missing_safety_doc)]
113pub unsafe fn get_tx_array_len(_field: i32) -> i32 {
114    0
115}
116
117#[allow(unused)]
118#[allow(clippy::missing_safety_doc)]
119pub unsafe fn get_current_ledger_obj_array_len(_field: i32) -> i32 {
120    0
121}
122
123#[allow(unused)]
124#[allow(clippy::missing_safety_doc)]
125pub unsafe fn get_ledger_obj_array_len(_cache_num: i32, _field: i32) -> i32 {
126    0
127}
128
129#[allow(unused)]
130#[allow(clippy::missing_safety_doc)]
131pub unsafe fn get_tx_nested_array_len(_locator_ptr: *const u8, _locator_len: usize) -> i32 {
132    0
133}
134
135#[allow(unused)]
136#[allow(clippy::missing_safety_doc)]
137pub unsafe fn get_current_ledger_obj_nested_array_len(
138    _locator_ptr: *const u8,
139    _locator_len: usize,
140) -> i32 {
141    _locator_len as i32
142}
143
144#[allow(unused)]
145#[allow(clippy::missing_safety_doc)]
146pub unsafe fn get_ledger_obj_nested_array_len(
147    _cache_num: i32,
148    _locator_ptr: *const u8,
149    _locator_len: usize,
150) -> i32 {
151    _locator_len as i32
152}
153
154#[allow(unused)]
155#[allow(clippy::missing_safety_doc)]
156pub unsafe fn update_data(_data_ptr: *const u8, _data_len: usize) -> i32 {
157    _data_len as i32
158}
159
160#[allow(unused)]
161#[allow(clippy::missing_safety_doc)]
162pub unsafe fn compute_sha512_half(
163    _data_ptr: *const u8,
164    _data_len: usize,
165    _out_buff_ptr: *mut u8,
166    _out_buff_len: usize,
167) -> i32 {
168    _out_buff_len as i32
169}
170
171#[allow(unused)]
172#[allow(clippy::missing_safety_doc)]
173pub unsafe fn check_sig(
174    _message_ptr: *const u8,
175    _message_len: usize,
176    _signature_ptr: *const u8,
177    _signature_len: usize,
178    _pubkey_ptr: *const u8,
179    _pubkey_len: usize,
180) -> i32 {
181    0
182}
183
184#[allow(unused)]
185#[allow(clippy::missing_safety_doc)]
186pub unsafe fn account_keylet(
187    _account_ptr: *const u8,
188    _account_len: usize,
189    _out_buff_ptr: *mut u8,
190    _out_buff_len: usize,
191) -> i32 {
192    _out_buff_len as i32
193}
194
195#[allow(unused)]
196#[allow(clippy::missing_safety_doc)]
197pub unsafe fn amm_keylet(
198    _issue1_ptr: *const u8,
199    _issue1_len: usize,
200    _issue2_ptr: *const u8,
201    _issue2_len: usize,
202    _out_buff_ptr: *mut u8,
203    _out_buff_len: usize,
204) -> i32 {
205    _out_buff_len as i32
206}
207
208#[allow(unused)]
209#[allow(clippy::missing_safety_doc)]
210pub unsafe fn check_keylet(
211    _account_ptr: *const u8,
212    _account_len: usize,
213    _sequence: i32,
214    _out_buff_ptr: *mut u8,
215    _out_buff_len: usize,
216) -> i32 {
217    _out_buff_len as i32
218}
219
220#[allow(unused)]
221#[allow(clippy::too_many_arguments)]
222#[allow(clippy::missing_safety_doc)]
223pub unsafe fn credential_keylet(
224    _subject_ptr: *const u8,
225    _subject_len: usize,
226    _issuer_ptr: *const u8,
227    _issuer_len: usize,
228    _cred_type_ptr: *const u8,
229    _cred_type_len: usize,
230    _out_buff_ptr: *mut u8,
231    _out_buff_len: usize,
232) -> i32 {
233    _out_buff_len as i32
234}
235
236#[allow(unused)]
237#[allow(clippy::missing_safety_doc)]
238pub unsafe fn delegate_keylet(
239    _account_ptr: *const u8,
240    _account_len: usize,
241    _authorize_ptr: *const u8,
242    _authorize_len: usize,
243    _out_buff_ptr: *mut u8,
244    _out_buff_len: usize,
245) -> i32 {
246    _out_buff_len as i32
247}
248
249#[allow(unused)]
250#[allow(clippy::missing_safety_doc)]
251pub unsafe fn deposit_preauth_keylet(
252    _account_ptr: *const u8,
253    _account_len: usize,
254    _authorize_ptr: *const u8,
255    _authorize_len: usize,
256    _out_buff_ptr: *mut u8,
257    _out_buff_len: usize,
258) -> i32 {
259    _out_buff_len as i32
260}
261
262#[allow(unused)]
263#[allow(clippy::missing_safety_doc)]
264pub unsafe fn did_keylet(
265    _account_ptr: *const u8,
266    _account_len: usize,
267    _out_buff_ptr: *mut u8,
268    _out_buff_len: usize,
269) -> i32 {
270    _out_buff_len as i32
271}
272
273#[allow(unused)]
274#[allow(clippy::missing_safety_doc)]
275pub unsafe fn escrow_keylet(
276    _account_ptr: *const u8,
277    _account_len: usize,
278    _sequence: i32,
279    _out_buff_ptr: *mut u8,
280    _out_buff_len: usize,
281) -> i32 {
282    _out_buff_len as i32
283}
284
285#[allow(unused)]
286#[allow(clippy::too_many_arguments)]
287#[allow(clippy::missing_safety_doc)]
288pub unsafe fn line_keylet(
289    _account1_ptr: *const u8,
290    _account1_len: usize,
291    _account2_ptr: *const u8,
292    _account2_len: usize,
293    _currency_ptr: *const u8,
294    _currency_len: usize,
295    _out_buff_ptr: *mut u8,
296    _out_buff_len: usize,
297) -> i32 {
298    _out_buff_len as i32
299}
300
301#[allow(unused)]
302#[allow(clippy::missing_safety_doc)]
303pub unsafe fn mpt_issuance_keylet(
304    _issuer_ptr: *const u8,
305    _issuer_len: usize,
306    _sequence: i32,
307    _out_buff_ptr: *mut u8,
308    _out_buff_len: usize,
309) -> i32 {
310    _out_buff_len as i32
311}
312
313#[allow(unused)]
314#[allow(clippy::missing_safety_doc)]
315pub unsafe fn mptoken_keylet(
316    _mptid_ptr: *const u8,
317    _mptid_len: usize,
318    _holder_ptr: *const u8,
319    _holder_len: usize,
320    _out_buff_ptr: *mut u8,
321    _out_buff_len: usize,
322) -> i32 {
323    _out_buff_len as i32
324}
325
326#[allow(unused)]
327#[allow(clippy::missing_safety_doc)]
328pub unsafe fn nft_offer_keylet(
329    _account_ptr: *const u8,
330    _account_len: usize,
331    _sequence: i32,
332    _out_buff_ptr: *mut u8,
333    _out_buff_len: usize,
334) -> i32 {
335    _out_buff_len as i32
336}
337
338#[allow(unused)]
339#[allow(clippy::missing_safety_doc)]
340pub unsafe fn offer_keylet(
341    _account_ptr: *const u8,
342    _account_len: usize,
343    _sequence: i32,
344    _out_buff_ptr: *mut u8,
345    _out_buff_len: usize,
346) -> i32 {
347    _out_buff_len as i32
348}
349
350#[allow(unused)]
351#[allow(clippy::missing_safety_doc)]
352pub unsafe fn oracle_keylet(
353    _account_ptr: *const u8,
354    _account_len: usize,
355    _document_id: i32,
356    _out_buff_ptr: *mut u8,
357    _out_buff_len: usize,
358) -> i32 {
359    _out_buff_len as i32
360}
361
362#[allow(unused)]
363#[allow(clippy::missing_safety_doc)]
364pub unsafe fn paychan_keylet(
365    _account_ptr: *const u8,
366    _account_len: usize,
367    _destination_ptr: *const u8,
368    _destination_len: usize,
369    _sequence: i32,
370    _out_buff_ptr: *mut u8,
371    _out_buff_len: usize,
372) -> i32 {
373    _out_buff_len as i32
374}
375
376#[allow(unused)]
377#[allow(clippy::missing_safety_doc)]
378pub unsafe fn permissioned_domain_keylet(
379    _account_ptr: *const u8,
380    _account_len: usize,
381    _sequence: i32,
382    _out_buff_ptr: *mut u8,
383    _out_buff_len: usize,
384) -> i32 {
385    _out_buff_len as i32
386}
387
388#[allow(unused)]
389#[allow(clippy::missing_safety_doc)]
390pub unsafe fn signers_keylet(
391    _account_ptr: *const u8,
392    _account_len: usize,
393    _out_buff_ptr: *mut u8,
394    _out_buff_len: usize,
395) -> i32 {
396    _out_buff_len as i32
397}
398
399#[allow(unused)]
400#[allow(clippy::missing_safety_doc)]
401pub unsafe fn ticket_keylet(
402    _account_ptr: *const u8,
403    _account_len: usize,
404    _sequence: i32,
405    _out_buff_ptr: *mut u8,
406    _out_buff_len: usize,
407) -> i32 {
408    _out_buff_len as i32
409}
410
411#[allow(unused)]
412#[allow(clippy::missing_safety_doc)]
413pub unsafe fn vault_keylet(
414    _account_ptr: *const u8,
415    _account_len: usize,
416    _sequence: i32,
417    _out_buff_ptr: *mut u8,
418    _out_buff_len: usize,
419) -> i32 {
420    _out_buff_len as i32
421}
422
423#[allow(unused)]
424#[allow(clippy::missing_safety_doc)]
425pub unsafe fn get_nft(
426    _account_ptr: *const u8,
427    _account_len: usize,
428    _nft_id_ptr: *const u8,
429    _nft_id_len: usize,
430    _out_buff_ptr: *mut u8,
431    _out_buff_len: usize,
432) -> i32 {
433    _out_buff_len as i32
434}
435
436#[allow(unused)]
437#[allow(clippy::missing_safety_doc)]
438pub unsafe fn get_nft_issuer(
439    _nft_id_ptr: *const u8,
440    _nft_id_len: usize,
441    _out_buff_ptr: *mut u8,
442    _out_buff_len: usize,
443) -> i32 {
444    _out_buff_len as i32
445}
446
447#[allow(unused)]
448#[allow(clippy::missing_safety_doc)]
449pub unsafe fn get_nft_taxon(
450    _nft_id_ptr: *const u8,
451    _nft_id_len: usize,
452    _out_buff_ptr: *mut u8,
453    _out_buff_len: usize,
454) -> i32 {
455    _out_buff_len as i32
456}
457
458#[allow(unused)]
459#[allow(clippy::missing_safety_doc)]
460pub unsafe fn get_nft_flags(_nft_id_ptr: *const u8, _nft_id_len: usize) -> i32 {
461    _nft_id_len as i32
462}
463
464#[allow(unused)]
465#[allow(clippy::missing_safety_doc)]
466pub unsafe fn get_nft_transfer_fee(_nft_id_ptr: *const u8, _nft_id_len: usize) -> i32 {
467    _nft_id_len as i32
468}
469
470#[allow(unused)]
471#[allow(clippy::missing_safety_doc)]
472pub unsafe fn get_nft_serial(
473    _nft_id_ptr: *const u8,
474    _nft_id_len: usize,
475    _out_buff_ptr: *mut u8,
476    _out_buff_len: usize,
477) -> i32 {
478    _out_buff_len as i32
479}
480
481#[allow(unused)]
482#[allow(clippy::missing_safety_doc)]
483pub unsafe fn float_from_int(
484    _in_int: i64,
485    _out_buff: *mut u8,
486    _out_buff_len: usize,
487    _rounding_mode: i32,
488) -> i32 {
489    _out_buff_len as i32
490}
491
492#[allow(unused)]
493#[allow(clippy::missing_safety_doc)]
494pub unsafe fn float_from_uint(
495    _in_uint_ptr: *const u8,
496    _in_uint_len: usize,
497    _out_buff: *mut u8,
498    _out_buff_len: usize,
499    _rounding_mode: i32,
500) -> i32 {
501    _out_buff_len as i32
502}
503
504#[allow(unused)]
505#[allow(clippy::missing_safety_doc)]
506pub unsafe fn float_set(
507    _exponent: i32,
508    _mantissa: i64,
509    _out_buff: *mut u8,
510    _out_buff_len: usize,
511    _rounding_mode: i32,
512) -> i32 {
513    _out_buff_len as i32
514}
515
516#[allow(unused)]
517#[allow(clippy::missing_safety_doc)]
518pub unsafe fn float_compare(
519    _in_buff1: *const u8,
520    _in_buff1_len: usize,
521    _in_buff2: *const u8,
522    _in_buff2_len: usize,
523) -> i32 {
524    0
525}
526
527#[allow(unused)]
528#[allow(clippy::missing_safety_doc)]
529pub unsafe fn float_add(
530    _in_buff1: *const u8,
531    _in_buff1_len: usize,
532    _in_buff2: *const u8,
533    _in_buff2_len: usize,
534    _out_buff: *mut u8,
535    _out_buff_len: usize,
536    _rounding_mode: i32,
537) -> i32 {
538    _out_buff_len as i32
539}
540
541#[allow(unused)]
542#[allow(clippy::missing_safety_doc)]
543pub unsafe fn float_subtract(
544    _in_buff1: *const u8,
545    _in_buff1_len: usize,
546    _in_buff2: *const u8,
547    _in_buff2_len: usize,
548    _out_buff: *mut u8,
549    _out_buff_len: usize,
550    _rounding_mode: i32,
551) -> i32 {
552    _out_buff_len as i32
553}
554
555#[allow(unused)]
556#[allow(clippy::missing_safety_doc)]
557pub unsafe fn float_multiply(
558    _in_buff1: *const u8,
559    _in_buff1_len: usize,
560    _in_buff2: *const u8,
561    _in_buff2_len: usize,
562    _out_buff: *mut u8,
563    _out_buff_len: usize,
564    _rounding_mode: i32,
565) -> i32 {
566    _out_buff_len as i32
567}
568
569#[allow(unused)]
570#[allow(clippy::missing_safety_doc)]
571pub unsafe fn float_divide(
572    _in_buff1: *const u8,
573    _in_buff1_len: usize,
574    _in_buff2: *const u8,
575    _in_buff2_len: usize,
576    _out_buff: *mut u8,
577    _out_buff_len: usize,
578    _rounding_mode: i32,
579) -> i32 {
580    _out_buff_len as i32
581}
582
583#[allow(unused)]
584#[allow(clippy::missing_safety_doc)]
585pub unsafe fn float_pow(
586    _in_buff: *const u8,
587    _in_buff_len: usize,
588    _in_int: i32,
589    _out_buff: *mut u8,
590    _out_buff_len: usize,
591    _rounding_mode: i32,
592) -> i32 {
593    _out_buff_len as i32
594}
595
596#[allow(unused)]
597#[allow(clippy::missing_safety_doc)]
598pub unsafe fn float_root(
599    _in_buff: *const u8,
600    _in_buff_len: usize,
601    _in_int: i32,
602    _out_buff: *mut u8,
603    _out_buff_len: usize,
604    _rounding_mode: i32,
605) -> i32 {
606    _out_buff_len as i32
607}
608
609#[allow(unused)]
610#[allow(clippy::missing_safety_doc)]
611pub unsafe fn float_log(
612    _in_buff: *const u8,
613    _in_buff_len: usize,
614    _out_buff: *mut u8,
615    _out_buff_len: usize,
616    _rounding_mode: i32,
617) -> i32 {
618    _out_buff_len as i32
619}
620
621#[allow(unused)]
622#[allow(clippy::missing_safety_doc)]
623pub unsafe fn trace(
624    _msg_read_ptr: *const u8,
625    _msg_read_len: usize,
626    _data_read_ptr: *const u8,
627    _data_read_len: usize,
628    _as_hex: i32,
629) -> i32 {
630    // Prevent overflow: saturate addition and cast
631    let sum = _data_read_len.saturating_add(_msg_read_len);
632    if sum > i32::MAX as usize {
633        i32::MAX
634    } else {
635        sum as i32
636    }
637}
638
639#[allow(unused)]
640#[allow(clippy::missing_safety_doc)]
641pub unsafe fn trace_num(_msg_read_ptr: *const u8, _msg_read_len: usize, _number: i64) -> i32 {
642    // Prevent overflow: saturate addition and cast to i32 safely
643    let sum = _msg_read_len.saturating_add(4);
644    if sum > i32::MAX as usize {
645        i32::MAX
646    } else {
647        sum as i32
648    }
649}
650
651#[allow(unused)]
652#[allow(clippy::missing_safety_doc)]
653pub unsafe fn trace_account(
654    _msg_read_ptr: *const u8,
655    _msg_read_len: usize,
656    _account_ptr: *const u8,
657    _account_len: usize,
658) -> i32 {
659    // Prevent overflow: saturate addition and cast to i32 safely
660    let sum = _msg_read_len.saturating_add(_account_len);
661    if sum > i32::MAX as usize {
662        i32::MAX
663    } else {
664        sum as i32
665    }
666}
667
668#[allow(unused)]
669#[allow(clippy::missing_safety_doc)]
670pub unsafe fn trace_opaque_float(
671    _msg_read_ptr: *const u8,
672    _msg_read_len: usize,
673    _opaque_float_ptr: *const u8,
674    _opaque_float_len: usize,
675) -> i32 {
676    // Prevent overflow: saturate addition and cast to i32 safely
677    let sum = _msg_read_len.saturating_add(_opaque_float_len);
678    if sum > i32::MAX as usize {
679        i32::MAX
680    } else {
681        sum as i32
682    }
683}
684
685#[allow(unused)]
686#[allow(clippy::missing_safety_doc)]
687pub unsafe fn trace_amount(
688    _msg_read_ptr: *const u8,
689    _msg_read_len: usize,
690    _amount_ptr: *const u8,
691    _amount_len: usize,
692) -> i32 {
693    // Prevent overflow: saturate addition and cast to i32 safely
694    let sum = _msg_read_len.saturating_add(_amount_len);
695    if sum > i32::MAX as usize {
696        i32::MAX
697    } else {
698        sum as i32
699    }
700}