From 2715a6e7779390390d45ae8ce87d0ced8985802f Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Sat, 8 Sep 2018 20:50:45 -0700 Subject: [PATCH] Add trait for PSBT key-value maps --- src/util/psbt/map/mod.rs | 15 +++++++++++++++ src/util/psbt/mod.rs | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 src/util/psbt/map/mod.rs diff --git a/src/util/psbt/map/mod.rs b/src/util/psbt/map/mod.rs new file mode 100644 index 00000000..621b865a --- /dev/null +++ b/src/util/psbt/map/mod.rs @@ -0,0 +1,15 @@ +use consensus::encode; +use util::psbt; +use util::psbt::raw; + +/// A trait that describes a PSBT key-value map. +pub trait Map { + /// Attempt to insert a key-value pair. + fn insert_pair(&mut self, pair: raw::Pair) -> Result<(), encode::Error>; + + /// Attempt to get all key-value pairs. + fn get_pairs(&self) -> Result, encode::Error>; + + /// Attempt to merge with another key-value map of the same type. + fn merge(&mut self, other: Self) -> Result<(), psbt::Error>; +} diff --git a/src/util/psbt/mod.rs b/src/util/psbt/mod.rs index 421c7cb5..7d87d59b 100644 --- a/src/util/psbt/mod.rs +++ b/src/util/psbt/mod.rs @@ -9,6 +9,9 @@ pub use self::error::Error; pub mod raw; +mod map; +pub use self::map::Map; + #[cfg(test)] mod tests { use consensus::encode::{deserialize, serialize};