testnumbat_wasm_node/api/
endpoint_finish_api_node.rs

1use crate::AndesApiImpl;
2use testnumbat_wasm::api::{EndpointFinishApi, Handle};
3
4extern "C" {
5    fn finish(dataOffset: *const u8, length: i32);
6
7    // big int API
8    fn bigIntFinishUnsigned(bih: i32);
9    fn bigIntFinishSigned(bih: i32);
10
11    // small int API
12    fn smallIntFinishUnsigned(value: i64);
13    fn smallIntFinishSigned(value: i64);
14
15    // managed buffer API
16    fn mBufferFinish(mBufferHandle: i32) -> i32;
17}
18
19/// Interface to only be used by code generated by the macros.
20/// The smart contract code doesn't have access to these methods directly.
21impl EndpointFinishApi for AndesApiImpl {
22    #[inline]
23    fn finish_slice_u8(&self, slice: &[u8]) {
24        unsafe {
25            finish(slice.as_ptr(), slice.len() as i32);
26        }
27    }
28
29    #[inline]
30    fn finish_big_int_raw(&self, handle: i32) {
31        unsafe {
32            bigIntFinishSigned(handle);
33        }
34    }
35
36    #[inline]
37    fn finish_big_uint_raw(&self, handle: i32) {
38        unsafe {
39            bigIntFinishUnsigned(handle);
40        }
41    }
42
43    #[inline]
44    fn finish_managed_buffer_raw(&self, handle: Handle) {
45        unsafe {
46            mBufferFinish(handle);
47        }
48    }
49
50    #[inline]
51    fn finish_u64(&self, value: u64) {
52        unsafe {
53            smallIntFinishUnsigned(value as i64);
54        }
55    }
56
57    #[inline]
58    fn finish_i64(&self, value: i64) {
59        unsafe {
60            smallIntFinishSigned(value);
61        }
62    }
63}