From ceb6d63e956deb3abb1971709c6cbf00f8894a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=BCndler?= Date: Fri, 8 Dec 2023 22:50:41 +0100 Subject: [PATCH] Add parsing for big builtins --- crates/uplc/src/parser.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/uplc/src/parser.rs b/crates/uplc/src/parser.rs index 2a0d3924..c39aa06e 100644 --- a/crates/uplc/src/parser.rs +++ b/crates/uplc/src/parser.rs @@ -251,7 +251,14 @@ peg::parser! { PlutusData::Map(pallas_codec::utils::KeyValuePairs::Def(kvps)) } / _* "List" _+ ls:plutus_list() { PlutusData::Array(ls) } - / _* "I" _+ n:number() {? Ok(PlutusData::BigInt(pallas_primitives::babbage::BigInt::Int(i64::try_from(n).or(Err("int"))?.into()))) } + / _* "I" _+ n:big_number() { match i64::try_from(n.clone()) { + Ok(n) => PlutusData::BigInt(pallas_primitives::alonzo::BigInt::Int(n.into())), + Err(_) => if n < 0.into() { + PlutusData::BigInt(pallas_primitives::babbage::BigInt::BigNInt(n.to_bytes_be().1.into())) + } else { + PlutusData::BigInt(pallas_primitives::babbage::BigInt::BigUInt(n.to_bytes_be().1.into())) + } + } } / _* "B" _+ "#" i:ident()* {? Ok(PlutusData::BoundedBytes( hex::decode(String::from_iter(i)).or(Err("bytes"))?.into()