Repository: ergoplatform/sigma-rust (language: rust)

Issue:
Parsing tuple expression as constants from base16 bytes in bindings
It was missed in #700.


Discussion / hints:

Fix patch:
diff --git a/bindings/ergo-lib-c-core/src/constant.rs b/bindings/ergo-lib-c-core/src/constant.rs
index 0142a69a3..d51d45763 100644
--- a/bindings/ergo-lib-c-core/src/constant.rs
+++ b/bindings/ergo-lib-c-core/src/constant.rs
@@ -11,6 +11,7 @@ use ergo_lib::{
     ergo_chain_types::{Base16DecodedBytes, EcPoint},
     ergotree_ir::{
         base16_str::Base16Str,
+        chain::ergo_box::RegisterValue,
         mir::constant::{TryExtractFrom, TryExtractInto},
         serialization::SigmaSerializable,
         sigma_protocol::sigma_boolean::ProveDlog,
@@ -30,8 +31,9 @@ pub unsafe fn constant_from_base16_bytes(
 ) -> Result<(), Error> {
     let constant_out = mut_ptr_as_mut(constant_out, "constant_out")?;
     let bytes = Base16DecodedBytes::try_from(bytes_str.to_string())?;
-    let constant = ergo_lib::ergotree_ir::mir::constant::Constant::try_from(bytes).map(Constant)?;
-    *constant_out = Box::into_raw(Box::new(constant));
+    let register_value = RegisterValue::sigma_parse_bytes(bytes.as_ref());
+    let constant = register_value.as_constant()?.clone();
+    *constant_out = Box::into_raw(Box::new(Constant(constant)));
     Ok(())
 }
 
diff --git a/bindings/ergo-lib-wasm/src/ast.rs b/bindings/ergo-lib-wasm/src/ast.rs
index a5b90da05..4968fc528 100644
--- a/bindings/ergo-lib-wasm/src/ast.rs
+++ b/bindings/ergo-lib-wasm/src/ast.rs
@@ -8,6 +8,7 @@ use crate::utils::I64;
 use ergo_lib::ergo_chain_types::Base16DecodedBytes;
 use ergo_lib::ergo_chain_types::EcPoint;
 use ergo_lib::ergotree_ir::base16_str::Base16Str;
+use ergo_lib::ergotree_ir::chain::ergo_box::RegisterValue;
 use ergo_lib::ergotree_ir::mir::constant::{TryExtractFrom, TryExtractInto};
 use ergo_lib::ergotree_ir::serialization::SigmaSerializable;
 use ergo_lib::ergotree_ir::sigma_protocol::sigma_boolean::ProveDlog;
@@ -47,7 +48,11 @@ impl Constant {
                 base16_bytes_str.clone()
             ))
         })?;
-        ergo_lib::ergotree_ir::mir::constant::Constant::try_from(bytes)
+
+        let register_value = RegisterValue::sigma_parse_bytes(bytes.as_ref());
+        register_value
+            .as_constant()
+            .cloned()
             .map_err(to_js)
             .map(Constant)
     }
diff --git a/ergo-chain-types/src/base16_bytes.rs b/ergo-chain-types/src/base16_bytes.rs
index 38c8f78ba..cf0532150 100644
--- a/ergo-chain-types/src/base16_bytes.rs
+++ b/ergo-chain-types/src/base16_bytes.rs
@@ -80,3 +80,9 @@ impl From<Vec<u8>> for Base16EncodedBytes {
         Base16EncodedBytes::new(v.as_slice())
     }
 }
+
+impl AsRef<[u8]> for Base16DecodedBytes {
+    fn as_ref(&self) -> &[u8] {
+        self.0.as_slice()
+    }
+}


Test patch: