Merge pull request #403 from LNP-BP/fix-macro-ns
Hygiene/single code style for all existing macros
This commit is contained in:
commit
e8bcde4d38
|
@ -18,31 +18,32 @@
|
||||||
|
|
||||||
macro_rules! impl_consensus_encoding {
|
macro_rules! impl_consensus_encoding {
|
||||||
($thing:ident, $($field:ident),+) => (
|
($thing:ident, $($field:ident),+) => (
|
||||||
impl ::consensus::Encodable for $thing {
|
impl $crate::consensus::Encodable for $thing {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn consensus_encode<S: ::std::io::Write>(
|
fn consensus_encode<S: ::std::io::Write>(
|
||||||
&self,
|
&self,
|
||||||
mut s: S,
|
mut s: S,
|
||||||
) -> Result<usize, ::consensus::encode::Error> {
|
) -> Result<usize, $crate::consensus::encode::Error> {
|
||||||
let mut len = 0;
|
let mut len = 0;
|
||||||
$(len += self.$field.consensus_encode(&mut s)?;)+
|
$(len += self.$field.consensus_encode(&mut s)?;)+
|
||||||
Ok(len)
|
Ok(len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::consensus::Decodable for $thing {
|
impl $crate::consensus::Decodable for $thing {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn consensus_decode<D: ::std::io::Read>(
|
fn consensus_decode<D: ::std::io::Read>(
|
||||||
mut d: D,
|
mut d: D,
|
||||||
) -> Result<$thing, ::consensus::encode::Error> {
|
) -> Result<$thing, $crate::consensus::encode::Error> {
|
||||||
Ok($thing {
|
Ok($thing {
|
||||||
$($field: ::consensus::Decodable::consensus_decode(&mut d)?),+
|
$($field: $crate::consensus::Decodable::consensus_decode(&mut d)?),+
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implements standard array methods for a given wrapper type
|
||||||
macro_rules! impl_array_newtype {
|
macro_rules! impl_array_newtype {
|
||||||
($thing:ident, $ty:ty, $len:expr) => {
|
($thing:ident, $ty:ty, $len:expr) => {
|
||||||
impl $thing {
|
impl $thing {
|
||||||
|
@ -81,7 +82,7 @@ macro_rules! impl_array_newtype {
|
||||||
pub fn into_bytes(self) -> [$ty; $len] { self.0 }
|
pub fn into_bytes(self) -> [$ty; $len] { self.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<&'a [$ty]> for $thing {
|
impl<'a> ::std::convert::From<&'a [$ty]> for $thing {
|
||||||
fn from(data: &'a [$ty]) -> $thing {
|
fn from(data: &'a [$ty]) -> $thing {
|
||||||
assert_eq!(data.len(), $len);
|
assert_eq!(data.len(), $len);
|
||||||
let mut ret = [0; $len];
|
let mut ret = [0; $len];
|
||||||
|
@ -102,23 +103,23 @@ macro_rules! impl_array_newtype {
|
||||||
|
|
||||||
impl_index_newtype!($thing, $ty);
|
impl_index_newtype!($thing, $ty);
|
||||||
|
|
||||||
impl PartialEq for $thing {
|
impl ::std::cmp::PartialEq for $thing {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn eq(&self, other: &$thing) -> bool {
|
fn eq(&self, other: &$thing) -> bool {
|
||||||
&self[..] == &other[..]
|
&self[..] == &other[..]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Eq for $thing {}
|
impl ::std::cmp::Eq for $thing {}
|
||||||
|
|
||||||
impl PartialOrd for $thing {
|
impl ::std::cmp::PartialOrd for $thing {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_cmp(&self, other: &$thing) -> Option<::std::cmp::Ordering> {
|
fn partial_cmp(&self, other: &$thing) -> Option<::std::cmp::Ordering> {
|
||||||
Some(self.cmp(&other))
|
Some(self.cmp(&other))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ord for $thing {
|
impl ::std::cmp::Ord for $thing {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cmp(&self, other: &$thing) -> ::std::cmp::Ordering {
|
fn cmp(&self, other: &$thing) -> ::std::cmp::Ordering {
|
||||||
// manually implement comparison to get little-endian ordering
|
// manually implement comparison to get little-endian ordering
|
||||||
|
@ -134,14 +135,14 @@ macro_rules! impl_array_newtype {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "clippy", allow(expl_impl_clone_on_copy))] // we don't define the `struct`, we have to explicitly impl
|
#[cfg_attr(feature = "clippy", allow(expl_impl_clone_on_copy))] // we don't define the `struct`, we have to explicitly impl
|
||||||
impl Clone for $thing {
|
impl ::std::clone::Clone for $thing {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone(&self) -> $thing {
|
fn clone(&self) -> $thing {
|
||||||
$thing::from(&self[..])
|
$thing::from(&self[..])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Copy for $thing {}
|
impl ::std::marker::Copy for $thing {}
|
||||||
|
|
||||||
impl ::std::hash::Hash for $thing {
|
impl ::std::hash::Hash for $thing {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -162,6 +163,7 @@ macro_rules! impl_array_newtype {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implements debug formatting for a given wrapper type
|
||||||
macro_rules! impl_array_newtype_show {
|
macro_rules! impl_array_newtype_show {
|
||||||
($thing:ident) => {
|
($thing:ident) => {
|
||||||
impl ::std::fmt::Debug for $thing {
|
impl ::std::fmt::Debug for $thing {
|
||||||
|
@ -172,6 +174,7 @@ macro_rules! impl_array_newtype_show {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implements standard indexing methods for a given wrapper type
|
||||||
macro_rules! impl_index_newtype {
|
macro_rules! impl_index_newtype {
|
||||||
($thing:ident, $ty:ty) => {
|
($thing:ident, $ty:ty) => {
|
||||||
impl ::std::ops::Index<::std::ops::Range<usize>> for $thing {
|
impl ::std::ops::Index<::std::ops::Range<usize>> for $thing {
|
||||||
|
@ -224,10 +227,10 @@ macro_rules! display_from_debug {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
macro_rules! hex_script (($s:expr) => (::blockdata::script::Script::from(<Vec<u8> as ::hashes::hex::FromHex>::from_hex($s).unwrap())));
|
macro_rules! hex_script (($s:expr) => ($crate::blockdata::script::Script::from(<Vec<u8> as $crate::hashes::hex::FromHex>::from_hex($s).unwrap())));
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
macro_rules! hex_hash (($h:ident, $s:expr) => ($h::from_slice(&<Vec<u8> as ::hashes::hex::FromHex>::from_hex($s).unwrap()).unwrap()));
|
macro_rules! hex_hash (($h:ident, $s:expr) => ($h::from_slice(&<Vec<u8> as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()).unwrap()));
|
||||||
|
|
||||||
macro_rules! serde_struct_impl {
|
macro_rules! serde_struct_impl {
|
||||||
($name:ident, $($fe:ident),*) => (
|
($name:ident, $($fe:ident),*) => (
|
||||||
|
@ -237,7 +240,7 @@ macro_rules! serde_struct_impl {
|
||||||
where
|
where
|
||||||
D: $crate::serde::de::Deserializer<'de>,
|
D: $crate::serde::de::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
use $crate::std::fmt::{self, Formatter};
|
use ::std::fmt::{self, Formatter};
|
||||||
use $crate::serde::de::IgnoredAny;
|
use $crate::serde::de::IgnoredAny;
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
|
@ -267,7 +270,7 @@ macro_rules! serde_struct_impl {
|
||||||
impl<'de> $crate::serde::Deserialize<'de> for Enum {
|
impl<'de> $crate::serde::Deserialize<'de> for Enum {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where
|
||||||
D: ::serde::de::Deserializer<'de>,
|
D: $crate::serde::de::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
deserializer.deserialize_str(EnumVisitor)
|
deserializer.deserialize_str(EnumVisitor)
|
||||||
}
|
}
|
||||||
|
@ -379,8 +382,8 @@ macro_rules! serde_string_impl {
|
||||||
where
|
where
|
||||||
D: $crate::serde::de::Deserializer<'de>,
|
D: $crate::serde::de::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
use $crate::std::fmt::{self, Formatter};
|
use ::std::fmt::{self, Formatter};
|
||||||
use $crate::std::str::FromStr;
|
use ::std::str::FromStr;
|
||||||
|
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
|
impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
|
||||||
|
@ -440,8 +443,8 @@ macro_rules! serde_struct_human_string_impl {
|
||||||
D: $crate::serde::de::Deserializer<'de>,
|
D: $crate::serde::de::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
if deserializer.is_human_readable() {
|
if deserializer.is_human_readable() {
|
||||||
use $crate::std::fmt::{self, Formatter};
|
use ::std::fmt::{self, Formatter};
|
||||||
use $crate::std::str::FromStr;
|
use ::std::str::FromStr;
|
||||||
|
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
|
impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
|
||||||
|
@ -475,7 +478,7 @@ macro_rules! serde_struct_human_string_impl {
|
||||||
|
|
||||||
deserializer.deserialize_str(Visitor)
|
deserializer.deserialize_str(Visitor)
|
||||||
} else {
|
} else {
|
||||||
use $crate::std::fmt::{self, Formatter};
|
use ::std::fmt::{self, Formatter};
|
||||||
use $crate::serde::de::IgnoredAny;
|
use $crate::serde::de::IgnoredAny;
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
|
@ -624,7 +627,7 @@ macro_rules! impl_bytes_newtype {
|
||||||
($t:ident, $len:expr) => (
|
($t:ident, $len:expr) => (
|
||||||
|
|
||||||
impl ::std::fmt::LowerHex for $t {
|
impl ::std::fmt::LowerHex for $t {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||||
for &ch in self.0.iter() {
|
for &ch in self.0.iter() {
|
||||||
write!(f, "{:02x}", ch)?;
|
write!(f, "{:02x}", ch)?;
|
||||||
}
|
}
|
||||||
|
@ -633,16 +636,16 @@ macro_rules! impl_bytes_newtype {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::fmt::Display for $t {
|
impl ::std::fmt::Display for $t {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||||
fmt::LowerHex::fmt(self, f)
|
fmt::LowerHex::fmt(self, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::hashes::hex::FromHex for $t {
|
impl $crate::hashes::hex::FromHex for $t {
|
||||||
fn from_byte_iter<I>(iter: I) -> Result<Self, ::hashes::hex::Error>
|
fn from_byte_iter<I>(iter: I) -> Result<Self, $crate::hashes::hex::Error>
|
||||||
where I: Iterator<Item=Result<u8, ::hashes::hex::Error>> +
|
where I: ::std::iter::Iterator<Item=Result<u8, $crate::hashes::hex::Error>> +
|
||||||
ExactSizeIterator +
|
::std::iter::ExactSizeIterator +
|
||||||
DoubleEndedIterator,
|
::std::iter::DoubleEndedIterator,
|
||||||
{
|
{
|
||||||
if iter.len() == $len {
|
if iter.len() == $len {
|
||||||
let mut ret = [0; $len];
|
let mut ret = [0; $len];
|
||||||
|
@ -651,23 +654,23 @@ macro_rules! impl_bytes_newtype {
|
||||||
}
|
}
|
||||||
Ok($t(ret))
|
Ok($t(ret))
|
||||||
} else {
|
} else {
|
||||||
Err(::hashes::hex::Error::InvalidLength(2 * $len, 2 * iter.len()))
|
Err($crate::hashes::hex::Error::InvalidLength(2 * $len, 2 * iter.len()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::str::FromStr for $t {
|
impl ::std::str::FromStr for $t {
|
||||||
type Err = ::hashes::hex::Error;
|
type Err = $crate::hashes::hex::Error;
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
hex::FromHex::from_hex(s)
|
$crate::hashes::hex::FromHex::from_hex(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature="serde")]
|
#[cfg(feature="serde")]
|
||||||
impl ::serde::Serialize for $t {
|
impl $crate::serde::Serialize for $t {
|
||||||
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
|
fn serialize<S: $crate::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
|
||||||
if s.is_human_readable() {
|
if s.is_human_readable() {
|
||||||
s.serialize_str(&::hashes::hex::ToHex::to_hex(self))
|
s.serialize_str(&$crate::hashes::hex::ToHex::to_hex(self))
|
||||||
} else {
|
} else {
|
||||||
s.serialize_bytes(&self[..])
|
s.serialize_bytes(&self[..])
|
||||||
}
|
}
|
||||||
|
@ -675,12 +678,12 @@ macro_rules! impl_bytes_newtype {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature="serde")]
|
#[cfg(feature="serde")]
|
||||||
impl<'de> ::serde::Deserialize<'de> for $t {
|
impl<'de> $crate::serde::Deserialize<'de> for $t {
|
||||||
fn deserialize<D: ::serde::Deserializer<'de>>(d: D) -> Result<$t, D::Error> {
|
fn deserialize<D: $crate::serde::Deserializer<'de>>(d: D) -> Result<$t, D::Error> {
|
||||||
if d.is_human_readable() {
|
if d.is_human_readable() {
|
||||||
struct HexVisitor;
|
struct HexVisitor;
|
||||||
|
|
||||||
impl<'de> ::serde::de::Visitor<'de> for HexVisitor {
|
impl<'de> $crate::serde::de::Visitor<'de> for HexVisitor {
|
||||||
type Value = $t;
|
type Value = $t;
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
fn expecting(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||||
|
@ -689,20 +692,20 @@ macro_rules! impl_bytes_newtype {
|
||||||
|
|
||||||
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
|
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
|
||||||
where
|
where
|
||||||
E: ::serde::de::Error,
|
E: $crate::serde::de::Error,
|
||||||
{
|
{
|
||||||
if let Ok(hex) = ::std::str::from_utf8(v) {
|
if let Ok(hex) = ::std::str::from_utf8(v) {
|
||||||
::hashes::hex::FromHex::from_hex(hex).map_err(E::custom)
|
$crate::hashes::hex::FromHex::from_hex(hex).map_err(E::custom)
|
||||||
} else {
|
} else {
|
||||||
return Err(E::invalid_value(::serde::de::Unexpected::Bytes(v), &self));
|
return Err(E::invalid_value($crate::serde::de::Unexpected::Bytes(v), &self));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||||
where
|
where
|
||||||
E: ::serde::de::Error,
|
E: $crate::serde::de::Error,
|
||||||
{
|
{
|
||||||
::hashes::hex::FromHex::from_hex(v).map_err(E::custom)
|
$crate::hashes::hex::FromHex::from_hex(v).map_err(E::custom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,7 +713,7 @@ macro_rules! impl_bytes_newtype {
|
||||||
} else {
|
} else {
|
||||||
struct BytesVisitor;
|
struct BytesVisitor;
|
||||||
|
|
||||||
impl<'de> ::serde::de::Visitor<'de> for BytesVisitor {
|
impl<'de> $crate::serde::de::Visitor<'de> for BytesVisitor {
|
||||||
type Value = $t;
|
type Value = $t;
|
||||||
|
|
||||||
fn expecting(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
fn expecting(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||||
|
@ -719,7 +722,7 @@ macro_rules! impl_bytes_newtype {
|
||||||
|
|
||||||
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
|
fn visit_bytes<E>(self, v: &[u8]) -> Result<Self::Value, E>
|
||||||
where
|
where
|
||||||
E: ::serde::de::Error,
|
E: $crate::serde::de::Error,
|
||||||
{
|
{
|
||||||
if v.len() != $len {
|
if v.len() != $len {
|
||||||
Err(E::invalid_length(v.len(), &stringify!($len)))
|
Err(E::invalid_length(v.len(), &stringify!($len)))
|
||||||
|
@ -788,7 +791,7 @@ macro_rules! user_enum {
|
||||||
where
|
where
|
||||||
D: $crate::serde::Deserializer<'de>,
|
D: $crate::serde::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
use $crate::std::fmt::{self, Formatter};
|
use ::std::fmt::{self, Formatter};
|
||||||
|
|
||||||
struct Visitor;
|
struct Visitor;
|
||||||
impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
|
impl<'de> $crate::serde::de::Visitor<'de> for Visitor {
|
||||||
|
@ -831,10 +834,10 @@ macro_rules! user_enum {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
impl ::serde::Serialize for $name {
|
impl $crate::serde::Serialize for $name {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: ::serde::Serializer,
|
S: $crate::serde::Serializer,
|
||||||
{
|
{
|
||||||
serializer.collect_str(&self)
|
serializer.collect_str(&self)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ use std::str::FromStr;
|
||||||
#[cfg(feature = "serde")] use serde;
|
#[cfg(feature = "serde")] use serde;
|
||||||
|
|
||||||
use hash_types::XpubIdentifier;
|
use hash_types::XpubIdentifier;
|
||||||
use hashes::{hex, sha512, Hash, HashEngine, Hmac, HmacEngine};
|
use hashes::{sha512, Hash, HashEngine, Hmac, HmacEngine};
|
||||||
use secp256k1::{self, Secp256k1};
|
use secp256k1::{self, Secp256k1};
|
||||||
|
|
||||||
use network::constants::Network;
|
use network::constants::Network;
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
#[allow(unused_macros)]
|
||||||
macro_rules! hex_psbt {
|
macro_rules! hex_psbt {
|
||||||
($s:expr) => { ::consensus::deserialize(&<Vec<u8> as ::hashes::hex::FromHex>::from_hex($s).unwrap()) };
|
($s:expr) => { $crate::consensus::deserialize(&<Vec<u8> as $crate::hashes::hex::FromHex>::from_hex($s).unwrap()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! merge {
|
macro_rules! merge {
|
||||||
|
@ -34,9 +34,9 @@ macro_rules! impl_psbt_de_serialize {
|
||||||
|
|
||||||
macro_rules! impl_psbt_deserialize {
|
macro_rules! impl_psbt_deserialize {
|
||||||
($thing:ty) => {
|
($thing:ty) => {
|
||||||
impl ::util::psbt::serialize::Deserialize for $thing {
|
impl $crate::util::psbt::serialize::Deserialize for $thing {
|
||||||
fn deserialize(bytes: &[u8]) -> Result<Self, ::consensus::encode::Error> {
|
fn deserialize(bytes: &[u8]) -> Result<Self, $crate::consensus::encode::Error> {
|
||||||
::consensus::deserialize(&bytes[..])
|
$crate::consensus::deserialize(&bytes[..])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -44,9 +44,9 @@ macro_rules! impl_psbt_deserialize {
|
||||||
|
|
||||||
macro_rules! impl_psbt_serialize {
|
macro_rules! impl_psbt_serialize {
|
||||||
($thing:ty) => {
|
($thing:ty) => {
|
||||||
impl ::util::psbt::serialize::Serialize for $thing {
|
impl $crate::util::psbt::serialize::Serialize for $thing {
|
||||||
fn serialize(&self) -> Vec<u8> {
|
fn serialize(&self) -> Vec<u8> {
|
||||||
::consensus::serialize(self)
|
$crate::consensus::serialize(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -54,20 +54,20 @@ macro_rules! impl_psbt_serialize {
|
||||||
|
|
||||||
macro_rules! impl_psbtmap_consensus_encoding {
|
macro_rules! impl_psbtmap_consensus_encoding {
|
||||||
($thing:ty) => {
|
($thing:ty) => {
|
||||||
impl ::consensus::Encodable for $thing {
|
impl $crate::consensus::Encodable for $thing {
|
||||||
fn consensus_encode<S: ::std::io::Write>(
|
fn consensus_encode<S: ::std::io::Write>(
|
||||||
&self,
|
&self,
|
||||||
mut s: S,
|
mut s: S,
|
||||||
) -> Result<usize, ::consensus::encode::Error> {
|
) -> Result<usize, $crate::consensus::encode::Error> {
|
||||||
let mut len = 0;
|
let mut len = 0;
|
||||||
for pair in ::util::psbt::Map::get_pairs(self)? {
|
for pair in $crate::util::psbt::Map::get_pairs(self)? {
|
||||||
len += ::consensus::Encodable::consensus_encode(
|
len += $crate::consensus::Encodable::consensus_encode(
|
||||||
&pair,
|
&pair,
|
||||||
&mut s,
|
&mut s,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(len + ::consensus::Encodable::consensus_encode(&0x00_u8, s)?)
|
Ok(len + $crate::consensus::Encodable::consensus_encode(&0x00_u8, s)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -75,16 +75,16 @@ macro_rules! impl_psbtmap_consensus_encoding {
|
||||||
|
|
||||||
macro_rules! impl_psbtmap_consensus_decoding {
|
macro_rules! impl_psbtmap_consensus_decoding {
|
||||||
($thing:ty) => {
|
($thing:ty) => {
|
||||||
impl ::consensus::Decodable for $thing {
|
impl $crate::consensus::Decodable for $thing {
|
||||||
fn consensus_decode<D: ::std::io::Read>(
|
fn consensus_decode<D: ::std::io::Read>(
|
||||||
mut d: D,
|
mut d: D,
|
||||||
) -> Result<Self, ::consensus::encode::Error> {
|
) -> Result<Self, $crate::consensus::encode::Error> {
|
||||||
let mut rv: Self = ::std::default::Default::default();
|
let mut rv: Self = ::std::default::Default::default();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match ::consensus::Decodable::consensus_decode(&mut d) {
|
match $crate::consensus::Decodable::consensus_decode(&mut d) {
|
||||||
Ok(pair) => ::util::psbt::Map::insert_pair(&mut rv, pair)?,
|
Ok(pair) => $crate::util::psbt::Map::insert_pair(&mut rv, pair)?,
|
||||||
Err(::consensus::encode::Error::Psbt(::util::psbt::Error::NoMorePairs)) => return Ok(rv),
|
Err($crate::consensus::encode::Error::Psbt($crate::util::psbt::Error::NoMorePairs)) => return Ok(rv),
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,29 +105,27 @@ macro_rules! impl_psbt_insert_pair {
|
||||||
($slf:ident.$unkeyed_name:ident <= <$raw_key:ident: _>|<$raw_value:ident: $unkeyed_value_type:ty>) => {
|
($slf:ident.$unkeyed_name:ident <= <$raw_key:ident: _>|<$raw_value:ident: $unkeyed_value_type:ty>) => {
|
||||||
if $raw_key.key.is_empty() {
|
if $raw_key.key.is_empty() {
|
||||||
if $slf.$unkeyed_name.is_none() {
|
if $slf.$unkeyed_name.is_none() {
|
||||||
let val: $unkeyed_value_type = ::util::psbt::serialize::Deserialize::deserialize(&$raw_value)?;
|
let val: $unkeyed_value_type = $crate::util::psbt::serialize::Deserialize::deserialize(&$raw_value)?;
|
||||||
|
|
||||||
$slf.$unkeyed_name = Some(val)
|
$slf.$unkeyed_name = Some(val)
|
||||||
} else {
|
} else {
|
||||||
return Err(::util::psbt::Error::DuplicateKey($raw_key).into());
|
return Err($crate::util::psbt::Error::DuplicateKey($raw_key).into());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(::util::psbt::Error::InvalidKey($raw_key).into());
|
return Err($crate::util::psbt::Error::InvalidKey($raw_key).into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($slf:ident.$keyed_name:ident <= <$raw_key:ident: $keyed_key_type:ty>|<$raw_value:ident: $keyed_value_type:ty>) => {
|
($slf:ident.$keyed_name:ident <= <$raw_key:ident: $keyed_key_type:ty>|<$raw_value:ident: $keyed_value_type:ty>) => {
|
||||||
if !$raw_key.key.is_empty() {
|
if !$raw_key.key.is_empty() {
|
||||||
let key_val: $keyed_key_type = ::util::psbt::serialize::Deserialize::deserialize(&$raw_key.key)?;
|
let key_val: $keyed_key_type = $crate::util::psbt::serialize::Deserialize::deserialize(&$raw_key.key)?;
|
||||||
|
|
||||||
match $slf.$keyed_name.entry(key_val) {
|
match $slf.$keyed_name.entry(key_val) {
|
||||||
::std::collections::btree_map::Entry::Vacant(empty_key) => {
|
::std::collections::btree_map::Entry::Vacant(empty_key) => {
|
||||||
let val: $keyed_value_type = ::util::psbt::serialize::Deserialize::deserialize(&$raw_value)?;
|
let val: $keyed_value_type = $crate::util::psbt::serialize::Deserialize::deserialize(&$raw_value)?;
|
||||||
empty_key.insert(val);
|
empty_key.insert(val);
|
||||||
}
|
}
|
||||||
::std::collections::btree_map::Entry::Occupied(_) => return Err(::util::psbt::Error::DuplicateKey($raw_key).into()),
|
::std::collections::btree_map::Entry::Occupied(_) => return Err($crate::util::psbt::Error::DuplicateKey($raw_key).into()),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(::util::psbt::Error::InvalidKey($raw_key).into());
|
return Err($crate::util::psbt::Error::InvalidKey($raw_key).into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -136,23 +134,23 @@ macro_rules! impl_psbt_insert_pair {
|
||||||
macro_rules! impl_psbt_get_pair {
|
macro_rules! impl_psbt_get_pair {
|
||||||
($rv:ident.push($slf:ident.$unkeyed_name:ident as <$unkeyed_typeval:expr, _>|<$unkeyed_value_type:ty>)) => {
|
($rv:ident.push($slf:ident.$unkeyed_name:ident as <$unkeyed_typeval:expr, _>|<$unkeyed_value_type:ty>)) => {
|
||||||
if let Some(ref $unkeyed_name) = $slf.$unkeyed_name {
|
if let Some(ref $unkeyed_name) = $slf.$unkeyed_name {
|
||||||
$rv.push(::util::psbt::raw::Pair {
|
$rv.push($crate::util::psbt::raw::Pair {
|
||||||
key: ::util::psbt::raw::Key {
|
key: $crate::util::psbt::raw::Key {
|
||||||
type_value: $unkeyed_typeval,
|
type_value: $unkeyed_typeval,
|
||||||
key: vec![],
|
key: vec![],
|
||||||
},
|
},
|
||||||
value: ::util::psbt::serialize::Serialize::serialize($unkeyed_name),
|
value: $crate::util::psbt::serialize::Serialize::serialize($unkeyed_name),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
($rv:ident.push($slf:ident.$keyed_name:ident as <$keyed_typeval:expr, $keyed_key_type:ty>|<$keyed_value_type:ty>)) => {
|
($rv:ident.push($slf:ident.$keyed_name:ident as <$keyed_typeval:expr, $keyed_key_type:ty>|<$keyed_value_type:ty>)) => {
|
||||||
for (key, val) in &$slf.$keyed_name {
|
for (key, val) in &$slf.$keyed_name {
|
||||||
$rv.push(::util::psbt::raw::Pair {
|
$rv.push($crate::util::psbt::raw::Pair {
|
||||||
key: ::util::psbt::raw::Key {
|
key: $crate::util::psbt::raw::Key {
|
||||||
type_value: $keyed_typeval,
|
type_value: $keyed_typeval,
|
||||||
key: ::util::psbt::serialize::Serialize::serialize(key),
|
key: $crate::util::psbt::serialize::Serialize::serialize(key),
|
||||||
},
|
},
|
||||||
value: ::util::psbt::serialize::Serialize::serialize(val),
|
value: $crate::util::psbt::serialize::Serialize::serialize(val),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue