bconv/
lib.rs

1// Convertor between bp-wallet and rust-bitcoin data types.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Written in 2020-2024 by
6//     Dr Maxim Orlovsky <orlovsky@lnp-bp.org>
7//
8// Copyright (C) 2020-2024 LNP/BP Standards Association. All rights reserved.
9// Copyright (C) 2020-2024 Dr Maxim Orlovsky. All rights reserved.
10//
11// Licensed under the Apache License, Version 2.0 (the "License");
12// you may not use this file except in compliance with the License.
13// You may obtain a copy of the License at
14//
15//     http://www.apache.org/licenses/LICENSE-2.0
16//
17// Unless required by applicable law or agreed to in writing, software
18// distributed under the License is distributed on an "AS IS" BASIS,
19// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20// See the License for the specific language governing permissions and
21// limitations under the License.
22
23use amplify::ByteArray;
24use bitcoin::hashes::Hash;
25
26pub trait Convertible {
27    type Target: Sized;
28    fn convert(&self) -> Self::Target;
29}
30
31impl Convertible for bpstd::Txid {
32    type Target = bitcoin::Txid;
33    fn convert(&self) -> Self::Target { Self::Target::from_byte_array(self.to_byte_array()) }
34}
35
36impl Convertible for bitcoin::Txid {
37    type Target = bpstd::Txid;
38    fn convert(&self) -> Self::Target { Self::Target::from_byte_array(self.to_byte_array()) }
39}