rgbstd/containers/
util.rs

1// RGB standard library for working with smart contracts on Bitcoin & Lightning
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Written in 2019-2023 by
6//     Dr Maxim Orlovsky <orlovsky@lnp-bp.org>
7//
8// Copyright (C) 2019-2023 LNP/BP Standards Association. All rights reserved.
9//
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13//
14//     http://www.apache.org/licenses/LICENSE-2.0
15//
16// Unless required by applicable law or agreed to in writing, software
17// distributed under the License is distributed on an "AS IS" BASIS,
18// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19// See the License for the specific language governing permissions and
20// limitations under the License.
21
22use amplify::confinement::SmallOrdSet;
23use bp::Tx;
24
25use super::TerminalSeal;
26use crate::LIB_NAME_RGB_STD;
27
28#[derive(Clone, Eq, PartialEq, Debug)]
29#[derive(StrictType, StrictDumb, StrictEncode, StrictDecode)]
30#[strict_type(lib = LIB_NAME_RGB_STD)]
31#[cfg_attr(
32    feature = "serde",
33    derive(Serialize, Deserialize),
34    serde(crate = "serde_crate", rename_all = "camelCase")
35)]
36pub struct Terminal {
37    pub seals: SmallOrdSet<TerminalSeal>,
38    pub tx: Option<Tx>,
39}
40
41impl Terminal {
42    pub fn new(seal: TerminalSeal) -> Self {
43        Terminal {
44            seals: small_bset![seal],
45            tx: None,
46        }
47    }
48    pub fn with(seal: TerminalSeal, tx: Tx) -> Self {
49        Terminal {
50            seals: small_bset![seal],
51            tx: Some(tx),
52        }
53    }
54}
55
56#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display, Default)]
57#[derive(StrictType, StrictEncode, StrictDecode)]
58#[strict_type(lib = LIB_NAME_RGB_STD, tags = repr, into_u8, try_from_u8)]
59#[cfg_attr(
60    feature = "serde",
61    derive(Serialize, Deserialize),
62    serde(crate = "serde_crate", rename_all = "camelCase")
63)]
64#[display(lowercase)]
65#[non_exhaustive]
66#[repr(u8)]
67pub enum ContainerVer {
68    // V0 was a previous version before v0.10, which is now not supported.
69    #[default]
70    V1 = 1,
71}