centrifuge / fudge

FUlly Decoupled Generic Environment for Substrate-chains
Other
22 stars 2 forks source link

Provide `StateUtils` in `with_state` and `with_mut_state` #5

Open mustermeiszer opened 2 years ago

mustermeiszer commented 2 years ago

Currently, the with_state and with_mut_state simply execute the given closure in an externalities provided environment.

It would be nice if the buider would pas a StateUtils struct to the closure. The StateUtils should provide some interface like:

impl StateUtils {
   // Executes an extrinsic or maybe just a Call enum variant  in the wasm environment. 
   pub fn exec_wasm(&self, Block::Extrinsic) -> Result;

   // Get the block this state is build upon
   pub fn block(&self) -> Block;

   // Maybe expose the API to the runtime to the closure, maybe something that allows actually working with the api
   pub fn API(&self) -> RuntimeAPi;

}

Implementation Idea

As the runtime API of the chains differ and need different trait bounds providing such an API statically via the builders is impossible. Probably the best approach would be to have a trait StateUtils<API> that each builder takes. The struct StateUtils implements this trait. But via the generic API chains can introduce additional trait bounds for the API that are checked during compilation.