From 799546b6549824f0ab248404289e1f668dd85ee7 Mon Sep 17 00:00:00 2001 From: KtorZ Date: Fri, 13 Sep 2024 18:33:23 +0200 Subject: [PATCH] Show strings as UTF-8 text string during type reification Instead of defaulting to hex-encoded bytearrays. --- crates/aiken-lang/src/expr.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/aiken-lang/src/expr.rs b/crates/aiken-lang/src/expr.rs index b04c29b0..d5e19f97 100644 --- a/crates/aiken-lang/src/expr.rs +++ b/crates/aiken-lang/src/expr.rs @@ -1063,11 +1063,20 @@ impl UntypedExpr { value: from_pallas_bigint(i).to_string(), }), - PlutusData::BoundedBytes(bytes) => Ok(UntypedExpr::ByteArray { - location: Span::empty(), - bytes: bytes.into(), - preferred_format: ByteArrayFormatPreference::HexadecimalString, - }), + PlutusData::BoundedBytes(bytes) => { + if tipo.is_string() { + Ok(UntypedExpr::String { + location: Span::empty(), + value: String::from_utf8(bytes.to_vec()).expect("invalid UTF-8 string"), + }) + } else { + Ok(UntypedExpr::ByteArray { + location: Span::empty(), + bytes: bytes.into(), + preferred_format: ByteArrayFormatPreference::HexadecimalString, + }) + } + } PlutusData::Array(args) => match tipo { Type::App {