corevm 0.1.26

The JAM CoreVM Service, a container service for running regular software on JAM.
Documentation
use alloc::borrow::Cow;
use codec::Encode;
use corevm_engine::AccumulateOps;
use corevm_host::StorageKey;
use jam_pvm_common::{
	accumulate::{get_storage, remove_storage, set_storage},
	ApiError,
};

/// An implementation of `AccumulateOps` that forwards all host-calls to JAM.
pub struct JamAccumulateOps;

impl AccumulateOps for JamAccumulateOps {
	type Error = ApiError;

	fn get(&self, key: &StorageKey) -> Option<Cow<'_, [u8]>> {
		key.using_encoded(|key| get_storage(key)).map(Cow::Owned)
	}

	fn set(&mut self, key: StorageKey, value: Cow<'_, [u8]>) -> Result<(), Self::Error> {
		key.using_encoded(|key| set_storage(key, value.as_ref()))?;
		Ok(())
	}

	fn remove(&mut self, key: &StorageKey) {
		key.using_encoded(|key| remove_storage(key));
	}
}