URI:
       truntime: Handle contract exit errors. - wasm-runtime - A wasm runtime
  HTML git clone https://git.parazyd.org/wasm-runtime
   DIR Log
   DIR Files
   DIR Refs
   DIR README
       ---
   DIR commit 5125a8bcdd2141fac1eb4cbd0666d29d12d3bdbf
   DIR parent 7344cb541280a961be374457ace9894d756e98c9
  HTML Author: parazyd <parazyd@dyne.org>
       Date:   Wed,  9 Mar 2022 00:06:25 +0100
       
       runtime: Handle contract exit errors.
       
       Diffstat:
         M Cargo.toml                          |       1 +
         M src/runtime.rs                      |      16 +++++++++++++---
       
       2 files changed, 14 insertions(+), 3 deletions(-)
       ---
   DIR diff --git a/Cargo.toml b/Cargo.toml
       t@@ -14,6 +14,7 @@ exclude = ["smart-contract"]
        
        [dependencies]
        anyhow = "1.0.55"
       +drk-sdk = { path = "./drk-sdk" }
        thiserror = "1.0.30"
        wasmer = "2.2.0"
        
   DIR diff --git a/src/runtime.rs b/src/runtime.rs
       t@@ -1,4 +1,5 @@
       -use anyhow::Result;
       +use anyhow::{anyhow, Result};
       +use drk_sdk::entrypoint;
        use wasmer::{imports, Cranelift, Instance, Memory, Module, Store, Universal, Value};
        
        use crate::memory::MemoryManipulation;
       t@@ -50,8 +51,17 @@ impl Runtime {
                let ret = entrypoint.call(&[Value::I32(mem_offset as i32)])?;
        
                println!("Executed successfully");
       -        println!("Contract returned: {:?}", ret);
       -        Ok(())
       +        println!("Contract returned: {:?}", ret[0]);
       +
       +        let retval = match ret[0] {
       +            Value::I64(v) => v as u64,
       +            _ => unreachable!(),
       +        };
       +
       +        match retval {
       +            entrypoint::SUCCESS => Ok(()),
       +            _ => Err(anyhow!("Contract exited with an error: {0:#x}", retval)),
       +        }
            }
        
            /// Allocate some memory space on a wasm linear memory to allow direct rw