1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::{
num_bigint::{BigInt, BigUint},
DebugApi,
};
use multiversx_sc::api::{BigIntApi, EndpointFinishApi, EndpointFinishApiImpl, ManagedBufferApi};
impl EndpointFinishApi for DebugApi {
type EndpointFinishApiImpl = DebugApi;
fn finish_api_impl() -> Self::EndpointFinishApiImpl {
DebugApi::new_from_static()
}
}
impl EndpointFinishApiImpl for DebugApi {
fn finish_slice_u8(&self, slice: &[u8]) {
let mut v = vec![0u8; slice.len()];
v.copy_from_slice(slice);
let mut tx_result = self.result_borrow_mut();
tx_result.result_values.push(v)
}
fn finish_big_int_raw(&self, handle: Self::BigIntHandle) {
let bi_bytes = self.bi_get_signed_bytes(handle);
let mut tx_result = self.result_borrow_mut();
tx_result.result_values.push(bi_bytes.into_vec());
}
fn finish_big_uint_raw(&self, handle: Self::BigIntHandle) {
let bu_bytes = self.bi_get_unsigned_bytes(handle);
let mut tx_result = self.result_borrow_mut();
tx_result.result_values.push(bu_bytes.into_vec());
}
fn finish_managed_buffer_raw(&self, handle: Self::ManagedBufferHandle) {
let bytes = self.mb_to_boxed_bytes(handle);
self.finish_slice_u8(bytes.as_slice());
}
fn finish_i64(&self, value: i64) {
if value == 0 {
self.finish_slice_u8(&[]);
} else {
self.finish_slice_u8(BigInt::from(value).to_signed_bytes_be().as_slice());
}
}
fn finish_u64(&self, value: u64) {
if value == 0 {
self.finish_slice_u8(&[]);
} else {
self.finish_slice_u8(BigUint::from(value).to_bytes_be().as_slice());
}
}
}