Skip to main content

dpp_plugin_sdk/
entry.rs

1//! ABI entry-point wrappers called by [`crate::export_plugin!`].
2
3use dpp_plugin_traits::DppSectorPlugin;
4
5use crate::abi;
6use crate::codec::{
7    calculate_metrics_bytes, describe_bytes, generate_passport_bytes, metadata_bytes,
8    validate_bytes,
9};
10
11pub fn run_metadata<P: DppSectorPlugin>(plugin: &P) -> u64 {
12    abi::write_output(metadata_bytes(plugin))
13}
14
15pub fn run_describe<P: DppSectorPlugin>(plugin: &P) -> u64 {
16    abi::write_output(describe_bytes(plugin))
17}
18
19/// # Safety
20/// `ptr`/`len` must describe a host-written input buffer (see [`abi::read_input`]).
21pub unsafe fn run_validate<P: DppSectorPlugin>(plugin: &P, ptr: u32, len: u32) -> u64 {
22    unsafe { abi::write_output(validate_bytes(plugin, abi::read_input(ptr, len))) }
23}
24
25/// # Safety
26/// `ptr`/`len` must describe a host-written input buffer (see [`abi::read_input`]).
27pub unsafe fn run_calculate_metrics<P: DppSectorPlugin>(plugin: &P, ptr: u32, len: u32) -> u64 {
28    unsafe { abi::write_output(calculate_metrics_bytes(plugin, abi::read_input(ptr, len))) }
29}
30
31/// # Safety
32/// `ptr`/`len` must describe a host-written input buffer (see [`abi::read_input`]).
33pub unsafe fn run_generate_passport<P: DppSectorPlugin>(plugin: &P, ptr: u32, len: u32) -> u64 {
34    unsafe { abi::write_output(generate_passport_bytes(plugin, abi::read_input(ptr, len))) }
35}