1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use crate::blockdata::block::{Block, BlockHeader};
use crate::blockdata::transaction::TransactionPrefix;
use crate::consensus::encode::{Decodable, Encodable, Error};
use crate::{PrivateKey, PublicKey, Transaction, TxIn, TxOut};
pub extern crate strict_encoding;
macro_rules! impl_strict_encoding {
( $thing:ident ) => {
impl strict_encoding::StrictEncode for $thing {
#[inline]
fn strict_encode<E: std::io::Write>(
&self,
mut e: E,
) -> Result<usize, strict_encoding::Error> {
self.consensus_encode(&mut e)
.map_err(strict_encoding::Error::from)
}
}
impl strict_encoding::StrictDecode for $thing {
#[inline]
fn strict_decode<D: std::io::Read>(mut d: D) -> Result<Self, strict_encoding::Error> {
Ok(Self::consensus_decode(&mut d)
.map_err($crate::consensus::encode::Error::from)?)
}
}
};
}
impl_strict_encoding!(PublicKey);
impl_strict_encoding!(PrivateKey);
impl_strict_encoding!(Transaction);
impl_strict_encoding!(TransactionPrefix);
impl_strict_encoding!(TxIn);
impl_strict_encoding!(TxOut);
impl_strict_encoding!(Block);
impl_strict_encoding!(BlockHeader);
impl From<Error> for strict_encoding::Error {
#[inline]
fn from(e: Error) -> Self {
strict_encoding::Error::DataIntegrityError(e.to_string())
}
}