1use std::str::FromStr;
7
8use async_graphql::scalar;
9use derive_more::Display;
10use linera_witty::{WitLoad, WitStore, WitType};
11use serde::{Deserialize, Serialize};
12use thiserror::Error;
13
14#[derive(
15 Clone,
16 Copy,
17 Default,
18 Display,
19 Hash,
20 PartialEq,
21 Eq,
22 PartialOrd,
23 Ord,
24 Serialize,
25 Deserialize,
26 WitType,
27 WitStore,
28 WitLoad,
29 Debug,
30)]
31#[cfg_attr(with_testing, derive(test_strategy::Arbitrary))]
32pub enum VmRuntime {
34 #[default]
36 Wasm,
37 Evm,
39}
40
41impl FromStr for VmRuntime {
42 type Err = InvalidVmRuntime;
43
44 fn from_str(string: &str) -> Result<Self, Self::Err> {
45 match string {
46 "wasm" => Ok(VmRuntime::Wasm),
47 "evm" => Ok(VmRuntime::Evm),
48 unknown => Err(InvalidVmRuntime(unknown.to_owned())),
49 }
50 }
51}
52
53scalar!(VmRuntime);
54
55#[derive(Clone, Debug, Error)]
57#[error("{0:?} is not a valid virtual machine runtime")]
58pub struct InvalidVmRuntime(String);
59
60#[derive(Clone, Debug, Deserialize, Serialize)]
62pub enum EvmQuery {
63 Query(Vec<u8>),
65 Mutation(Vec<u8>),
67}