Skip to content

Commit

Permalink
Fix assemblyscript build
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Papierski committed Jun 15, 2022
1 parent 17c07ed commit e35e834
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ import { addAssociatedKey, AddKeyFailure, ActionType, setActionThreshold, SetThr
const ARG_KEY_MANAGEMENT_THRESHOLD = "key_management_threshold";
const ARG_DEPLOY_THRESHOLD = "deploy_threshold";

function handleError(error: SetThresholdFailure): void {
switch (error) {
case SetThresholdFailure.Ok:
break;
case SetThresholdFailure.KeyManagementThreshold:
Error.fromErrorCode(ErrorCode.KeyManagementThreshold).revert();
break;
case SetThresholdFailure.DeploymentThreshold:
Error.fromErrorCode(ErrorCode.DeploymentThreshold).revert();
break;
case SetThresholdFailure.PermissionDeniedError:
Error.fromErrorCode(ErrorCode.PermissionDenied).revert();
break;
case SetThresholdFailure.InsufficientTotalWeight:
Error.fromErrorCode(ErrorCode.InsufficientTotalWeight).revert();
break;
}
}

export function call(): void {
let keyManagementThresholdBytes = CL.getNamedArg(ARG_KEY_MANAGEMENT_THRESHOLD);
let keyManagementThreshold = keyManagementThresholdBytes[0];
Expand All @@ -17,31 +36,11 @@ export function call(): void {

if (keyManagementThreshold != 0) {
const result1 = setActionThreshold(ActionType.KeyManagement, keyManagementThreshold);
switch (result1) {
case SetThresholdFailure.Ok:
break;
case SetThresholdFailure.PermissionDeniedError:
Error.fromErrorCode(ErrorCode.PermissionDenied).revert();
break;
default:
// TODO: Create standard Error from those enum values
Error.fromUserError(4464 + 1).revert();
break;
}
handleError(result1);
}

if (deployThreshold != 0) {
const result2 = setActionThreshold(ActionType.Deployment, deployThreshold);
switch (result2) {
case SetThresholdFailure.Ok:
break;
case SetThresholdFailure.PermissionDeniedError:
Error.fromErrorCode(ErrorCode.PermissionDenied).revert();
break;
default:
// TODO: Create standard Error from those enum values
Error.fromUserError(4464).revert();
break;
}
handleError(result2);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"asbuild:optimized": "asc --lib ../../.. assembly/index.ts -b ../../../../target_as/authorized_keys.wasm --optimize --use abort=",
"asbuild:optimized": "asc --lib ../../.. assembly/index.ts -b ../../../../target_as/set_action_thresholds.wasm --optimize --use abort=",
"asbuild": "npm run asbuild:optimized"
},
"devDependencies": {
Expand Down

0 comments on commit e35e834

Please sign in to comment.