diff --git a/rust-runner/src/call_args.rs b/rust-runner/src/call_args.rs index 6a4afb6..55805f3 100644 --- a/rust-runner/src/call_args.rs +++ b/rust-runner/src/call_args.rs @@ -42,22 +42,32 @@ pub fn init( let allocator = runtime.allocator(); let descriptor_ptr = allocator.alloc(16)?; - let context_ptr = allocator.alloc(context.len() as u32)?; - let input_ptr = allocator.alloc(input.len() as u32)?; - - write_u32(&mut context_ptr_slc, context_ptr); - write_u32(&mut context_length, context.len() as u32); - write_u32(&mut input_ptr_slc, input_ptr); - write_u32(&mut input_length, input.len() as u32); + println!("descriptor_ptr: {}", descriptor_ptr); let memory = env.memory(DEFAULT_MEMORY_INDEX)?; + if context.len() > 0 { + let context_ptr = allocator.alloc(context.len() as u32)?; + write_u32(&mut context_ptr_slc, context_ptr); + write_u32(&mut context_length, context.len() as u32); + memory.set(context_ptr, context)?; + println!("context_ptr: {}", context_ptr); + } + + if input.len() > 0 { + let input_ptr = allocator.alloc(input.len() as u32)?; + write_u32(&mut input_ptr_slc, input_ptr); + write_u32(&mut input_length, input.len() as u32); + memory.set(input_ptr, input)?; + println!("input_ptr: {}", input_ptr); + } + memory.set(descriptor_ptr, &context_ptr_slc)?; memory.set(descriptor_ptr+4, &context_length)?; memory.set(descriptor_ptr+8, &input_ptr_slc)?; memory.set(descriptor_ptr+12, &input_length)?; - memory.set(context_ptr, context)?; - memory.set(input_ptr, input)?; + + println!("descriptor: {:?}", memory.get(descriptor_ptr, 16)); Ok(descriptor_ptr as i32) } \ No newline at end of file diff --git a/rust-runner/src/main.rs b/rust-runner/src/main.rs index af0901d..9f980da 100644 --- a/rust-runner/src/main.rs +++ b/rust-runner/src/main.rs @@ -61,9 +61,6 @@ fn main() { // Add module to the programm let module_instance = program.add_module("contract", module).expect("Module to be added successfully"); - // Create allocator - runtime.allocator().alloc(5*1024*1024).expect("to allocate 5mb successfully"); // reserve stack space - // Initialize call descriptor let descriptor = call_args::init( &*program.module("env").expect("env module to exist"),