bitcoincash/util/psbt/map/
mod.rs

1// SPDX-License-Identifier: CC0-1.0
2
3use crate::prelude::*;
4
5use crate::io;
6
7use crate::consensus::encode;
8use crate::util::psbt::raw;
9
10mod global;
11mod input;
12mod output;
13
14pub use self::input::{Input, PsbtSighashType};
15pub use self::output::{Output, TapTree, IncompleteTapTree};
16
17/// A trait that describes a PSBT key-value map.
18pub(super) trait Map {
19    /// Attempt to get all key-value pairs.
20    fn get_pairs(&self) -> Result<Vec<raw::Pair>, io::Error>;
21
22    /// Encodes map data with bitcoin consensus encoding.
23    fn consensus_encode_map<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
24        let mut len = 0;
25        for pair in Map::get_pairs(self)? {
26            len += encode::Encodable::consensus_encode(&pair, w)?;
27        }
28
29        Ok(len + encode::Encodable::consensus_encode(&0x00_u8, w)?)
30    }
31}