chore(deps): Upgrade to minicbor 0.17 (breaking changes) (#109)
This commit is contained in:
parent
25a65529e0
commit
65a4468f46
18 changed files with 653 additions and 490 deletions
|
|
@ -13,5 +13,5 @@ authors = [
|
|||
]
|
||||
|
||||
[dependencies]
|
||||
minicbor = { version = "0.15", features = ["std", "half", "derive"] }
|
||||
minicbor = { version = "0.17", features = ["std", "half", "derive"] }
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,6 @@ pub use minicbor;
|
|||
/// Round-trip friendly common helper structs
|
||||
pub mod utils;
|
||||
|
||||
pub trait Fragment: Sized + for<'b> minicbor::Decode<'b> + minicbor::Encode {}
|
||||
pub trait Fragment: Sized + for<'b> minicbor::Decode<'b, ()> + minicbor::Encode<()> {}
|
||||
|
||||
impl<T> Fragment for T where T: for<'b> minicbor::Decode<'b> + minicbor::Encode + Sized {}
|
||||
impl<T> Fragment for T where T: for<'b> minicbor::Decode<'b, ()> + minicbor::Encode<()> + Sized {}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,11 @@ use minicbor::{data::Tag, Decode, Encode};
|
|||
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord)]
|
||||
pub struct SkipCbor<const N: usize> {}
|
||||
|
||||
impl<'b, const N: usize> minicbor::Decode<'b> for SkipCbor<N> {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C, const N: usize> minicbor::Decode<'b, C> for SkipCbor<N> {
|
||||
fn decode(
|
||||
d: &mut minicbor::Decoder<'b>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<Self, minicbor::decode::Error> {
|
||||
{
|
||||
let probe = d.probe();
|
||||
println!("skipped cbor value {}: {:?}", N, probe.datatype()?);
|
||||
|
|
@ -18,10 +21,11 @@ impl<'b, const N: usize> minicbor::Decode<'b> for SkipCbor<N> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> minicbor::Encode for SkipCbor<N> {
|
||||
impl<C, const N: usize> minicbor::Encode<C> for SkipCbor<N> {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
_e: &mut minicbor::Encoder<W>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
todo!()
|
||||
}
|
||||
|
|
@ -50,15 +54,15 @@ impl<K, V> Deref for KeyValuePairs<K, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b, K, V> minicbor::decode::Decode<'b> for KeyValuePairs<K, V>
|
||||
impl<'b, C, K, V> minicbor::decode::Decode<'b, C> for KeyValuePairs<K, V>
|
||||
where
|
||||
K: Encode + Decode<'b>,
|
||||
V: Encode + Decode<'b>,
|
||||
K: Encode<C> + Decode<'b, C>,
|
||||
V: Encode<C> + Decode<'b, C>,
|
||||
{
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
let datatype = d.datatype()?;
|
||||
|
||||
let items: Result<Vec<_>, _> = d.map_iter::<K, V>()?.collect();
|
||||
let items: Result<Vec<_>, _> = d.map_iter_with::<C, K, V>(ctx)?.collect();
|
||||
let items = items?;
|
||||
|
||||
match datatype {
|
||||
|
|
@ -71,30 +75,31 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<K, V> minicbor::encode::Encode for KeyValuePairs<K, V>
|
||||
impl<C, K, V> minicbor::encode::Encode<C> for KeyValuePairs<K, V>
|
||||
where
|
||||
K: Encode,
|
||||
V: Encode,
|
||||
K: Encode<C>,
|
||||
V: Encode<C>,
|
||||
{
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
KeyValuePairs::Def(x) => {
|
||||
e.map(x.len() as u64)?;
|
||||
|
||||
for (k, v) in x.iter() {
|
||||
k.encode(e)?;
|
||||
v.encode(e)?;
|
||||
k.encode(e, ctx)?;
|
||||
v.encode(e, ctx)?;
|
||||
}
|
||||
}
|
||||
KeyValuePairs::Indef(x) => {
|
||||
e.begin_map()?;
|
||||
|
||||
for (k, v) in x.iter() {
|
||||
k.encode(e)?;
|
||||
v.encode(e)?;
|
||||
k.encode(e, ctx)?;
|
||||
v.encode(e, ctx)?;
|
||||
}
|
||||
|
||||
e.end()?;
|
||||
|
|
@ -123,16 +128,16 @@ impl<A> Deref for MaybeIndefArray<A> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b, A> minicbor::decode::Decode<'b> for MaybeIndefArray<A>
|
||||
impl<'b, C, A> minicbor::decode::Decode<'b, C> for MaybeIndefArray<A>
|
||||
where
|
||||
A: minicbor::decode::Decode<'b>,
|
||||
A: minicbor::decode::Decode<'b, C>,
|
||||
{
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
let datatype = d.datatype()?;
|
||||
|
||||
match datatype {
|
||||
minicbor::data::Type::Array => Ok(Self::Def(d.decode()?)),
|
||||
minicbor::data::Type::ArrayIndef => Ok(Self::Indef(d.decode()?)),
|
||||
minicbor::data::Type::Array => Ok(Self::Def(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::ArrayIndef => Ok(Self::Indef(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"unknown data type of maybe indef array",
|
||||
)),
|
||||
|
|
@ -140,17 +145,18 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<A> minicbor::encode::Encode for MaybeIndefArray<A>
|
||||
impl<C, A> minicbor::encode::Encode<C> for MaybeIndefArray<A>
|
||||
where
|
||||
A: minicbor::encode::Encode,
|
||||
A: minicbor::encode::Encode<C>,
|
||||
{
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
MaybeIndefArray::Def(x) => {
|
||||
e.encode(x)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
// TODO: this seemed necesary on alonzo, but breaks on byron. We need to double check.
|
||||
//MaybeIndefArray::Indef(x) if x.is_empty() => {
|
||||
|
|
@ -160,7 +166,7 @@ where
|
|||
e.begin_array()?;
|
||||
|
||||
for v in x.iter() {
|
||||
e.encode(v)?;
|
||||
e.encode_with(v, ctx)?;
|
||||
}
|
||||
|
||||
e.end()?;
|
||||
|
|
@ -191,30 +197,31 @@ impl<P> Deref for OrderPreservingProperties<P> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b, P> minicbor::decode::Decode<'b> for OrderPreservingProperties<P>
|
||||
impl<'b, C, P> minicbor::decode::Decode<'b, C> for OrderPreservingProperties<P>
|
||||
where
|
||||
P: Decode<'b>,
|
||||
P: Decode<'b, C>,
|
||||
{
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
let len = d.map()?.unwrap_or_default();
|
||||
|
||||
let components: Result<_, _> = (0..len).map(|_| d.decode()).collect();
|
||||
let components: Result<_, _> = (0..len).map(|_| d.decode_with(ctx)).collect();
|
||||
|
||||
Ok(Self(components?))
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> minicbor::encode::Encode for OrderPreservingProperties<P>
|
||||
impl<C, P> minicbor::encode::Encode<C> for OrderPreservingProperties<P>
|
||||
where
|
||||
P: Encode,
|
||||
P: Encode<C>,
|
||||
{
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
e.map(self.0.len() as u64)?;
|
||||
for component in &self.0 {
|
||||
e.encode(component)?;
|
||||
e.encode_with(component, ctx)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
@ -225,28 +232,29 @@ where
|
|||
#[derive(Debug)]
|
||||
pub struct CborWrap<T>(pub T);
|
||||
|
||||
impl<'b, T> minicbor::Decode<'b> for CborWrap<T>
|
||||
impl<'b, C, T> minicbor::Decode<'b, C> for CborWrap<T>
|
||||
where
|
||||
T: minicbor::Decode<'b>,
|
||||
T: minicbor::Decode<'b, C>,
|
||||
{
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.tag()?;
|
||||
let cbor = d.bytes()?;
|
||||
let wrapped = minicbor::decode(cbor)?;
|
||||
let wrapped = minicbor::decode_with(cbor, ctx)?;
|
||||
|
||||
Ok(CborWrap(wrapped))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> minicbor::Encode for CborWrap<T>
|
||||
impl<C, T> minicbor::Encode<C> for CborWrap<T>
|
||||
where
|
||||
T: minicbor::Encode,
|
||||
T: minicbor::Encode<C>,
|
||||
{
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
let buf = minicbor::to_vec(&self.0).map_err(|_| {
|
||||
let buf = minicbor::to_vec_with(&self.0, ctx).map_err(|_| {
|
||||
minicbor::encode::Error::message("error encoding cbor-wrapped structure")
|
||||
})?;
|
||||
|
||||
|
|
@ -274,27 +282,28 @@ impl<I, const T: u64> TagWrap<I, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b, I, const T: u64> minicbor::Decode<'b> for TagWrap<I, T>
|
||||
impl<'b, C, I, const T: u64> minicbor::Decode<'b, C> for TagWrap<I, T>
|
||||
where
|
||||
I: minicbor::Decode<'b>,
|
||||
I: minicbor::Decode<'b, C>,
|
||||
{
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.tag()?;
|
||||
|
||||
Ok(TagWrap(d.decode()?))
|
||||
Ok(TagWrap(d.decode_with(ctx)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl<I, const T: u64> minicbor::Encode for TagWrap<I, T>
|
||||
impl<C, I, const T: u64> minicbor::Encode<C> for TagWrap<I, T>
|
||||
where
|
||||
I: minicbor::Encode,
|
||||
I: minicbor::Encode<C>,
|
||||
{
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
e.tag(Tag::Unassigned(T))?;
|
||||
e.encode(&self.0)?;
|
||||
e.encode_with(&self.0, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -306,17 +315,21 @@ where
|
|||
#[derive(Debug)]
|
||||
pub struct EmptyMap;
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for EmptyMap {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for EmptyMap {
|
||||
fn decode(
|
||||
d: &mut minicbor::Decoder<'b>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<Self, minicbor::decode::Error> {
|
||||
d.skip()?;
|
||||
Ok(EmptyMap)
|
||||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for EmptyMap {
|
||||
impl<C> minicbor::encode::Encode<C> for EmptyMap {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
e.map(0)?;
|
||||
|
||||
|
|
@ -340,16 +353,16 @@ impl<T> Deref for ZeroOrOneArray<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b, T> minicbor::decode::Decode<'b> for ZeroOrOneArray<T>
|
||||
impl<'b, C, T> minicbor::decode::Decode<'b, C> for ZeroOrOneArray<T>
|
||||
where
|
||||
T: Decode<'b>,
|
||||
T: Decode<'b, C>,
|
||||
{
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
let len = d.array()?;
|
||||
|
||||
match len {
|
||||
Some(0) => Ok(ZeroOrOneArray(None)),
|
||||
Some(1) => Ok(ZeroOrOneArray(Some(d.decode()?))),
|
||||
Some(1) => Ok(ZeroOrOneArray(Some(d.decode_with(ctx)?))),
|
||||
Some(_) => Err(minicbor::decode::Error::message(
|
||||
"found invalid len for zero-or-one pattern",
|
||||
)),
|
||||
|
|
@ -360,18 +373,19 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> minicbor::encode::Encode for ZeroOrOneArray<T>
|
||||
impl<C, T> minicbor::encode::Encode<C> for ZeroOrOneArray<T>
|
||||
where
|
||||
T: minicbor::Encode,
|
||||
T: minicbor::Encode<C>,
|
||||
{
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match &self.0 {
|
||||
Some(x) => {
|
||||
e.array(1)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
None => {
|
||||
e.array(0)?;
|
||||
|
|
@ -392,8 +406,11 @@ pub enum AnyUInt {
|
|||
U64(u64),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for AnyUInt {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for AnyUInt {
|
||||
fn decode(
|
||||
d: &mut minicbor::Decoder<'b>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<Self, minicbor::decode::Error> {
|
||||
match d.datatype()? {
|
||||
minicbor::data::Type::U8 => match d.u8()? {
|
||||
x @ 0..=0x17 => Ok(AnyUInt::MajorByte(x)),
|
||||
|
|
@ -409,39 +426,60 @@ impl<'b> minicbor::decode::Decode<'b> for AnyUInt {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for AnyUInt {
|
||||
impl<C> minicbor::encode::Encode<C> for AnyUInt {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
AnyUInt::MajorByte(x) => {
|
||||
let b = &x.to_be_bytes()[..];
|
||||
e.encode(minicbor::data::Cbor::from(b))?;
|
||||
|
||||
e.writer_mut()
|
||||
.write_all(b)
|
||||
.map_err(minicbor::encode::Error::write)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
AnyUInt::U8(x) => {
|
||||
let x = x.to_be_bytes();
|
||||
let b = &[[24u8], x].concat()[..];
|
||||
e.encode(minicbor::data::Cbor::from(b))?;
|
||||
|
||||
e.writer_mut()
|
||||
.write_all(b)
|
||||
.map_err(minicbor::encode::Error::write)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
AnyUInt::U16(x) => {
|
||||
let x = &x.to_be_bytes()[..];
|
||||
let b = &[&[25u8], x].concat()[..];
|
||||
e.encode(minicbor::data::Cbor::from(b))?;
|
||||
|
||||
e.writer_mut()
|
||||
.write_all(b)
|
||||
.map_err(minicbor::encode::Error::write)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
AnyUInt::U32(x) => {
|
||||
let x = &x.to_be_bytes()[..];
|
||||
let b = &[&[26u8], x].concat()[..];
|
||||
e.encode(minicbor::data::Cbor::from(b))?;
|
||||
|
||||
e.writer_mut()
|
||||
.write_all(b)
|
||||
.map_err(minicbor::encode::Error::write)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
AnyUInt::U64(x) => {
|
||||
let x = &x.to_be_bytes()[..];
|
||||
let b = &[&[27u8], x].concat()[..];
|
||||
e.encode(minicbor::data::Cbor::from(b))?;
|
||||
|
||||
e.writer_mut()
|
||||
.write_all(b)
|
||||
.map_err(minicbor::encode::Error::write)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ authors = [
|
|||
]
|
||||
|
||||
[dependencies]
|
||||
minicbor = { version = "0.15" }
|
||||
hex = "0.4"
|
||||
cryptoxide = { version = "0.4.1" }
|
||||
thiserror = "1.0"
|
||||
rand_core = "0.6"
|
||||
pallas-codec = { version = "0.9.0", path = "../pallas-codec" }
|
||||
|
||||
[dev-dependencies]
|
||||
quickcheck = "1.0"
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
use minicbor::{Decode, Encode};
|
||||
use pallas_codec::minicbor;
|
||||
use std::{fmt, ops::Deref, str::FromStr};
|
||||
|
||||
/// data that is a cryptographic [`struct@Hash`] of `BYTES` long.
|
||||
///
|
||||
/// Possible values with Cardano are 32 bytes long (block hash or transaction
|
||||
/// hash). Or 28 bytes long (as used in addresses)
|
||||
///
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Hash<const BYTES: usize>([u8; BYTES]);
|
||||
|
||||
|
|
@ -68,17 +67,21 @@ impl<const BYTES: usize> FromStr for Hash<BYTES> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<const BYTES: usize> Encode for Hash<BYTES> {
|
||||
impl<C, const BYTES: usize> minicbor::Encode<C> for Hash<BYTES> {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
e.bytes(&self.0)?.ok()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, const BYTES: usize> Decode<'a> for Hash<BYTES> {
|
||||
fn decode(d: &mut minicbor::Decoder<'a>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'a, C, const BYTES: usize> minicbor::Decode<'a, C> for Hash<BYTES> {
|
||||
fn decode(
|
||||
d: &mut minicbor::Decoder<'a>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<Self, minicbor::decode::Error> {
|
||||
let bytes = d.bytes()?;
|
||||
if bytes.len() == BYTES {
|
||||
let mut hash = [0; BYTES];
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::hash::Hash;
|
||||
use cryptoxide::blake2b::Blake2b;
|
||||
use minicbor::encode::Write;
|
||||
use pallas_codec::minicbor;
|
||||
|
||||
/// handy method to create a hash of given `SIZE` bit size.
|
||||
///
|
||||
|
|
@ -72,14 +72,17 @@ macro_rules! common_hasher {
|
|||
/// convenient function to directly generate the hash
|
||||
/// of the given [minicbor::Encode] data object
|
||||
#[inline]
|
||||
pub fn hash_cbor(data: &impl minicbor::Encode) -> Hash<{ $size / 8 }> {
|
||||
pub fn hash_cbor(data: &impl minicbor::Encode<()>) -> Hash<{ $size / 8 }> {
|
||||
let mut hasher = Self::new();
|
||||
let () = minicbor::encode(data, &mut hasher).expect("Infallible");
|
||||
hasher.finalize()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn hash_tagged_cbor(data: &impl minicbor::Encode, tag: u8) -> Hash<{ $size / 8 }> {
|
||||
pub fn hash_tagged_cbor(
|
||||
data: &impl minicbor::Encode<()>,
|
||||
tag: u8,
|
||||
) -> Hash<{ $size / 8 }> {
|
||||
let mut hasher = Self::new();
|
||||
hasher.input(&[tag]);
|
||||
let () = minicbor::encode(data, &mut hasher).expect("Infallible");
|
||||
|
|
@ -122,7 +125,7 @@ impl<const BITS: usize> Write for Hasher<BITS> {
|
|||
}
|
||||
*/
|
||||
|
||||
impl<'a, const BITS: usize> Write for &'a mut Hasher<BITS> {
|
||||
impl<'a, const BITS: usize> minicbor::encode::Write for &'a mut Hasher<BITS> {
|
||||
type Error = std::convert::Infallible;
|
||||
|
||||
#[inline]
|
||||
|
|
|
|||
|
|
@ -22,13 +22,17 @@ pub enum Message {
|
|||
BatchDone,
|
||||
}
|
||||
|
||||
impl Encode for Message {
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for Message {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
match self {
|
||||
Message::RequestRange { range } => {
|
||||
e.array(3)?.u16(0)?;
|
||||
range.0.encode(e)?;
|
||||
range.1.encode(e)?;
|
||||
e.encode(&range.0)?;
|
||||
e.encode(&range.1)?;
|
||||
Ok(())
|
||||
}
|
||||
Message::ClientDone => {
|
||||
|
|
@ -56,15 +60,15 @@ impl Encode for Message {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for Message {
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
impl<'b> Decode<'b, ()> for Message {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
d.array()?;
|
||||
let label = d.u16()?;
|
||||
|
||||
match label {
|
||||
0 => {
|
||||
let point1 = Point::decode(d)?;
|
||||
let point2 = Point::decode(d)?;
|
||||
let point1 = d.decode()?;
|
||||
let point2 = d.decode()?;
|
||||
Ok(Message::RequestRange {
|
||||
range: (point1, point2),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,33 +1,41 @@
|
|||
use crate::common::Point;
|
||||
use pallas_codec::minicbor;
|
||||
use pallas_codec::minicbor::{decode, encode, Decode, Decoder, Encode, Encoder};
|
||||
|
||||
use super::{BlockContent, HeaderContent, Message, SkippedContent, Tip};
|
||||
|
||||
impl Encode for Tip {
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl minicbor::encode::Encode<()> for Tip {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
e.array(2)?;
|
||||
self.0.encode(e)?;
|
||||
e.encode(&self.0)?;
|
||||
e.u64(self.1)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for Tip {
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
impl<'b> Decode<'b, ()> for Tip {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
d.array()?;
|
||||
let point = Point::decode(d)?;
|
||||
let point = d.decode()?;
|
||||
let block_num = d.u64()?;
|
||||
|
||||
Ok(Tip(point, block_num))
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> Encode for Message<C>
|
||||
impl<C> Encode<()> for Message<C>
|
||||
where
|
||||
C: Encode,
|
||||
C: Encode<()>,
|
||||
{
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
match self {
|
||||
Message::RequestNext => {
|
||||
e.array(1)?.u16(0)?;
|
||||
|
|
@ -39,33 +47,33 @@ where
|
|||
}
|
||||
Message::RollForward(content, tip) => {
|
||||
e.array(3)?.u16(2)?;
|
||||
content.encode(e)?;
|
||||
tip.encode(e)?;
|
||||
e.encode(content)?;
|
||||
e.encode(tip)?;
|
||||
Ok(())
|
||||
}
|
||||
Message::RollBackward(point, tip) => {
|
||||
e.array(3)?.u16(3)?;
|
||||
point.encode(e)?;
|
||||
tip.encode(e)?;
|
||||
e.encode(point)?;
|
||||
e.encode(tip)?;
|
||||
Ok(())
|
||||
}
|
||||
Message::FindIntersect(points) => {
|
||||
e.array(2)?.u16(4)?;
|
||||
e.array(points.len() as u64)?;
|
||||
for point in points.iter() {
|
||||
point.encode(e)?;
|
||||
e.encode(point)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Message::IntersectFound(point, tip) => {
|
||||
e.array(3)?.u16(5)?;
|
||||
point.encode(e)?;
|
||||
tip.encode(e)?;
|
||||
e.encode(point)?;
|
||||
e.encode(tip)?;
|
||||
Ok(())
|
||||
}
|
||||
Message::IntersectNotFound(tip) => {
|
||||
e.array(1)?.u16(6)?;
|
||||
tip.encode(e)?;
|
||||
e.encode(tip)?;
|
||||
Ok(())
|
||||
}
|
||||
Message::Done => {
|
||||
|
|
@ -76,11 +84,11 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b, C> Decode<'b> for Message<C>
|
||||
impl<'b, C> Decode<'b, ()> for Message<C>
|
||||
where
|
||||
C: Decode<'b>,
|
||||
C: Decode<'b, ()>,
|
||||
{
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
d.array()?;
|
||||
let label = d.u16()?;
|
||||
|
||||
|
|
@ -88,26 +96,26 @@ where
|
|||
0 => Ok(Message::RequestNext),
|
||||
1 => Ok(Message::AwaitReply),
|
||||
2 => {
|
||||
let content = C::decode(d)?;
|
||||
let tip = Tip::decode(d)?;
|
||||
let content = d.decode()?;
|
||||
let tip = d.decode()?;
|
||||
Ok(Message::RollForward(content, tip))
|
||||
}
|
||||
3 => {
|
||||
let point = Point::decode(d)?;
|
||||
let tip = Tip::decode(d)?;
|
||||
let point = d.decode()?;
|
||||
let tip = d.decode()?;
|
||||
Ok(Message::RollBackward(point, tip))
|
||||
}
|
||||
4 => {
|
||||
let points = Vec::<Point>::decode(d)?;
|
||||
let points = d.decode()?;
|
||||
Ok(Message::FindIntersect(points))
|
||||
}
|
||||
5 => {
|
||||
let point = Point::decode(d)?;
|
||||
let tip = Tip::decode(d)?;
|
||||
let point = d.decode()?;
|
||||
let tip = d.decode()?;
|
||||
Ok(Message::IntersectFound(point, tip))
|
||||
}
|
||||
6 => {
|
||||
let tip = Tip::decode(d)?;
|
||||
let tip = d.decode()?;
|
||||
Ok(Message::IntersectNotFound(tip))
|
||||
}
|
||||
7 => Ok(Message::Done),
|
||||
|
|
@ -118,8 +126,8 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for HeaderContent {
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
impl<'b> Decode<'b, ()> for HeaderContent {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
d.array()?;
|
||||
let variant = d.u8()?; // era variant
|
||||
|
||||
|
|
@ -156,35 +164,47 @@ impl<'b> Decode<'b> for HeaderContent {
|
|||
}
|
||||
}
|
||||
|
||||
impl Encode for HeaderContent {
|
||||
fn encode<W: encode::Write>(&self, _e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for HeaderContent {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
_e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for BlockContent {
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
impl<'b> Decode<'b, ()> for BlockContent {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
d.tag()?;
|
||||
let bytes = d.bytes()?;
|
||||
Ok(BlockContent(Vec::from(bytes)))
|
||||
}
|
||||
}
|
||||
|
||||
impl Encode for BlockContent {
|
||||
fn encode<W: encode::Write>(&self, _e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for BlockContent {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
_e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for SkippedContent {
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
impl<'b> Decode<'b, ()> for SkippedContent {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
d.skip()?;
|
||||
Ok(SkippedContent)
|
||||
}
|
||||
}
|
||||
|
||||
impl Encode for SkippedContent {
|
||||
fn encode<W: encode::Write>(&self, _e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for SkippedContent {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
_e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,8 +39,12 @@ impl Point {
|
|||
}
|
||||
}
|
||||
|
||||
impl Encode for Point {
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for Point {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
match self {
|
||||
Point::Origin => e.array(0)?,
|
||||
Point::Specific(slot, hash) => e.array(2)?.u64(*slot)?.bytes(hash)?,
|
||||
|
|
@ -50,8 +54,8 @@ impl Encode for Point {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for Point {
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
impl<'b> Decode<'b, ()> for Point {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
let size = d.array()?;
|
||||
|
||||
match size {
|
||||
|
|
|
|||
|
|
@ -49,16 +49,20 @@ impl VersionTable {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct VersionData(NetworkMagic);
|
||||
|
||||
impl Encode for VersionData {
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for VersionData {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
e.u64(self.0)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for VersionData {
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
impl<'b> Decode<'b, ()> for VersionData {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
let network_magic = d.u64()?;
|
||||
|
||||
Ok(Self(network_magic))
|
||||
|
|
|
|||
|
|
@ -50,8 +50,12 @@ impl VersionData {
|
|||
}
|
||||
}
|
||||
|
||||
impl Encode for VersionData {
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for VersionData {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
e.array(2)?
|
||||
.u64(self.network_magic)?
|
||||
.bool(self.initiator_and_responder_diffusion_mode)?;
|
||||
|
|
@ -60,8 +64,8 @@ impl Encode for VersionData {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for VersionData {
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
impl<'b> Decode<'b, ()> for VersionData {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
d.array()?;
|
||||
let network_magic = d.u64()?;
|
||||
let initiator_and_responder_diffusion_mode = d.bool()?;
|
||||
|
|
|
|||
|
|
@ -10,27 +10,31 @@ where
|
|||
pub values: HashMap<u64, T>,
|
||||
}
|
||||
|
||||
impl<T> Encode for VersionTable<T>
|
||||
impl<T> Encode<()> for VersionTable<T>
|
||||
where
|
||||
T: Debug + Clone + Encode,
|
||||
T: Debug + Clone + Encode<()>,
|
||||
{
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
e.map(self.values.len() as u64)?;
|
||||
|
||||
for key in self.values.keys().sorted() {
|
||||
e.u64(*key)?;
|
||||
self.values[key].encode(e)?;
|
||||
e.encode(&self.values[key])?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, T> Decode<'b> for VersionTable<T>
|
||||
impl<'b, T> Decode<'b, ()> for VersionTable<T>
|
||||
where
|
||||
T: Debug + Clone + Decode<'b>,
|
||||
T: Debug + Clone + Decode<'b, ()>,
|
||||
{
|
||||
fn decode(_d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
fn decode(_d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
@ -49,13 +53,17 @@ where
|
|||
Refuse(RefuseReason),
|
||||
}
|
||||
|
||||
impl<D> Encode for Message<D>
|
||||
impl<D> Encode<()> for Message<D>
|
||||
where
|
||||
D: Debug + Clone,
|
||||
D: Encode,
|
||||
VersionTable<D>: Encode,
|
||||
D: Encode<()>,
|
||||
VersionTable<D>: Encode<()>,
|
||||
{
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
match self {
|
||||
Message::Propose(version_table) => {
|
||||
e.array(2)?.u16(0)?;
|
||||
|
|
@ -68,7 +76,7 @@ where
|
|||
}
|
||||
Message::Refuse(reason) => {
|
||||
e.array(2)?.u16(2)?;
|
||||
reason.encode(e)?;
|
||||
e.encode(reason)?;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -76,12 +84,12 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b, D> Decode<'b> for Message<D>
|
||||
impl<'b, D> Decode<'b, ()> for Message<D>
|
||||
where
|
||||
D: Decode<'b> + Debug + Clone,
|
||||
VersionTable<D>: Decode<'b>,
|
||||
D: Decode<'b, ()> + Debug + Clone,
|
||||
VersionTable<D>: Decode<'b, ()>,
|
||||
{
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
d.array()?;
|
||||
|
||||
match d.u16()? {
|
||||
|
|
@ -92,7 +100,7 @@ where
|
|||
Ok(Message::Accept(version_number, version_data))
|
||||
}
|
||||
2 => {
|
||||
let reason = RefuseReason::decode(d)?;
|
||||
let reason: RefuseReason = d.decode()?;
|
||||
Ok(Message::Refuse(reason))
|
||||
}
|
||||
_ => Err(decode::Error::message(
|
||||
|
|
@ -116,8 +124,12 @@ pub enum RefuseReason {
|
|||
Refused(VersionNumber, String),
|
||||
}
|
||||
|
||||
impl Encode for RefuseReason {
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for RefuseReason {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
match self {
|
||||
RefuseReason::VersionMismatch(versions) => {
|
||||
e.array(2)?;
|
||||
|
|
@ -149,8 +161,8 @@ impl Encode for RefuseReason {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for RefuseReason {
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
impl<'b> Decode<'b, ()> for RefuseReason {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
d.array()?;
|
||||
|
||||
match d.u16()? {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,12 @@ use pallas_codec::minicbor::{decode, encode, Decode, Encode, Encoder};
|
|||
|
||||
use super::{AcquireFailure, Message, Query};
|
||||
|
||||
impl Encode for AcquireFailure {
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for AcquireFailure {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
let code = match self {
|
||||
AcquireFailure::PointTooOld => 0,
|
||||
AcquireFailure::PointNotInChain => 1,
|
||||
|
|
@ -15,9 +19,10 @@ impl Encode for AcquireFailure {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for AcquireFailure {
|
||||
impl<'b> Decode<'b, ()> for AcquireFailure {
|
||||
fn decode(
|
||||
d: &mut pallas_codec::minicbor::Decoder<'b>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<Self, pallas_codec::minicbor::decode::Error> {
|
||||
let code = d.u16()?;
|
||||
|
||||
|
|
@ -31,13 +36,17 @@ impl<'b> Decode<'b> for AcquireFailure {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Q> Encode for Message<Q>
|
||||
impl<Q> Encode<()> for Message<Q>
|
||||
where
|
||||
Q: Query,
|
||||
Q::Request: Encode,
|
||||
Q::Response: Encode,
|
||||
Q::Request: Encode<()>,
|
||||
Q::Response: Encode<()>,
|
||||
{
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
match self {
|
||||
Message::Acquire(Some(point)) => {
|
||||
e.array(2)?.u16(0)?;
|
||||
|
|
@ -90,14 +99,15 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b, Q> Decode<'b> for Message<Q>
|
||||
impl<'b, Q> Decode<'b, ()> for Message<Q>
|
||||
where
|
||||
Q: Query,
|
||||
Q::Request: Decode<'b>,
|
||||
Q::Response: Decode<'b>,
|
||||
Q::Request: Decode<'b, ()>,
|
||||
Q::Response: Decode<'b, ()>,
|
||||
{
|
||||
fn decode(
|
||||
d: &mut pallas_codec::minicbor::Decoder<'b>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<Self, pallas_codec::minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
let label = d.u16()?;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use pallas_codec::minicbor::{data::Cbor, decode, encode, Decode, Decoder, Encode, Encoder};
|
||||
use pallas_codec::minicbor::{decode, encode, Decode, Decoder, Encode, Encoder};
|
||||
|
||||
use super::Query;
|
||||
|
||||
|
|
@ -13,8 +13,12 @@ pub enum RequestV10 {
|
|||
GetChainPoint,
|
||||
}
|
||||
|
||||
impl Encode for RequestV10 {
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for RequestV10 {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
match self {
|
||||
Self::BlockQuery(..) => {
|
||||
todo!()
|
||||
|
|
@ -35,8 +39,8 @@ impl Encode for RequestV10 {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for RequestV10 {
|
||||
fn decode(_d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
impl<'b> Decode<'b, ()> for RequestV10 {
|
||||
fn decode(_d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
|
@ -44,16 +48,22 @@ impl<'b> Decode<'b> for RequestV10 {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct GenericResponse(Vec<u8>);
|
||||
|
||||
impl Encode for GenericResponse {
|
||||
fn encode<W: encode::Write>(&self, _e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for GenericResponse {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
_e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for GenericResponse {
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
let cbor: Cbor = d.decode()?;
|
||||
let slice = cbor.as_ref();
|
||||
impl<'b> Decode<'b, ()> for GenericResponse {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
let start = d.position();
|
||||
d.skip()?;
|
||||
let end = d.position();
|
||||
let slice = &d.input()[start..end];
|
||||
let vec = slice.to_vec();
|
||||
Ok(GenericResponse(vec))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,12 @@ pub type TxId = u64;
|
|||
#[derive(Debug)]
|
||||
pub struct TxIdAndSize(TxId, TxSizeInBytes);
|
||||
|
||||
impl Encode for TxIdAndSize {
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for TxIdAndSize {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
e.array(2)?;
|
||||
e.u64(self.0)?;
|
||||
e.u32(self.1)?;
|
||||
|
|
@ -36,8 +40,8 @@ impl Encode for TxIdAndSize {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for TxIdAndSize {
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
impl<'b> Decode<'b, ()> for TxIdAndSize {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
d.array()?;
|
||||
let id = d.u64()?;
|
||||
let size = d.u32()?;
|
||||
|
|
@ -66,8 +70,12 @@ pub enum Message {
|
|||
Done,
|
||||
}
|
||||
|
||||
impl Encode for Message {
|
||||
fn encode<W: encode::Write>(&self, e: &mut Encoder<W>) -> Result<(), encode::Error<W::Error>> {
|
||||
impl Encode<()> for Message {
|
||||
fn encode<W: encode::Write>(
|
||||
&self,
|
||||
e: &mut Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), encode::Error<W::Error>> {
|
||||
match self {
|
||||
Message::RequestTxIds(blocking, ack, req) => {
|
||||
e.array(4)?.u16(0)?;
|
||||
|
|
@ -80,7 +88,7 @@ impl Encode for Message {
|
|||
e.array(2)?.u16(1)?;
|
||||
e.array(ids.len() as u64)?;
|
||||
for id in ids {
|
||||
id.encode(e)?;
|
||||
e.encode(id)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -108,8 +116,8 @@ impl Encode for Message {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b> Decode<'b> for Message {
|
||||
fn decode(d: &mut Decoder<'b>) -> Result<Self, decode::Error> {
|
||||
impl<'b> Decode<'b, ()> for Message {
|
||||
fn decode(d: &mut Decoder<'b>, _ctx: &mut ()) -> Result<Self, decode::Error> {
|
||||
d.array()?;
|
||||
let label = d.u16()?;
|
||||
|
||||
|
|
@ -121,7 +129,7 @@ impl<'b> Decode<'b> for Message {
|
|||
Ok(Message::RequestTxIds(blocking, ack, req))
|
||||
}
|
||||
1 => {
|
||||
let items = Vec::<TxIdAndSize>::decode(d)?;
|
||||
let items = d.decode()?;
|
||||
Ok(Message::ReplyTxIds(items))
|
||||
}
|
||||
2 => {
|
||||
|
|
|
|||
|
|
@ -122,15 +122,15 @@ pub enum Value {
|
|||
Multiasset(Coin, Multiasset<Coin>),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for Value {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for Value {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
match d.datatype()? {
|
||||
minicbor::data::Type::U32 => Ok(Value::Coin(d.decode()?)),
|
||||
minicbor::data::Type::U64 => Ok(Value::Coin(d.decode()?)),
|
||||
minicbor::data::Type::U32 => Ok(Value::Coin(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::U64 => Ok(Value::Coin(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::Array => {
|
||||
d.array()?;
|
||||
let coin = d.decode()?;
|
||||
let multiasset = d.decode()?;
|
||||
let coin = d.decode_with(ctx)?;
|
||||
let multiasset = d.decode_with(ctx)?;
|
||||
Ok(Value::Multiasset(coin, multiasset))
|
||||
}
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
|
|
@ -140,20 +140,21 @@ impl<'b> minicbor::decode::Decode<'b> for Value {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for Value {
|
||||
impl<C> minicbor::encode::Encode<C> for Value {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
// TODO: check how to deal with uint variants (u32 vs u64)
|
||||
match self {
|
||||
Value::Coin(coin) => {
|
||||
e.encode(coin)?;
|
||||
e.encode_with(coin, ctx)?;
|
||||
}
|
||||
Value::Multiasset(coin, other) => {
|
||||
e.array(2)?;
|
||||
e.encode(coin)?;
|
||||
e.encode(other)?;
|
||||
e.encode_with(coin, ctx)?;
|
||||
e.encode_with(other, ctx)?;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -192,8 +193,11 @@ pub enum InstantaneousRewardSource {
|
|||
Treasury,
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for InstantaneousRewardSource {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for InstantaneousRewardSource {
|
||||
fn decode(
|
||||
d: &mut minicbor::Decoder<'b>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<Self, minicbor::decode::Error> {
|
||||
let variant = d.u32()?;
|
||||
|
||||
match variant {
|
||||
|
|
@ -204,10 +208,11 @@ impl<'b> minicbor::decode::Decode<'b> for InstantaneousRewardSource {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for InstantaneousRewardSource {
|
||||
impl<C> minicbor::encode::Encode<C> for InstantaneousRewardSource {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
let variant = match self {
|
||||
Self::Reserves => 0,
|
||||
|
|
@ -226,35 +231,36 @@ pub enum InstantaneousRewardTarget {
|
|||
OtherAccountingPot(Coin),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for InstantaneousRewardTarget {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for InstantaneousRewardTarget {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
let datatype = d.datatype()?;
|
||||
|
||||
match datatype {
|
||||
minicbor::data::Type::Map | minicbor::data::Type::MapIndef => {
|
||||
let a = d.decode()?;
|
||||
let a = d.decode_with(ctx)?;
|
||||
Ok(Self::StakeCredentials(a))
|
||||
}
|
||||
_ => {
|
||||
let a = d.decode()?;
|
||||
let a = d.decode_with(ctx)?;
|
||||
Ok(Self::OtherAccountingPot(a))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for InstantaneousRewardTarget {
|
||||
impl<C> minicbor::encode::Encode<C> for InstantaneousRewardTarget {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
InstantaneousRewardTarget::StakeCredentials(a) => {
|
||||
a.encode(e)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
Ok(())
|
||||
}
|
||||
InstantaneousRewardTarget::OtherAccountingPot(a) => {
|
||||
a.encode(e)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
@ -285,15 +291,22 @@ pub enum Relay {
|
|||
MultiHostName(DnsName),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for Relay {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for Relay {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
let variant = d.u16()?;
|
||||
|
||||
match variant {
|
||||
0 => Ok(Relay::SingleHostAddr(d.decode()?, d.decode()?, d.decode()?)),
|
||||
1 => Ok(Relay::SingleHostName(d.decode()?, d.decode()?)),
|
||||
2 => Ok(Relay::MultiHostName(d.decode()?)),
|
||||
0 => Ok(Relay::SingleHostAddr(
|
||||
d.decode_with(ctx)?,
|
||||
d.decode_with(ctx)?,
|
||||
d.decode_with(ctx)?,
|
||||
)),
|
||||
1 => Ok(Relay::SingleHostName(
|
||||
d.decode_with(ctx)?,
|
||||
d.decode_with(ctx)?,
|
||||
)),
|
||||
2 => Ok(Relay::MultiHostName(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"invalid variant id for Relay",
|
||||
)),
|
||||
|
|
@ -301,33 +314,34 @@ impl<'b> minicbor::decode::Decode<'b> for Relay {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for Relay {
|
||||
impl<C> minicbor::encode::Encode<C> for Relay {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
Relay::SingleHostAddr(a, b, c) => {
|
||||
e.array(4)?;
|
||||
e.encode(0)?;
|
||||
e.encode(a)?;
|
||||
e.encode(b)?;
|
||||
e.encode(c)?;
|
||||
e.encode_with(0, ctx)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
e.encode_with(c, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Relay::SingleHostName(a, b) => {
|
||||
e.array(3)?;
|
||||
e.encode(1)?;
|
||||
e.encode(a)?;
|
||||
e.encode(b)?;
|
||||
e.encode_with(1, ctx)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Relay::MultiHostName(a) => {
|
||||
e.array(2)?;
|
||||
e.encode(2)?;
|
||||
e.encode(a)?;
|
||||
e.encode_with(2, ctx)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -355,28 +369,29 @@ pub struct RationalNumber {
|
|||
pub denominator: u64,
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for RationalNumber {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for RationalNumber {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.tag()?;
|
||||
d.array()?;
|
||||
|
||||
Ok(RationalNumber {
|
||||
numerator: d.decode()?,
|
||||
denominator: d.decode()?,
|
||||
numerator: d.decode_with(ctx)?,
|
||||
denominator: d.decode_with(ctx)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for RationalNumber {
|
||||
impl<C> minicbor::encode::Encode<C> for RationalNumber {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
// TODO: check if this is the correct tag
|
||||
e.tag(Tag::Unassigned(30))?;
|
||||
e.array(2)?;
|
||||
e.encode(self.numerator)?;
|
||||
e.encode(self.denominator)?;
|
||||
e.encode_with(self.numerator, ctx)?;
|
||||
e.encode_with(self.denominator, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -392,14 +407,14 @@ pub enum StakeCredential {
|
|||
Scripthash(Scripthash),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for StakeCredential {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for StakeCredential {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
let variant = d.u16()?;
|
||||
|
||||
match variant {
|
||||
0 => Ok(StakeCredential::AddrKeyhash(d.decode()?)),
|
||||
1 => Ok(StakeCredential::Scripthash(d.decode()?)),
|
||||
0 => Ok(StakeCredential::AddrKeyhash(d.decode_with(ctx)?)),
|
||||
1 => Ok(StakeCredential::Scripthash(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"invalid variant id for StakeCredential",
|
||||
)),
|
||||
|
|
@ -407,23 +422,24 @@ impl<'b> minicbor::decode::Decode<'b> for StakeCredential {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for StakeCredential {
|
||||
impl<C> minicbor::encode::Encode<C> for StakeCredential {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
StakeCredential::AddrKeyhash(a) => {
|
||||
e.array(2)?;
|
||||
e.encode(0)?;
|
||||
e.encode(a)?;
|
||||
e.encode_with(0, ctx)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
StakeCredential::Scripthash(a) => {
|
||||
e.array(2)?;
|
||||
e.encode(1)?;
|
||||
e.encode(a)?;
|
||||
e.encode_with(1, ctx)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -452,35 +468,35 @@ pub enum Certificate {
|
|||
MoveInstantaneousRewardsCert(MoveInstantaneousReward),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for Certificate {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for Certificate {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
let variant = d.u16()?;
|
||||
|
||||
match variant {
|
||||
0 => {
|
||||
let a = d.decode()?;
|
||||
let a = d.decode_with(ctx)?;
|
||||
Ok(Certificate::StakeRegistration(a))
|
||||
}
|
||||
1 => {
|
||||
let a = d.decode()?;
|
||||
let a = d.decode_with(ctx)?;
|
||||
Ok(Certificate::StakeDeregistration(a))
|
||||
}
|
||||
2 => {
|
||||
let a = d.decode()?;
|
||||
let b = d.decode()?;
|
||||
let a = d.decode_with(ctx)?;
|
||||
let b = d.decode_with(ctx)?;
|
||||
Ok(Certificate::StakeDelegation(a, b))
|
||||
}
|
||||
3 => {
|
||||
let operator = d.decode()?;
|
||||
let vrf_keyhash = d.decode()?;
|
||||
let pledge = d.decode()?;
|
||||
let cost = d.decode()?;
|
||||
let margin = d.decode()?;
|
||||
let reward_account = d.decode()?;
|
||||
let pool_owners = d.decode()?;
|
||||
let relays = d.decode()?;
|
||||
let pool_metadata = d.decode()?;
|
||||
let operator = d.decode_with(ctx)?;
|
||||
let vrf_keyhash = d.decode_with(ctx)?;
|
||||
let pledge = d.decode_with(ctx)?;
|
||||
let cost = d.decode_with(ctx)?;
|
||||
let margin = d.decode_with(ctx)?;
|
||||
let reward_account = d.decode_with(ctx)?;
|
||||
let pool_owners = d.decode_with(ctx)?;
|
||||
let relays = d.decode_with(ctx)?;
|
||||
let pool_metadata = d.decode_with(ctx)?;
|
||||
|
||||
Ok(Certificate::PoolRegistration {
|
||||
operator,
|
||||
|
|
@ -495,18 +511,18 @@ impl<'b> minicbor::decode::Decode<'b> for Certificate {
|
|||
})
|
||||
}
|
||||
4 => {
|
||||
let a = d.decode()?;
|
||||
let b = d.decode()?;
|
||||
let a = d.decode_with(ctx)?;
|
||||
let b = d.decode_with(ctx)?;
|
||||
Ok(Certificate::PoolRetirement(a, b))
|
||||
}
|
||||
5 => {
|
||||
let a = d.decode()?;
|
||||
let b = d.decode()?;
|
||||
let c = d.decode()?;
|
||||
let a = d.decode_with(ctx)?;
|
||||
let b = d.decode_with(ctx)?;
|
||||
let c = d.decode_with(ctx)?;
|
||||
Ok(Certificate::GenesisKeyDelegation(a, b, c))
|
||||
}
|
||||
6 => {
|
||||
let a = d.decode()?;
|
||||
let a = d.decode_with(ctx)?;
|
||||
Ok(Certificate::MoveInstantaneousRewardsCert(a))
|
||||
}
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
|
|
@ -516,31 +532,32 @@ impl<'b> minicbor::decode::Decode<'b> for Certificate {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for Certificate {
|
||||
impl<C> minicbor::encode::Encode<C> for Certificate {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
Certificate::StakeRegistration(a) => {
|
||||
e.array(2)?;
|
||||
e.u16(0)?;
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Certificate::StakeDeregistration(a) => {
|
||||
e.array(2)?;
|
||||
e.u16(1)?;
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Certificate::StakeDelegation(a, b) => {
|
||||
e.array(3)?;
|
||||
e.u16(2)?;
|
||||
e.encode(a)?;
|
||||
e.encode(b)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -558,39 +575,39 @@ impl minicbor::encode::Encode for Certificate {
|
|||
e.array(10)?;
|
||||
e.u16(3)?;
|
||||
|
||||
e.encode(operator)?;
|
||||
e.encode(vrf_keyhash)?;
|
||||
e.encode(pledge)?;
|
||||
e.encode(cost)?;
|
||||
e.encode(margin)?;
|
||||
e.encode(reward_account)?;
|
||||
e.encode(pool_owners)?;
|
||||
e.encode(relays)?;
|
||||
e.encode(pool_metadata)?;
|
||||
e.encode_with(operator, ctx)?;
|
||||
e.encode_with(vrf_keyhash, ctx)?;
|
||||
e.encode_with(pledge, ctx)?;
|
||||
e.encode_with(cost, ctx)?;
|
||||
e.encode_with(margin, ctx)?;
|
||||
e.encode_with(reward_account, ctx)?;
|
||||
e.encode_with(pool_owners, ctx)?;
|
||||
e.encode_with(relays, ctx)?;
|
||||
e.encode_with(pool_metadata, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Certificate::PoolRetirement(a, b) => {
|
||||
e.array(3)?;
|
||||
e.u16(4)?;
|
||||
e.encode(a)?;
|
||||
e.encode(b)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Certificate::GenesisKeyDelegation(a, b, c) => {
|
||||
e.array(4)?;
|
||||
e.u16(5)?;
|
||||
e.encode(a)?;
|
||||
e.encode(b)?;
|
||||
e.encode(c)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
e.encode_with(c, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Certificate::MoveInstantaneousRewardsCert(a) => {
|
||||
e.array(2)?;
|
||||
e.u16(6)?;
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -700,25 +717,25 @@ pub enum TransactionBodyComponent {
|
|||
NetworkId(NetworkId),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for TransactionBodyComponent {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
let key: u32 = d.decode()?;
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for TransactionBodyComponent {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
let key: u32 = d.decode_with(ctx)?;
|
||||
|
||||
match key {
|
||||
0 => Ok(Self::Inputs(d.decode()?)),
|
||||
1 => Ok(Self::Outputs(d.decode()?)),
|
||||
2 => Ok(Self::Fee(d.decode()?)),
|
||||
3 => Ok(Self::Ttl(d.decode()?)),
|
||||
4 => Ok(Self::Certificates(d.decode()?)),
|
||||
5 => Ok(Self::Withdrawals(d.decode()?)),
|
||||
6 => Ok(Self::Update(d.decode()?)),
|
||||
7 => Ok(Self::AuxiliaryDataHash(d.decode()?)),
|
||||
8 => Ok(Self::ValidityIntervalStart(d.decode()?)),
|
||||
9 => Ok(Self::Mint(d.decode()?)),
|
||||
11 => Ok(Self::ScriptDataHash(d.decode()?)),
|
||||
13 => Ok(Self::Collateral(d.decode()?)),
|
||||
14 => Ok(Self::RequiredSigners(d.decode()?)),
|
||||
15 => Ok(Self::NetworkId(d.decode()?)),
|
||||
0 => Ok(Self::Inputs(d.decode_with(ctx)?)),
|
||||
1 => Ok(Self::Outputs(d.decode_with(ctx)?)),
|
||||
2 => Ok(Self::Fee(d.decode_with(ctx)?)),
|
||||
3 => Ok(Self::Ttl(d.decode_with(ctx)?)),
|
||||
4 => Ok(Self::Certificates(d.decode_with(ctx)?)),
|
||||
5 => Ok(Self::Withdrawals(d.decode_with(ctx)?)),
|
||||
6 => Ok(Self::Update(d.decode_with(ctx)?)),
|
||||
7 => Ok(Self::AuxiliaryDataHash(d.decode_with(ctx)?)),
|
||||
8 => Ok(Self::ValidityIntervalStart(d.decode_with(ctx)?)),
|
||||
9 => Ok(Self::Mint(d.decode_with(ctx)?)),
|
||||
11 => Ok(Self::ScriptDataHash(d.decode_with(ctx)?)),
|
||||
13 => Ok(Self::Collateral(d.decode_with(ctx)?)),
|
||||
14 => Ok(Self::RequiredSigners(d.decode_with(ctx)?)),
|
||||
15 => Ok(Self::NetworkId(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"invalid map key for transaction body component",
|
||||
)),
|
||||
|
|
@ -726,67 +743,68 @@ impl<'b> minicbor::decode::Decode<'b> for TransactionBodyComponent {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for TransactionBodyComponent {
|
||||
impl<C> minicbor::encode::Encode<C> for TransactionBodyComponent {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
TransactionBodyComponent::Inputs(x) => {
|
||||
e.encode(0)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(0, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::Outputs(x) => {
|
||||
e.encode(1)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(1, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::Fee(x) => {
|
||||
e.encode(2)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(2, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::Ttl(x) => {
|
||||
e.encode(3)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(3, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::Certificates(x) => {
|
||||
e.encode(4)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(4, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::Withdrawals(x) => {
|
||||
e.encode(5)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(5, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::Update(x) => {
|
||||
e.encode(6)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(6, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::AuxiliaryDataHash(x) => {
|
||||
e.encode(7)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(7, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::ValidityIntervalStart(x) => {
|
||||
e.encode(8)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(8, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::Mint(x) => {
|
||||
e.encode(9)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(9, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::ScriptDataHash(x) => {
|
||||
e.encode(11)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(11, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::Collateral(x) => {
|
||||
e.encode(13)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(13, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::RequiredSigners(x) => {
|
||||
e.encode(14)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(14, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
TransactionBodyComponent::NetworkId(x) => {
|
||||
e.encode(15)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(15, ctx)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -807,24 +825,25 @@ impl Deref for TransactionBody {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for TransactionBody {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for TransactionBody {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
let len = d.map()?.unwrap_or_default();
|
||||
|
||||
let components: Result<_, _> = (0..len).map(|_| d.decode()).collect();
|
||||
let components: Result<_, _> = (0..len).map(|_| d.decode_with(ctx)).collect();
|
||||
|
||||
Ok(Self(components?))
|
||||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for TransactionBody {
|
||||
impl<C> minicbor::encode::Encode<C> for TransactionBody {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
e.map(self.0.len() as u64)?;
|
||||
for component in &self.0 {
|
||||
e.encode(component)?;
|
||||
e.encode_with(component, ctx)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
@ -850,18 +869,21 @@ pub enum NativeScript {
|
|||
InvalidHereafter(u64),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for NativeScript {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for NativeScript {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
let variant = d.u32()?;
|
||||
|
||||
match variant {
|
||||
0 => Ok(NativeScript::ScriptPubkey(d.decode()?)),
|
||||
1 => Ok(NativeScript::ScriptAll(d.decode()?)),
|
||||
2 => Ok(NativeScript::ScriptAny(d.decode()?)),
|
||||
3 => Ok(NativeScript::ScriptNOfK(d.decode()?, d.decode()?)),
|
||||
4 => Ok(NativeScript::InvalidBefore(d.decode()?)),
|
||||
5 => Ok(NativeScript::InvalidHereafter(d.decode()?)),
|
||||
0 => Ok(NativeScript::ScriptPubkey(d.decode_with(ctx)?)),
|
||||
1 => Ok(NativeScript::ScriptAll(d.decode_with(ctx)?)),
|
||||
2 => Ok(NativeScript::ScriptAny(d.decode_with(ctx)?)),
|
||||
3 => Ok(NativeScript::ScriptNOfK(
|
||||
d.decode_with(ctx)?,
|
||||
d.decode_with(ctx)?,
|
||||
)),
|
||||
4 => Ok(NativeScript::InvalidBefore(d.decode_with(ctx)?)),
|
||||
5 => Ok(NativeScript::InvalidHereafter(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"unknown variant id for native script",
|
||||
)),
|
||||
|
|
@ -869,38 +891,39 @@ impl<'b> minicbor::decode::Decode<'b> for NativeScript {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for NativeScript {
|
||||
impl<C> minicbor::encode::Encode<C> for NativeScript {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
e.array(2)?;
|
||||
|
||||
match self {
|
||||
NativeScript::ScriptPubkey(v) => {
|
||||
e.encode(0)?;
|
||||
e.encode(v)?;
|
||||
e.encode_with(0, ctx)?;
|
||||
e.encode_with(v, ctx)?;
|
||||
}
|
||||
NativeScript::ScriptAll(v) => {
|
||||
e.encode(1)?;
|
||||
e.encode(v)?;
|
||||
e.encode_with(1, ctx)?;
|
||||
e.encode_with(v, ctx)?;
|
||||
}
|
||||
NativeScript::ScriptAny(v) => {
|
||||
e.encode(2)?;
|
||||
e.encode(v)?;
|
||||
e.encode_with(2, ctx)?;
|
||||
e.encode_with(v, ctx)?;
|
||||
}
|
||||
NativeScript::ScriptNOfK(a, b) => {
|
||||
e.encode(3)?;
|
||||
e.encode(a)?;
|
||||
e.encode(b)?;
|
||||
e.encode_with(3, ctx)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
}
|
||||
NativeScript::InvalidBefore(v) => {
|
||||
e.encode(4)?;
|
||||
e.encode(v)?;
|
||||
e.encode_with(4, ctx)?;
|
||||
e.encode_with(v, ctx)?;
|
||||
}
|
||||
NativeScript::InvalidHereafter(v) => {
|
||||
e.encode(5)?;
|
||||
e.encode(v)?;
|
||||
e.encode_with(5, ctx)?;
|
||||
e.encode_with(v, ctx)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -931,8 +954,8 @@ pub enum BigInt {
|
|||
BigNInt(ByteVec),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for BigInt {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for BigInt {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
let datatype = d.datatype()?;
|
||||
|
||||
match datatype {
|
||||
|
|
@ -943,13 +966,13 @@ impl<'b> minicbor::decode::Decode<'b> for BigInt {
|
|||
| minicbor::data::Type::I8
|
||||
| minicbor::data::Type::I16
|
||||
| minicbor::data::Type::I32
|
||||
| minicbor::data::Type::I64 => Ok(Self::Int(d.decode()?)),
|
||||
| minicbor::data::Type::I64 => Ok(Self::Int(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::Tag => {
|
||||
let tag = d.tag()?;
|
||||
|
||||
match tag {
|
||||
minicbor::data::Tag::PosBignum => Ok(Self::BigUInt(d.decode()?)),
|
||||
minicbor::data::Tag::NegBignum => Ok(Self::BigNInt(d.decode()?)),
|
||||
minicbor::data::Tag::PosBignum => Ok(Self::BigUInt(d.decode_with(ctx)?)),
|
||||
minicbor::data::Tag::NegBignum => Ok(Self::BigNInt(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"invalid cbor tag for big int",
|
||||
)),
|
||||
|
|
@ -962,22 +985,23 @@ impl<'b> minicbor::decode::Decode<'b> for BigInt {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for BigInt {
|
||||
impl<C> minicbor::encode::Encode<C> for BigInt {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
BigInt::Int(x) => {
|
||||
e.encode(x)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
BigInt::BigUInt(x) => {
|
||||
e.tag(Tag::PosBignum)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
BigInt::BigNInt(x) => {
|
||||
e.tag(Tag::NegBignum)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -995,8 +1019,8 @@ pub enum PlutusData {
|
|||
ArrayIndef(MaybeIndefArray<PlutusData>),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::decode::Decode<'b> for PlutusData {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::decode::Decode<'b, C> for PlutusData {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
let type_ = d.datatype()?;
|
||||
|
||||
match type_ {
|
||||
|
|
@ -1005,8 +1029,10 @@ impl<'b> minicbor::decode::Decode<'b> for PlutusData {
|
|||
let tag = probe.tag()?;
|
||||
|
||||
match tag {
|
||||
Tag::Unassigned(121..=127 | 1280..=1400 | 102) => Ok(Self::Constr(d.decode()?)),
|
||||
Tag::PosBignum | Tag::NegBignum => Ok(Self::BigInt(d.decode()?)),
|
||||
Tag::Unassigned(121..=127 | 1280..=1400 | 102) => {
|
||||
Ok(Self::Constr(d.decode_with(ctx)?))
|
||||
}
|
||||
Tag::PosBignum | Tag::NegBignum => Ok(Self::BigInt(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"unknown tag for plutus data tag",
|
||||
)),
|
||||
|
|
@ -1019,12 +1045,12 @@ impl<'b> minicbor::decode::Decode<'b> for PlutusData {
|
|||
| minicbor::data::Type::I8
|
||||
| minicbor::data::Type::I16
|
||||
| minicbor::data::Type::I32
|
||||
| minicbor::data::Type::I64 => Ok(Self::BigInt(d.decode()?)),
|
||||
minicbor::data::Type::Map => Ok(Self::Map(d.decode()?)),
|
||||
minicbor::data::Type::Bytes => Ok(Self::BoundedBytes(d.decode()?)),
|
||||
minicbor::data::Type::BytesIndef => Ok(Self::BoundedBytes(d.decode()?)),
|
||||
minicbor::data::Type::Array => Ok(Self::Array(d.decode()?)),
|
||||
minicbor::data::Type::ArrayIndef => Ok(Self::ArrayIndef(d.decode()?)),
|
||||
| minicbor::data::Type::I64 => Ok(Self::BigInt(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::Map => Ok(Self::Map(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::Bytes => Ok(Self::BoundedBytes(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::BytesIndef => Ok(Self::BoundedBytes(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::Array => Ok(Self::Array(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::ArrayIndef => Ok(Self::ArrayIndef(d.decode_with(ctx)?)),
|
||||
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"bad cbor data type for plutus data",
|
||||
|
|
@ -1033,29 +1059,30 @@ impl<'b> minicbor::decode::Decode<'b> for PlutusData {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::encode::Encode for PlutusData {
|
||||
impl<C> minicbor::encode::Encode<C> for PlutusData {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
Self::Constr(a) => {
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
}
|
||||
Self::Map(a) => {
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
}
|
||||
Self::BigInt(a) => {
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
}
|
||||
Self::BoundedBytes(a) => {
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
}
|
||||
Self::Array(a) => {
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
}
|
||||
Self::ArrayIndef(a) => {
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1070,18 +1097,18 @@ pub struct Constr<A> {
|
|||
pub fields: MaybeIndefArray<A>,
|
||||
}
|
||||
|
||||
impl<'b, A> minicbor::decode::Decode<'b> for Constr<A>
|
||||
impl<'b, C, A> minicbor::decode::Decode<'b, C> for Constr<A>
|
||||
where
|
||||
A: minicbor::decode::Decode<'b>,
|
||||
A: minicbor::decode::Decode<'b, C>,
|
||||
{
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
let tag = d.tag()?;
|
||||
|
||||
match tag {
|
||||
Tag::Unassigned(x) => match x {
|
||||
121..=127 | 1280..=1400 => Ok(Constr {
|
||||
tag: x,
|
||||
fields: d.decode()?,
|
||||
fields: d.decode_with(ctx)?,
|
||||
any_constructor: None,
|
||||
}),
|
||||
102 => {
|
||||
|
|
@ -1089,8 +1116,8 @@ where
|
|||
|
||||
Ok(Constr {
|
||||
tag: x,
|
||||
any_constructor: Some(d.decode()?),
|
||||
fields: d.decode()?,
|
||||
any_constructor: Some(d.decode_with(ctx)?),
|
||||
fields: d.decode_with(ctx)?,
|
||||
})
|
||||
}
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
|
|
@ -1104,26 +1131,27 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<A> minicbor::encode::Encode for Constr<A>
|
||||
impl<C, A> minicbor::encode::Encode<C> for Constr<A>
|
||||
where
|
||||
A: minicbor::encode::Encode,
|
||||
A: minicbor::encode::Encode<C>,
|
||||
{
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
e.tag(Tag::Unassigned(self.tag))?;
|
||||
|
||||
match self.tag {
|
||||
102 => {
|
||||
e.array(2)?;
|
||||
e.encode(self.any_constructor.unwrap_or_default())?;
|
||||
e.encode(&self.fields)?;
|
||||
e.encode_with(self.any_constructor.unwrap_or_default(), ctx)?;
|
||||
e.encode_with(&self.fields, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
_ => {
|
||||
e.encode(&self.fields)?;
|
||||
e.encode_with(&self.fields, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1240,8 +1268,8 @@ pub enum Metadatum {
|
|||
Map(KeyValuePairs<Metadatum, Metadatum>),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::Decode<'b> for Metadatum {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::Decode<'b, C> for Metadatum {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
match d.datatype()? {
|
||||
minicbor::data::Type::U8 => {
|
||||
let i = d.u8()?;
|
||||
|
|
@ -1279,10 +1307,10 @@ impl<'b> minicbor::Decode<'b> for Metadatum {
|
|||
let i = d.int()?;
|
||||
Ok(Metadatum::Int(i))
|
||||
}
|
||||
minicbor::data::Type::Bytes => Ok(Metadatum::Bytes(d.decode()?)),
|
||||
minicbor::data::Type::String => Ok(Metadatum::Text(d.decode()?)),
|
||||
minicbor::data::Type::Array => Ok(Metadatum::Array(d.decode()?)),
|
||||
minicbor::data::Type::Map => Ok(Metadatum::Map(d.decode()?)),
|
||||
minicbor::data::Type::Bytes => Ok(Metadatum::Bytes(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::String => Ok(Metadatum::Text(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::Array => Ok(Metadatum::Array(d.decode_with(ctx)?)),
|
||||
minicbor::data::Type::Map => Ok(Metadatum::Map(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"Can't turn data type into metadatum",
|
||||
)),
|
||||
|
|
@ -1290,26 +1318,27 @@ impl<'b> minicbor::Decode<'b> for Metadatum {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::Encode for Metadatum {
|
||||
impl<C> minicbor::Encode<C> for Metadatum {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
Metadatum::Int(a) => {
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
}
|
||||
Metadatum::Bytes(a) => {
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
}
|
||||
Metadatum::Text(a) => {
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
}
|
||||
Metadatum::Array(a) => {
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
}
|
||||
Metadatum::Map(a) => {
|
||||
e.encode(a)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -1331,16 +1360,16 @@ pub enum AuxiliaryData {
|
|||
Alonzo(AlonzoAuxiliaryData),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::Decode<'b> for AuxiliaryData {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::Decode<'b, C> for AuxiliaryData {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
match d.datatype()? {
|
||||
minicbor::data::Type::Map | minicbor::data::Type::MapIndef => {
|
||||
Ok(AuxiliaryData::Shelley(d.decode()?))
|
||||
Ok(AuxiliaryData::Shelley(d.decode_with(ctx)?))
|
||||
}
|
||||
minicbor::data::Type::Array => {
|
||||
d.array()?;
|
||||
let transaction_metadata = d.decode()?;
|
||||
let auxiliary_scripts = d.decode()?;
|
||||
let transaction_metadata = d.decode_with(ctx)?;
|
||||
let auxiliary_scripts = d.decode_with(ctx)?;
|
||||
Ok(AuxiliaryData::ShelleyMa {
|
||||
transaction_metadata,
|
||||
auxiliary_scripts,
|
||||
|
|
@ -1348,7 +1377,7 @@ impl<'b> minicbor::Decode<'b> for AuxiliaryData {
|
|||
}
|
||||
minicbor::data::Type::Tag => {
|
||||
d.tag()?;
|
||||
Ok(AuxiliaryData::Alonzo(d.decode()?))
|
||||
Ok(AuxiliaryData::Alonzo(d.decode_with(ctx)?))
|
||||
}
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"Can't infer variant from data type for AuxiliaryData",
|
||||
|
|
@ -1357,27 +1386,28 @@ impl<'b> minicbor::Decode<'b> for AuxiliaryData {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::Encode for AuxiliaryData {
|
||||
impl<C> minicbor::Encode<C> for AuxiliaryData {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
AuxiliaryData::Shelley(m) => {
|
||||
e.encode(m)?;
|
||||
e.encode_with(m, ctx)?;
|
||||
}
|
||||
AuxiliaryData::ShelleyMa {
|
||||
transaction_metadata,
|
||||
auxiliary_scripts,
|
||||
} => {
|
||||
e.array(2)?;
|
||||
e.encode(transaction_metadata)?;
|
||||
e.encode(auxiliary_scripts)?;
|
||||
e.encode_with(transaction_metadata, ctx)?;
|
||||
e.encode_with(auxiliary_scripts, ctx)?;
|
||||
}
|
||||
AuxiliaryData::Alonzo(v) => {
|
||||
// TODO: check if this is the correct tag
|
||||
e.tag(Tag::Unassigned(259))?;
|
||||
e.encode(v)?;
|
||||
e.encode_with(v, ctx)?;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -57,13 +57,13 @@ pub enum AddrDistr {
|
|||
Variant1,
|
||||
}
|
||||
|
||||
impl<'b> minicbor::Decode<'b> for AddrDistr {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::Decode<'b, C> for AddrDistr {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
let variant = d.u32()?;
|
||||
|
||||
match variant {
|
||||
0 => Ok(AddrDistr::Variant0(d.decode()?)),
|
||||
0 => Ok(AddrDistr::Variant0(d.decode_with(ctx)?)),
|
||||
1 => Ok(AddrDistr::Variant1),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"invalid variant for addrdstr",
|
||||
|
|
@ -72,10 +72,11 @@ impl<'b> minicbor::Decode<'b> for AddrDistr {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::Encode for AddrDistr {
|
||||
impl minicbor::Encode<()> for AddrDistr {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
AddrDistr::Variant0(x) => {
|
||||
|
|
@ -103,8 +104,11 @@ pub enum AddrType {
|
|||
Other(u64),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::Decode<'b> for AddrType {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::Decode<'b, C> for AddrType {
|
||||
fn decode(
|
||||
d: &mut minicbor::Decoder<'b>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<Self, minicbor::decode::Error> {
|
||||
let variant = d.u64()?;
|
||||
|
||||
match variant {
|
||||
|
|
@ -116,10 +120,11 @@ impl<'b> minicbor::Decode<'b> for AddrType {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::Encode for AddrType {
|
||||
impl<C> minicbor::Encode<C> for AddrType {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
AddrType::PubKey => e.u64(0)?,
|
||||
|
|
@ -139,22 +144,23 @@ pub enum AddrAttrProperty {
|
|||
Unparsed(u8, ByteVec),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::Decode<'b> for AddrAttrProperty {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::Decode<'b, C> for AddrAttrProperty {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
let key = d.u8()?;
|
||||
|
||||
match key {
|
||||
0 => Ok(AddrAttrProperty::AddrDistr(d.decode()?)),
|
||||
1 => Ok(AddrAttrProperty::Bytes(d.decode()?)),
|
||||
x => Ok(AddrAttrProperty::Unparsed(x, d.decode()?)),
|
||||
0 => Ok(AddrAttrProperty::AddrDistr(d.decode_with(ctx)?)),
|
||||
1 => Ok(AddrAttrProperty::Bytes(d.decode_with(ctx)?)),
|
||||
x => Ok(AddrAttrProperty::Unparsed(x, d.decode_with(ctx)?)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl minicbor::Encode for AddrAttrProperty {
|
||||
impl<C> minicbor::Encode<C> for AddrAttrProperty {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
AddrAttrProperty::AddrDistr(x) => {
|
||||
|
|
@ -224,36 +230,37 @@ pub enum TxIn {
|
|||
Other(u8, ByteVec),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::Decode<'b> for TxIn {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::Decode<'b, C> for TxIn {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
|
||||
let variant = d.u8()?;
|
||||
|
||||
match variant {
|
||||
0 => Ok(TxIn::Variant0(d.decode()?)),
|
||||
x => Ok(TxIn::Other(x, d.decode()?)),
|
||||
0 => Ok(TxIn::Variant0(d.decode_with(ctx)?)),
|
||||
x => Ok(TxIn::Other(x, d.decode_with(ctx)?)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl minicbor::Encode for TxIn {
|
||||
impl<C> minicbor::Encode<C> for TxIn {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
TxIn::Variant0(x) => {
|
||||
e.array(2)?;
|
||||
e.u8(0)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
TxIn::Other(a, b) => {
|
||||
e.array(2)?;
|
||||
e.u8(*a)?;
|
||||
e.encode(b)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -295,38 +302,39 @@ pub enum Twit {
|
|||
Other(u8, ByteVec),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::Decode<'b> for Twit {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::Decode<'b, C> for Twit {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
|
||||
let variant = d.u8()?;
|
||||
|
||||
match variant {
|
||||
0 => Ok(Twit::PkWitness(d.decode()?)),
|
||||
1 => Ok(Twit::ScriptWitness(d.decode()?)),
|
||||
2 => Ok(Twit::RedeemWitness(d.decode()?)),
|
||||
x => Ok(Twit::Other(x, d.decode()?)),
|
||||
0 => Ok(Twit::PkWitness(d.decode_with(ctx)?)),
|
||||
1 => Ok(Twit::ScriptWitness(d.decode_with(ctx)?)),
|
||||
2 => Ok(Twit::RedeemWitness(d.decode_with(ctx)?)),
|
||||
x => Ok(Twit::Other(x, d.decode_with(ctx)?)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl minicbor::Encode for Twit {
|
||||
impl<C> minicbor::Encode<C> for Twit {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
Twit::PkWitness(x) => {
|
||||
e.array(2)?;
|
||||
e.u8(0)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Twit::ScriptWitness(x) => {
|
||||
e.array(2)?;
|
||||
e.u8(1)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -407,56 +415,57 @@ pub enum Ssc {
|
|||
Variant3(SscCerts),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::Decode<'b> for Ssc {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::Decode<'b, C> for Ssc {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
|
||||
let variant = d.u8()?;
|
||||
|
||||
match variant {
|
||||
0 => Ok(Ssc::Variant0(d.decode()?, d.decode()?)),
|
||||
1 => Ok(Ssc::Variant1(d.decode()?, d.decode()?)),
|
||||
2 => Ok(Ssc::Variant2(d.decode()?, d.decode()?)),
|
||||
3 => Ok(Ssc::Variant3(d.decode()?)),
|
||||
0 => Ok(Ssc::Variant0(d.decode_with(ctx)?, d.decode_with(ctx)?)),
|
||||
1 => Ok(Ssc::Variant1(d.decode_with(ctx)?, d.decode_with(ctx)?)),
|
||||
2 => Ok(Ssc::Variant2(d.decode_with(ctx)?, d.decode_with(ctx)?)),
|
||||
3 => Ok(Ssc::Variant3(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message("invalid variant for ssc")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl minicbor::Encode for Ssc {
|
||||
impl<C> minicbor::Encode<C> for Ssc {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
Ssc::Variant0(a, b) => {
|
||||
e.array(3)?;
|
||||
e.u8(0)?;
|
||||
e.encode(a)?;
|
||||
e.encode(b)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Ssc::Variant1(a, b) => {
|
||||
e.array(3)?;
|
||||
e.u8(1)?;
|
||||
e.encode(a)?;
|
||||
e.encode(b)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Ssc::Variant2(a, b) => {
|
||||
e.array(3)?;
|
||||
e.u8(2)?;
|
||||
e.encode(a)?;
|
||||
e.encode(b)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Ssc::Variant3(x) => {
|
||||
e.array(2)?;
|
||||
e.u8(3)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -472,17 +481,17 @@ pub enum SscProof {
|
|||
Variant3(ByronHash),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::Decode<'b> for SscProof {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::Decode<'b, C> for SscProof {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
|
||||
let variant = d.u8()?;
|
||||
|
||||
match variant {
|
||||
0 => Ok(SscProof::Variant0(d.decode()?, d.decode()?)),
|
||||
1 => Ok(SscProof::Variant1(d.decode()?, d.decode()?)),
|
||||
2 => Ok(SscProof::Variant2(d.decode()?, d.decode()?)),
|
||||
3 => Ok(SscProof::Variant3(d.decode()?)),
|
||||
0 => Ok(SscProof::Variant0(d.decode_with(ctx)?, d.decode_with(ctx)?)),
|
||||
1 => Ok(SscProof::Variant1(d.decode_with(ctx)?, d.decode_with(ctx)?)),
|
||||
2 => Ok(SscProof::Variant2(d.decode_with(ctx)?, d.decode_with(ctx)?)),
|
||||
3 => Ok(SscProof::Variant3(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"invalid variant for sscproof",
|
||||
)),
|
||||
|
|
@ -490,40 +499,41 @@ impl<'b> minicbor::Decode<'b> for SscProof {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::Encode for SscProof {
|
||||
impl<C> minicbor::Encode<C> for SscProof {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
SscProof::Variant0(a, b) => {
|
||||
e.array(3)?;
|
||||
e.u8(0)?;
|
||||
e.encode(a)?;
|
||||
e.encode(b)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
SscProof::Variant1(a, b) => {
|
||||
e.array(3)?;
|
||||
e.u8(1)?;
|
||||
e.encode(a)?;
|
||||
e.encode(b)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
SscProof::Variant2(a, b) => {
|
||||
e.array(3)?;
|
||||
e.u8(2)?;
|
||||
e.encode(a)?;
|
||||
e.encode(b)?;
|
||||
e.encode_with(a, ctx)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
SscProof::Variant3(x) => {
|
||||
e.array(2)?;
|
||||
e.u8(3)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -580,36 +590,37 @@ pub enum TxFeePol {
|
|||
Other(u8, ByteVec),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::Decode<'b> for TxFeePol {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::Decode<'b, C> for TxFeePol {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
|
||||
let variant = d.u8()?;
|
||||
|
||||
match variant {
|
||||
0 => Ok(TxFeePol::Variant0(d.decode()?)),
|
||||
x => Ok(TxFeePol::Other(x, d.decode()?)),
|
||||
0 => Ok(TxFeePol::Variant0(d.decode_with(ctx)?)),
|
||||
x => Ok(TxFeePol::Other(x, d.decode_with(ctx)?)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl minicbor::Encode for TxFeePol {
|
||||
impl<C> minicbor::Encode<C> for TxFeePol {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
TxFeePol::Variant0(x) => {
|
||||
e.array(2)?;
|
||||
e.u8(0)?;
|
||||
e.encode(x)?;
|
||||
e.encode_with(x, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
TxFeePol::Other(a, b) => {
|
||||
e.array(2)?;
|
||||
e.u8(*a)?;
|
||||
e.encode(b)?;
|
||||
e.encode_with(b, ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -725,16 +736,16 @@ pub enum BlockSig {
|
|||
DlgSig(DlgSig),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::Decode<'b> for BlockSig {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::Decode<'b, C> for BlockSig {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
|
||||
let variant = d.u8()?;
|
||||
|
||||
match variant {
|
||||
0 => Ok(BlockSig::Signature(d.decode()?)),
|
||||
1 => Ok(BlockSig::LwdlgSig(d.decode()?)),
|
||||
2 => Ok(BlockSig::DlgSig(d.decode()?)),
|
||||
0 => Ok(BlockSig::Signature(d.decode_with(ctx)?)),
|
||||
1 => Ok(BlockSig::LwdlgSig(d.decode_with(ctx)?)),
|
||||
2 => Ok(BlockSig::DlgSig(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"unknown variant for blocksig",
|
||||
)),
|
||||
|
|
@ -742,10 +753,11 @@ impl<'b> minicbor::Decode<'b> for BlockSig {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::Encode for BlockSig {
|
||||
impl<C> minicbor::Encode<C> for BlockSig {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
_ctx: &mut C,
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
BlockSig::Signature(x) => {
|
||||
|
|
@ -914,15 +926,15 @@ pub enum Block {
|
|||
EbBlock(EbBlock),
|
||||
}
|
||||
|
||||
impl<'b> minicbor::Decode<'b> for Block {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>) -> Result<Self, minicbor::decode::Error> {
|
||||
impl<'b, C> minicbor::Decode<'b, C> for Block {
|
||||
fn decode(d: &mut minicbor::Decoder<'b>, ctx: &mut C) -> Result<Self, minicbor::decode::Error> {
|
||||
d.array()?;
|
||||
|
||||
let variant = d.u32()?;
|
||||
|
||||
match variant {
|
||||
0 => Ok(Block::EbBlock(d.decode()?)),
|
||||
1 => Ok(Block::MainBlock(d.decode()?)),
|
||||
0 => Ok(Block::EbBlock(d.decode_with(ctx)?)),
|
||||
1 => Ok(Block::MainBlock(d.decode_with(ctx)?)),
|
||||
_ => Err(minicbor::decode::Error::message(
|
||||
"unknown variant for block",
|
||||
)),
|
||||
|
|
@ -930,10 +942,11 @@ impl<'b> minicbor::Decode<'b> for Block {
|
|||
}
|
||||
}
|
||||
|
||||
impl minicbor::Encode for Block {
|
||||
impl minicbor::Encode<()> for Block {
|
||||
fn encode<W: minicbor::encode::Write>(
|
||||
&self,
|
||||
e: &mut minicbor::Encoder<W>,
|
||||
_ctx: &mut (),
|
||||
) -> Result<(), minicbor::encode::Error<W::Error>> {
|
||||
match self {
|
||||
Block::EbBlock(x) => {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ where
|
|||
|
||||
impl<'a, T> Fragment<'a> for T
|
||||
where
|
||||
T: Encode + Decode<'a> + Sized,
|
||||
T: Encode<()> + Decode<'a, ()> + Sized,
|
||||
{
|
||||
fn encode_fragment(&self) -> Result<Vec<u8>, Error> {
|
||||
to_vec(self).map_err(|e| e.into())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue