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