sp_auto_id/
runtime_interface.rs

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