@@ -788,17 +788,13 @@ export function useMachineExecuteRestartCmd() {
788788 : oasis . misc . fromHex ( '000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c' )
789789 const roflmarket = new oasisRT . roflmarket . Wrapper ( sapphireRuntimeId )
790790
791- const restartRequest = {
792- wipe_storage : false ,
793- }
794-
795- const command = {
791+ const encodedCommand = oasis . misc . toCBOR ( {
796792 // https://github.com/oasisprotocol/cli/blob/b6894a1bb6ea7918a9b2ba3efe30b1911388e2f6/build/rofl/scheduler/commands.go#L9-L42
797793 method : 'Restart' ,
798- args : restartRequest ,
799- }
800-
801- const encodedCommand = oasis . misc . toCBOR ( command )
794+ args : {
795+ wipe_storage : false ,
796+ } ,
797+ } )
802798
803799 return await sendTransactionAsync (
804800 roflmarket
@@ -830,17 +826,13 @@ export function useMachineExecuteStopCmd() {
830826 : oasis . misc . fromHex ( '000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c' )
831827 const roflmarket = new oasisRT . roflmarket . Wrapper ( sapphireRuntimeId )
832828
833- const restartRequest = {
834- wipe_storage : false ,
835- }
836-
837- const command = {
829+ const encodedCommand = oasis . misc . toCBOR ( {
838830 // https://github.com/oasisprotocol/cli/blob/b6894a1bb6ea7918a9b2ba3efe30b1911388e2f6/build/rofl/scheduler/commands.go#L9-L42
839831 method : 'Terminate' ,
840- args : restartRequest ,
841- }
842-
843- const encodedCommand = oasis . misc . toCBOR ( command )
832+ args : {
833+ wipe_storage : false ,
834+ } ,
835+ } )
844836
845837 return await sendTransactionAsync (
846838 roflmarket
@@ -912,6 +904,14 @@ export function useMachineTopUp() {
912904 'net.oasis.deployment.orc.ref' : ( machine . deployment . metadata as any ) [
913905 'net.oasis.deployment.orc.ref'
914906 ] ,
907+ // Copy permissions like log.view
908+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
909+ ...( ( machine . deployment . metadata as any ) [ 'net.oasis.scheduler.permissions' ] && {
910+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
911+ 'net.oasis.scheduler.permissions' : ( machine . deployment . metadata as any ) [
912+ 'net.oasis.scheduler.permissions'
913+ ] ,
914+ } ) ,
915915 } ,
916916 } ,
917917 term : duration . term ,
@@ -927,3 +927,74 @@ export function useMachineTopUp() {
927927 } ,
928928 } )
929929}
930+
931+ export function useGrantLogsPermission ( ) {
932+ const { sendTransactionAsync } = useSendTransaction ( )
933+ return useMutation <
934+ `0x${string } `,
935+ AxiosError < unknown > ,
936+ {
937+ machine : RoflMarketInstance
938+ provider : string
939+ network : 'mainnet' | 'testnet'
940+ evmAddress : `0x${string } `
941+ }
942+ > ( {
943+ mutationFn : async ( { machine, provider, network, evmAddress } ) => {
944+ const sapphireRuntimeId =
945+ network === 'mainnet'
946+ ? oasis . misc . fromHex ( '000000000000000000000000000000000000000000000000f80306c9858e7279' )
947+ : oasis . misc . fromHex ( '000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c' )
948+ const roflmarket = new oasisRT . roflmarket . Wrapper ( sapphireRuntimeId )
949+
950+ const encodedCommand = oasis . misc . toCBOR ( {
951+ // https://github.com/oasisprotocol/cli/blob/b6894a1bb6ea7918a9b2ba3efe30b1911388e2f6/build/rofl/scheduler/commands.go#L9-L42
952+ method : 'Deploy' ,
953+ args : {
954+ deployment : {
955+ app_id : oasisRT . rofl . fromBech32 ( machine . deployment . app_id as string ) ,
956+ manifest_hash : oasis . misc . fromHex ( machine . deployment . manifest_hash as string ) ,
957+ metadata : {
958+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
959+ ...( machine . deployment . metadata as any ) ,
960+ // https://github.com/oasisprotocol/oasis-sdk/blob/b38b693/rofl-scheduler/src/types.rs#L49-L53
961+ 'net.oasis.scheduler.permissions' : oasis . misc . toBase64 (
962+ oasis . misc . toCBOR ( {
963+ // Keep other permissions
964+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
965+ ...( ( machine . deployment . metadata as any ) ?. [ 'net.oasis.scheduler.permissions' ] &&
966+ ( oasis . misc . fromCBOR (
967+ oasis . misc . fromBase64 (
968+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
969+ ( machine . deployment . metadata as any ) ?. [ 'net.oasis.scheduler.permissions' ] ,
970+ ) ,
971+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
972+ ) as any ) ) ,
973+ 'log.view' : [
974+ oasis . staking . addressFromBech32 (
975+ oasisRT . address . toBech32 ( getOasisAddressBytesFromEvm ( evmAddress ) ) ,
976+ ) ,
977+ ] ,
978+ } ) ,
979+ ) ,
980+ } ,
981+ } ,
982+ wipe_storage : false ,
983+ } ,
984+ } )
985+
986+ return await sendTransactionAsync (
987+ roflmarket
988+ . callInstanceExecuteCmds ( )
989+ . setBody ( {
990+ provider : oasis . staking . addressFromBech32 ( provider ) ,
991+ id : oasis . misc . fromHex ( machine . id ) as oasisRT . types . MachineID ,
992+ cmds : [ encodedCommand ] ,
993+ } )
994+ . toSubcall ( ) ,
995+ )
996+ // Doesn't wait for transaction receipt
997+ // Takes about 1 minute to complete after transaction receipt.
998+ } ,
999+ } )
1000+ }
0 commit comments