feat: decode plutus data
This commit is contained in:
parent
fa3c88a31e
commit
e8f783e7bb
|
@ -5,7 +5,7 @@ use flat_rs::{
|
||||||
en::{self, Encode, Encoder},
|
en::{self, Encode, Encoder},
|
||||||
Flat,
|
Flat,
|
||||||
};
|
};
|
||||||
use pallas_primitives::Fragment;
|
use pallas_primitives::{babbage::PlutusData, Fragment};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{
|
ast::{
|
||||||
|
@ -302,6 +302,14 @@ impl<'b> Decode<'b> for Constant {
|
||||||
2 => Ok(Constant::String(String::decode(d)?)),
|
2 => Ok(Constant::String(String::decode(d)?)),
|
||||||
3 => Ok(Constant::Unit),
|
3 => Ok(Constant::Unit),
|
||||||
4 => Ok(Constant::Bool(bool::decode(d)?)),
|
4 => Ok(Constant::Bool(bool::decode(d)?)),
|
||||||
|
8 => {
|
||||||
|
let cbor = Vec::<u8>::decode(d)?;
|
||||||
|
|
||||||
|
let data = PlutusData::decode_fragment(&cbor)
|
||||||
|
.map_err(|err| de::Error::Message(err.to_string()))?;
|
||||||
|
|
||||||
|
Ok(Constant::Data(data))
|
||||||
|
}
|
||||||
x => Err(de::Error::Message(format!(
|
x => Err(de::Error::Message(format!(
|
||||||
"Unknown constant constructor tag: {}",
|
"Unknown constant constructor tag: {}",
|
||||||
x
|
x
|
||||||
|
|
Loading…
Reference in New Issue