diff --git a/moveos/moveos-stdlib/moveos-stdlib/sources/move_action.move b/moveos/moveos-stdlib/moveos-stdlib/sources/move_action.move new file mode 100644 index 0000000000..4257e769f8 --- /dev/null +++ b/moveos/moveos-stdlib/moveos-stdlib/sources/move_action.move @@ -0,0 +1,74 @@ +module moveos_std::move_action{ + + use std::error; + use std::string::{String}; + use std::option::{Self, Option}; + + const EInvalidType: u64 = 1; + + struct ScriptCall has store, copy, drop { + code: vector, + //It is hard to implement TypeTag in Move, so we use String instead + ty_args: vector, + args: vector>, + } + + //TODO define in another module + struct ModuleId has store, copy, drop { + module_address: address, + name: String, + } + + struct FunctionId has store, copy, drop { + module_id: ModuleId, + name: String, + } + + struct FunctionCall has store, copy, drop { + functionId: FunctionId, + ty_args: vector, + args: vector>, + } + + struct ModuleBundle has store, copy, drop { + modules: vector>, + } + + struct MoveAction has store, copy, drop { + script_call: Option, + function_call: Option, + module_bundle: Option, + } + + public fun is_script_call(move_action: &MoveAction): bool { + option::is_some(&move_action.script_call) + } + + public fun into_script_call(move_action: MoveAction): ScriptCall { + assert!(is_script_call(&move_action), error::invalid_argument(EInvalidType)); + option::extract(&mut move_action.script_call) + } + + public fun is_function_call(move_action: &MoveAction): bool { + option::is_some(&move_action.function_call) + } + + public fun into_function_call(move_action: MoveAction): FunctionCall { + assert!(is_function_call(&move_action), error::invalid_argument(EInvalidType)); + option::extract(&mut move_action.function_call) + } + + public fun is_module_bundle(move_action: &MoveAction): bool { + option::is_some(&move_action.module_bundle) + } + + public fun into_module_bundle(move_action: MoveAction): ModuleBundle { + assert!(is_module_bundle(&move_action), error::invalid_argument(EInvalidType)); + option::extract(&mut move_action.module_bundle) + } + + /// We provide a native function to decode MoveAction from bytes + /// We can not use the `bcs::from_bytes` directly + /// because we can not define a `MoveAction` which has same bcs layout with the MoveAction in Rust + public native fun decode_move_action(bytes: &vector): MoveAction; +} \ No newline at end of file