remove extra dependencies and return result for data encode/decode

This commit is contained in:
Kasey White
2022-08-29 14:03:07 -04:00
committed by Kasey White
parent 65b133251a
commit 2d1f147d40
5 changed files with 32 additions and 13 deletions

View File

@@ -13,5 +13,4 @@ authors = ["Lucas Rosa <x@rvcas.dev>", "Kasey White <kwhitemsg@gmail.com>"]
[dependencies]
anyhow = "1.0.57"
clap = { version = "3.1.14", features = ["derive"] }
hex = "0.4.3"
uplc = { path = '../uplc', version = "0.0.10" }

View File

@@ -16,7 +16,7 @@ exclude = ["test_data/*"]
cryptoxide = "0.4.2"
flat-rs = { path = "../flat", version = "0.0.10" }
hex = "0.4.3"
minicbor = { version = "0.17.1", features = ["std"] }
minicbor = { version = "0.18.0", features = ["std"] }
pallas-codec = "0.12.0"
pallas-primitives = "0.12.0"
peg = "0.8.0"

View File

@@ -8,12 +8,13 @@ mod pretty;
pub mod program_builder;
pub use pallas_primitives::alonzo::PlutusData;
pub type Error = Box<dyn std::error::Error>;
use pallas_primitives::Fragment;
pub fn plutus_data(bytes: &[u8]) -> PlutusData {
PlutusData::decode_fragment(bytes).unwrap()
pub fn plutus_data(bytes: &[u8]) -> Result<PlutusData, Error> {
PlutusData::decode_fragment(bytes)
}
pub fn plutus_data_to_bytes(data: &PlutusData) -> Vec<u8> {
PlutusData::encode_fragment(data).unwrap()
pub fn plutus_data_to_bytes(data: &PlutusData) -> Result<Vec<u8>, Error> {
PlutusData::encode_fragment(data)
}

View File

@@ -227,9 +227,9 @@ impl Constant {
.append((*right).to_doc_list())
.append(RcDoc::text(")")),
Constant::Data(data) => {
RcDoc::text("#").append(RcDoc::text(hex::encode(plutus_data_to_bytes(data))))
}
Constant::Data(data) => RcDoc::text("#").append(RcDoc::text(hex::encode(
plutus_data_to_bytes(data).unwrap(),
))),
}
}
}