@@ -49,6 +49,7 @@ use linera_base::{
4949 vm:: VmRuntime ,
5050} ;
5151use linera_views:: { batch:: Batch , ViewError } ;
52+ use linera_witty:: { WitLoad , WitStore , WitType } ;
5253use serde:: { Deserialize , Serialize } ;
5354use system:: AdminOperation ;
5455use thiserror:: Error ;
@@ -679,7 +680,7 @@ pub trait ServiceRuntime: BaseRuntime {
679680 ) -> Result < Vec < u8 > , ExecutionError > ;
680681
681682 /// Schedules an operation to be included in the block proposed after execution.
682- fn schedule_operation ( & mut self , operation : Vec < u8 > ) -> Result < ( ) , ExecutionError > ;
683+ fn schedule_operation ( & mut self , input : OperationInput ) -> Result < ( ) , ExecutionError > ;
683684
684685 /// Checks if the service has exceeded its execution time limit.
685686 fn check_execution_time ( & mut self ) -> Result < ( ) , ExecutionError > ;
@@ -817,17 +818,29 @@ pub trait ContractRuntime: BaseRuntime {
817818 fn write_batch ( & mut self , batch : Batch ) -> Result < ( ) , ExecutionError > ;
818819}
819820
821+ /// Input for an operation, which can be either direct bytes or a composed operation.
822+ #[ derive( Debug , PartialEq , Eq , Hash , Clone , Serialize , Deserialize , WitType , WitLoad , WitStore ) ]
823+ pub enum OperationInput {
824+ /// Direct input as bytes.
825+ Direct (
826+ #[ serde( with = "serde_bytes" ) ]
827+ #[ debug( with = "hex_debug" ) ]
828+ Vec < u8 >
829+ ) ,
830+ /// Composed input that uses the result from the previous operation in the block.
831+ /// If operation_results is empty, an error should be raised during execution.
832+ Composed ,
833+ }
834+
820835/// An operation to be executed in a block.
821836#[ derive( Debug , PartialEq , Eq , Hash , Clone , Serialize , Deserialize ) ]
822837pub enum Operation {
823838 /// A system operation.
824839 System ( Box < SystemOperation > ) ,
825- /// A user operation (in serialized form) .
840+ /// A user operation.
826841 User {
827842 application_id : ApplicationId ,
828- #[ serde( with = "serde_bytes" ) ]
829- #[ debug( with = "hex_debug" ) ]
830- bytes : Vec < u8 > ,
843+ input : OperationInput ,
831844 } ,
832845}
833846
@@ -1176,10 +1189,20 @@ impl Operation {
11761189 ) -> Result < Self , bcs:: Error > {
11771190 Ok ( Operation :: User {
11781191 application_id,
1179- bytes : bcs:: to_bytes ( & operation) ?,
1192+ input : OperationInput :: Direct ( bcs:: to_bytes ( & operation) ?) ,
11801193 } )
11811194 }
11821195
1196+ /// Creates a new composed user application operation that uses the result from the
1197+ /// previous operation as input.
1198+ #[ cfg( with_testing) ]
1199+ pub fn user_composed ( application_id : ApplicationId ) -> Self {
1200+ Operation :: User {
1201+ application_id,
1202+ input : OperationInput :: Composed ,
1203+ }
1204+ }
1205+
11831206 /// Returns a reference to the [`SystemOperation`] in this [`Operation`], if this [`Operation`]
11841207 /// is for the system application.
11851208 pub fn as_system_operation ( & self ) -> Option < & SystemOperation > {
0 commit comments