rgbstd/containers/validate.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 rgb::validation::{ResolveTx, Validator, Validity, Warning};
23
24use super::Consignment;
25
26impl<const TYPE: bool> Consignment<TYPE> {
27 pub fn validate<R: ResolveTx>(
28 mut self,
29 resolver: &mut R,
30 ) -> Result<Consignment<TYPE>, Consignment<TYPE>> {
31 let mut status = Validator::validate(&self, resolver);
32
33 let validity = status.validity();
34
35 if self.transfer != TYPE {
36 status.add_warning(Warning::Custom(s!("invalid consignment type")));
37 }
38 // TODO: check that interface ids match implementations
39 // TODO: check bundle ids listed in terminals are present in the consignment
40 // TODO: check attach ids from data containers are present in operations
41
42 self.validation_status = Some(status);
43 if validity != Validity::Valid {
44 Err(self)
45 } else {
46 Ok(self)
47 }
48 }
49}