sp_auto_id/
runtime_interface.rs

1use crate::{DerVec, SignatureVerificationRequest, TbsCertificate};
2use sp_runtime_interface::pass_by::{AllocateAndReturnByCodec, PassFatPointerAndDecode};
3use sp_runtime_interface::runtime_interface;
4
5/// AutoId runtime interface.
6#[runtime_interface]
7pub trait AutoIdRuntimeInterface {
8    fn verify_signature(
9        &mut self,
10        req: PassFatPointerAndDecode<SignatureVerificationRequest>,
11    ) -> AllocateAndReturnByCodec<Option<()>> {
12        // TODO: we need to conditional compile for benchmarks here since
13        //  benchmark externalities does not provide custom extensions.
14        //  Remove this once the issue is resolved: https://github.com/paritytech/polkadot-sdk/issues/137
15        #[cfg(feature = "runtime-benchmarks")]
16        {
17            use crate::host_functions::verify_signature;
18            verify_signature(req)
19        }
20
21        #[cfg(not(feature = "runtime-benchmarks"))]
22        {
23            use crate::host_functions::HostFunctionExtension;
24            use sp_externalities::ExternalitiesExt;
25            self.extension::<HostFunctionExtension>()
26                .expect("No `AutoIdHostFunctionExtension` associated for the current context!")
27                .verify_signature(req)
28        }
29    }
30
31    fn decode_tbs_certificate(
32        &mut self,
33        certificate: PassFatPointerAndDecode<DerVec>,
34    ) -> AllocateAndReturnByCodec<Option<TbsCertificate>> {
35        // TODO: we need to conditional compile for benchmarks here since
36        //  benchmark externalities does not provide custom extensions.
37        //  Remove this once the issue is resolved: https://github.com/paritytech/polkadot-sdk/issues/137
38        #[cfg(feature = "runtime-benchmarks")]
39        {
40            use crate::host_functions::decode_tbs_certificate;
41            decode_tbs_certificate(certificate)
42        }
43
44        #[cfg(not(feature = "runtime-benchmarks"))]
45        {
46            use crate::host_functions::HostFunctionExtension;
47            use sp_externalities::ExternalitiesExt;
48            self.extension::<HostFunctionExtension>()
49                .expect("No `AutoIdHostFunctionExtension` associated for the current context!")
50                .decode_tbs_certificate(certificate)
51        }
52    }
53}