commit 5125a8bcdd2141fac1eb4cbd0666d29d12d3bdbf
parent 7344cb541280a961be374457ace9894d756e98c9
Author: parazyd <parazyd@dyne.org>
Date: Wed, 9 Mar 2022 00:06:25 +0100
runtime: Handle contract exit errors.
Diffstat:
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -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"
diff --git a/src/runtime.rs b/src/runtime.rs
@@ -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;
@@ -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