Skip to content

Commit

Permalink
Remove endowment:long-running
Browse files Browse the repository at this point in the history
  • Loading branch information
david0xd committed Sep 21, 2023
1 parent 814188a commit b4953aa
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 326 deletions.
266 changes: 44 additions & 222 deletions packages/snaps-controllers/src/snaps/SnapController.test.ts

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import {
getErrorMessage,
HandlerType,
logError,
logWarning,
normalizeRelative,
resolveVersionRange,
SnapCaveatType,
Expand Down Expand Up @@ -2112,7 +2111,6 @@ export class SnapController extends BaseController<

try {
const result = await this.#executeWithTimeout(
snapId,
this.messagingSystem.call('ExecutionService:executeSnap', {
...snapData,
endowments: await this.#getEndowments(snapId),
Expand Down Expand Up @@ -2563,7 +2561,6 @@ export class SnapController extends BaseController<
// This will either get the result or reject due to the timeout.
try {
const result = await this.#executeWithTimeout(
snapId,
handleRpcRequestPromise,
timer,
);
Expand All @@ -2583,31 +2580,15 @@ export class SnapController extends BaseController<
* Awaits the specified promise and rejects if the promise doesn't resolve
* before the timeout.
*
* @param snapId - The snap id.
* @param promise - The promise to await.
* @param timer - An optional timer object to control the timeout.
* @returns The result of the promise or rejects if the promise times out.
* @template PromiseValue - The value of the Promise.
*/
async #executeWithTimeout<PromiseValue>(
snapId: ValidatedSnapId,
promise: Promise<PromiseValue>,
timer?: Timer,
): Promise<PromiseValue> {
const isLongRunning = this.messagingSystem.call(
'PermissionController:hasPermission',
snapId,
SnapEndowments.LongRunning,
);

// Long running snaps have timeouts disabled
if (isLongRunning) {
logWarning(
`${SnapEndowments.LongRunning} will soon be deprecated. For more information please see https://github.com/MetaMask/snaps-monorepo/issues/945.`,
);
return promise;
}

const result = await withTimeout(promise, timer ?? this.maxRequestTime);
if (result === hasTimedOut) {
throw new Error('The request timed out.');
Expand Down
1 change: 0 additions & 1 deletion packages/snaps-controllers/src/snaps/endowments/enum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export enum SnapEndowments {
NetworkAccess = 'endowment:network-access',
LongRunning = 'endowment:long-running',
TransactionInsight = 'endowment:transaction-insight',
Cronjob = 'endowment:cronjob',
EthereumProvider = 'endowment:ethereum-provider',
Expand Down
2 changes: 0 additions & 2 deletions packages/snaps-controllers/src/snaps/endowments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from './cronjob';
import { ethereumProviderEndowmentBuilder } from './ethereum-provider';
import { lifecycleHooksEndowmentBuilder } from './lifecycle-hooks';
import { longRunningEndowmentBuilder } from './long-running';
import {
getNameLookupCaveatMapper,
nameLookupCaveatSpecifications,
Expand All @@ -30,7 +29,6 @@ import { webAssemblyEndowmentBuilder } from './web-assembly';

export const endowmentPermissionBuilders = {
[networkAccessEndowmentBuilder.targetName]: networkAccessEndowmentBuilder,
[longRunningEndowmentBuilder.targetName]: longRunningEndowmentBuilder,
[transactionInsightEndowmentBuilder.targetName]:
transactionInsightEndowmentBuilder,
[cronjobEndowmentBuilder.targetName]: cronjobEndowmentBuilder,
Expand Down

This file was deleted.

45 changes: 0 additions & 45 deletions packages/snaps-controllers/src/snaps/endowments/long-running.ts

This file was deleted.

9 changes: 0 additions & 9 deletions packages/snaps-controllers/src/snaps/permission.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,6 @@ describe('buildSnapEndowmentSpecifications', () => {
],
"targetName": "endowment:lifecycle-hooks",
},
"endowment:long-running": {
"allowedCaveats": null,
"endowmentGetter": [Function],
"permissionType": "Endowment",
"subjectTypes": [
"snap",
],
"targetName": "endowment:long-running",
},
"endowment:name-lookup": {
"allowedCaveats": [
"chainIds",
Expand Down
13 changes: 5 additions & 8 deletions packages/snaps-controllers/src/test-utils/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,9 @@ export const getControllerMessenger = (registry = new MockSnapsRegistry()) => {
SnapControllerEvents | AllowedEvents
>();

messenger.registerActionHandler(
'PermissionController:hasPermission',
(permission) => {
return permission !== SnapEndowments.LongRunning;
},
);
messenger.registerActionHandler('PermissionController:hasPermission', () => {
return true;
});

messenger.registerActionHandler('PermissionController:hasPermissions', () => {
return true;
Expand Down Expand Up @@ -483,8 +480,8 @@ export const getRestrictedCronjobControllerMessenger = (
if (mocked) {
messenger.registerActionHandler(
'PermissionController:hasPermission',
(permission) => {
return permission !== SnapEndowments.LongRunning;
() => {
return true;
},
);

Expand Down
1 change: 0 additions & 1 deletion packages/snaps-utils/src/manifest/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ export const ChainIdsStruct = array(ChainIdStruct);

/* eslint-disable @typescript-eslint/naming-convention */
export const PermissionsStruct = type({
'endowment:long-running': optional(object({})),
'endowment:network-access': optional(object({})),
'endowment:webassembly': optional(object({})),
'endowment:transaction-insight': optional(
Expand Down

0 comments on commit b4953aa

Please sign in to comment.