2014-07-18 13:56:17 +00:00
|
|
|
// Rust Bitcoin Library
|
|
|
|
// Written in 2014 by
|
|
|
|
// Andrew Poelstra <apoelstra@wpsoftware.net>
|
|
|
|
//
|
|
|
|
// To the extent possible under law, the author(s) have dedicated all
|
|
|
|
// copyright and related and neighboring rights to this software to
|
|
|
|
// the public domain worldwide. This software is distributed without
|
|
|
|
// any warranty.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the CC0 Public Domain Dedication
|
|
|
|
// along with this software.
|
|
|
|
// If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
#![macro_escape]
|
|
|
|
|
2014-08-01 16:01:39 +00:00
|
|
|
macro_rules! impl_consensus_encoding(
|
2014-07-18 13:56:17 +00:00
|
|
|
($thing:ident, $($field:ident),+) => (
|
2014-08-01 16:01:39 +00:00
|
|
|
impl<S: ::network::serialize::SimpleEncoder<E>, E> ::network::encodable::ConsensusEncodable<S, E> for $thing {
|
|
|
|
#[inline]
|
|
|
|
fn consensus_encode(&self, s: &mut S) -> Result<(), E> {
|
|
|
|
$( try!(self.$field.consensus_encode(s)); )+
|
|
|
|
Ok(())
|
2014-07-18 13:56:17 +00:00
|
|
|
}
|
2014-08-01 16:01:39 +00:00
|
|
|
}
|
2014-07-18 13:56:17 +00:00
|
|
|
|
2014-08-01 16:01:39 +00:00
|
|
|
impl<D: ::network::serialize::SimpleDecoder<E>, E> ::network::encodable::ConsensusDecodable<D, E> for $thing {
|
|
|
|
#[inline]
|
|
|
|
fn consensus_decode(d: &mut D) -> Result<$thing, E> {
|
|
|
|
use network::encodable::ConsensusDecodable;
|
|
|
|
Ok($thing {
|
|
|
|
$( $field: try!(ConsensusDecodable::consensus_decode(d)), )+
|
|
|
|
})
|
2014-07-18 13:56:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
)
|
|
|
|
|
2014-07-29 03:12:10 +00:00
|
|
|
macro_rules! impl_json(
|
|
|
|
($thing:ident, $($field:ident),+) => (
|
|
|
|
impl ::serialize::json::ToJson for $thing {
|
|
|
|
fn to_json(&self) -> ::serialize::json::Json {
|
|
|
|
use std::collections::TreeMap;
|
|
|
|
use serialize::json::{ToJson, Object};
|
|
|
|
let mut ret = TreeMap::new();
|
|
|
|
$( ret.insert(stringify!($field).to_string(), self.$field.to_json()); )+
|
|
|
|
Object(ret)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
)
|
|
|
|
|