sonicapi/util/
annotations.rs

1// SONIC: Standard library for formally-verifiable distributed contracts
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Designed in 2019-2025 by Dr Maxim Orlovsky <orlovsky@ubideco.org>
6// Written in 2024-2025 by Dr Maxim Orlovsky <orlovsky@ubideco.org>
7//
8// Copyright (C) 2019-2024 LNP/BP Standards Association, Switzerland.
9// Copyright (C) 2024-2025 Laboratories for Ubiquitous Deterministic Computing (UBIDECO),
10//                         Institute for Distributed and Cognitive Systems (InDCS), Switzerland.
11// Copyright (C) 2019-2025 Dr Maxim Orlovsky.
12// All rights under the above copyrights are reserved.
13//
14// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
15// in compliance with the License. You may obtain a copy of the License at
16//
17//        http://www.apache.org/licenses/LICENSE-2.0
18//
19// Unless required by applicable law or agreed to in writing, software distributed under the License
20// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
21// or implied. See the License for the specific language governing permissions and limitations under
22// the License.
23
24use amplify::confinement::{SmallBlob, TinyOrdMap};
25use commit_verify::StrictHash;
26use strict_encoding::stl::{AlphaCaps, AlphaNumDash};
27use strict_encoding::RString;
28
29use crate::LIB_NAME_SONIC;
30
31#[derive(Wrapper, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, From, Display)]
32#[wrapper(Deref, FromStr)]
33#[display(inner)]
34#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
35#[strict_type(lib = LIB_NAME_SONIC)]
36#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(transparent))]
37pub struct AnnotationName(RString<AlphaCaps, AlphaNumDash>);
38
39impl From<&'static str> for AnnotationName {
40    fn from(s: &'static str) -> Self { Self(RString::from(s)) }
41}
42
43#[derive(Wrapper, WrapperMut, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default, From)]
44#[wrapper(Deref)]
45#[wrapper_mut(DerefMut)]
46#[derive(CommitEncode)]
47#[commit_encode(strategy = strict, id = StrictHash)]
48#[derive(StrictType, StrictEncode, StrictDecode)]
49#[strict_type(lib = LIB_NAME_SONIC)]
50#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
51pub struct Annotations(TinyOrdMap<AnnotationName, SmallBlob>);