@@ -20,7 +20,7 @@ use crate::host::wasm_common::{err_to_errno_and_log, RowIterIdx, TimingSpan, Tim
2020use crate :: host:: AbiCall ;
2121use anyhow:: Context ;
2222use bytes:: Bytes ;
23- use spacetimedb_lib:: { bsatn, ConnectionId , Identity , RawModuleDef } ;
23+ use spacetimedb_lib:: { bsatn, ConnectionId , Identity , RawModuleDef , Timestamp } ;
2424use spacetimedb_primitives:: { errno, ColId , IndexId , ProcedureId , ReducerId , TableId , ViewFnPtr } ;
2525use spacetimedb_sats:: Serialize ;
2626use v8:: {
@@ -129,7 +129,22 @@ pub(super) fn sys_v1_2<'scope>(scope: &mut PinScope<'scope, '_>) -> Local<'scope
129129 with_sys_result_value,
130130 AbiCall :: ProcedureHttpRequest ,
131131 procedure_http_request
132- )
132+ ) ,
133+ (
134+ with_sys_result_value,
135+ AbiCall :: ProcedureStartMutTransaction ,
136+ procedure_start_mut_tx
137+ ) ,
138+ (
139+ with_sys_result_noret,
140+ AbiCall :: ProcedureAbortMutTransaction ,
141+ procedure_abort_mut_tx
142+ ) ,
143+ (
144+ with_sys_result_noret,
145+ AbiCall :: ProcedureCommitMutTransaction ,
146+ procedure_commit_mut_tx
147+ ) ,
133148 )
134149}
135150
@@ -1585,3 +1600,37 @@ fn procedure_http_request<'scope>(
15851600 & [ response. into ( ) , response_body. into ( ) ] ,
15861601 ) )
15871602}
1603+
1604+ fn procedure_start_mut_tx < ' scope > (
1605+ scope : & mut PinScope < ' scope , ' _ > ,
1606+ _args : FunctionCallbackArguments < ' _ > ,
1607+ ) -> SysCallResult < Local < ' scope , v8:: BigInt > > {
1608+ let env = get_env ( scope) ?;
1609+
1610+ let fut = env. instance_env . start_mutable_tx ( ) ?;
1611+
1612+ let rt = tokio:: runtime:: Handle :: current ( ) ;
1613+ rt. block_on ( fut) ;
1614+
1615+ let timestamp = Timestamp :: now ( ) . to_micros_since_unix_epoch ( ) as u64 ;
1616+
1617+ Ok ( v8:: BigInt :: new_from_u64 ( scope, timestamp) )
1618+ }
1619+
1620+ fn procedure_abort_mut_tx ( scope : & mut PinScope < ' _ , ' _ > , _args : FunctionCallbackArguments < ' _ > ) -> SysCallResult < ( ) > {
1621+ let env = get_env ( scope) ?;
1622+
1623+ env. instance_env . abort_mutable_tx ( ) ?;
1624+ Ok ( ( ) )
1625+ }
1626+
1627+ fn procedure_commit_mut_tx ( scope : & mut PinScope < ' _ , ' _ > , _args : FunctionCallbackArguments < ' _ > ) -> SysCallResult < ( ) > {
1628+ let env = get_env ( scope) ?;
1629+
1630+ let fut = env. instance_env . commit_mutable_tx ( ) ?;
1631+
1632+ let rt = tokio:: runtime:: Handle :: current ( ) ;
1633+ rt. block_on ( fut) ;
1634+
1635+ Ok ( ( ) )
1636+ }
0 commit comments