@@ -11,6 +11,7 @@ use stacks_common::util::secp256k1::{secp256k1_recover, secp256k1_verify, Secp25
11
11
use wasmtime:: { AsContextMut , Caller , Engine , Linker , Memory , Module , Store , Trap , Val , ValType } ;
12
12
13
13
use super :: analysis:: { CheckError , CheckErrors } ;
14
+ use super :: ast:: parse;
14
15
use super :: callables:: { DefineType , DefinedFunction } ;
15
16
use super :: contracts:: Contract ;
16
17
use super :: costs:: { constants as cost_constants, CostTracker , LimitedCostTracker } ;
@@ -1673,6 +1674,25 @@ fn pass_argument_to_wasm(
1673
1674
}
1674
1675
}
1675
1676
1677
+ pub fn signature_from_string (
1678
+ val : & str ,
1679
+ version : ClarityVersion ,
1680
+ epoch : StacksEpochId ,
1681
+ ) -> Result < TypeSignature , Error > {
1682
+ let expr = parse (
1683
+ & QualifiedContractIdentifier :: transient ( ) ,
1684
+ val,
1685
+ version,
1686
+ epoch,
1687
+ ) ?;
1688
+ let expr = expr. first ( ) . ok_or ( CheckErrors :: InvalidTypeDescription ) ?;
1689
+ Ok ( TypeSignature :: parse_type_repr (
1690
+ StacksEpochId :: latest ( ) ,
1691
+ expr,
1692
+ & mut ( ) ,
1693
+ ) ?)
1694
+ }
1695
+
1676
1696
/// Reserve space on the Wasm stack for the return value of a function, if
1677
1697
/// needed, and return a vector of `Val`s that can be passed to `call`, as a
1678
1698
/// place to store the return value, along with the new offset, which is the
@@ -5546,7 +5566,11 @@ fn link_print_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), Error> {
5546
5566
. func_wrap (
5547
5567
"clarity" ,
5548
5568
"print" ,
5549
- |mut caller : Caller < ' _ , ClarityWasmContext > , value_offset : i32 , value_length : i32 | {
5569
+ |mut caller : Caller < ' _ , ClarityWasmContext > ,
5570
+ value_offset : i32 ,
5571
+ _value_length : i32 ,
5572
+ serialized_ty_offset : i32 ,
5573
+ serialized_ty_length : i32 | {
5550
5574
// runtime_cost(ClarityCostFunction::Print, env, input.size())?;
5551
5575
5552
5576
// Get the memory from the caller
@@ -5555,14 +5579,19 @@ fn link_print_fn(linker: &mut Linker<ClarityWasmContext>) -> Result<(), Error> {
5555
5579
. and_then ( |export| export. into_memory ( ) )
5556
5580
. ok_or ( Error :: Wasm ( WasmError :: MemoryNotFound ) ) ?;
5557
5581
5558
- // Read in the bytes from the Wasm memory
5559
- let bytes = read_bytes_from_wasm ( memory, & mut caller, value_offset, value_length) ?;
5582
+ let serialized_ty = String :: from_utf8 ( read_bytes_from_wasm (
5583
+ memory,
5584
+ & mut caller,
5585
+ serialized_ty_offset,
5586
+ serialized_ty_length,
5587
+ ) ?) ?;
5560
5588
5561
- let clarity_val = Value :: deserialize_read ( & mut bytes. as_slice ( ) , None , false ) ?;
5589
+ let epoch = caller. data ( ) . global_context . epoch_id ;
5590
+ let version = caller. data ( ) . contract_context ( ) . get_clarity_version ( ) ;
5562
5591
5563
- if cfg ! ( feature = "developer-mode" ) {
5564
- debug ! ( "{}" , & clarity_val) ;
5565
- }
5592
+ let value_ty = signature_from_string ( & serialized_ty , * version , epoch ) ? ;
5593
+ let clarity_val =
5594
+ read_from_wasm_indirect ( memory , & mut caller , & value_ty , value_offset , epoch ) ? ;
5566
5595
5567
5596
caller. data_mut ( ) . register_print_event ( clarity_val) ?;
5568
5597
0 commit comments