Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Endpoint definition Owner-Only Support #335

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/smartcontracts/typesystem/endpoint.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { assert } from "chai";
import { EndpointDefinition } from "./endpoint";


describe("test endpoint", () => {
it('should handle an only-owner modifier', async () => {
const actual = EndpointDefinition.fromJSON({
name: 'foo',
ownerOnly: true,
mutability: 'payable',
payableInTokens: [],
inputs: [],
outputs: [],
})

assert.isTrue(actual.modifiers.ownerOnly)
assert.isTrue(actual.modifiers.isOwnerOnly())
})
});
12 changes: 10 additions & 2 deletions src/smartcontracts/typesystem/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ export class EndpointDefinition {

static fromJSON(json: {
name: string,
ownerOnly?: boolean
mutability: string,
payableInTokens: string[],
inputs: any[],
outputs: any[]
}): EndpointDefinition {
json.name = json.name == null ? NamePlaceholder : json.name;
json.ownerOnly = json.ownerOnly || false;
json.payableInTokens = json.payableInTokens || [];
json.inputs = json.inputs || [];
json.outputs = json.outputs || [];

let input = json.inputs.map(param => EndpointParameterDefinition.fromJSON(param));
let output = json.outputs.map(param => EndpointParameterDefinition.fromJSON(param));
let modifiers = new EndpointModifiers(json.mutability, json.payableInTokens);
let modifiers = new EndpointModifiers(json.mutability, json.payableInTokens, json.ownerOnly);

return new EndpointDefinition(json.name, input, output, modifiers);
}
Expand All @@ -44,10 +46,12 @@ export class EndpointDefinition {
export class EndpointModifiers {
readonly mutability: string;
readonly payableInTokens: string[];
readonly ownerOnly: boolean;

constructor(mutability: string, payableInTokens: string[]) {
constructor(mutability: string, payableInTokens: string[], ownerOnly?: boolean) {
michavie marked this conversation as resolved.
Show resolved Hide resolved
this.mutability = mutability || "";
this.payableInTokens = payableInTokens || [];
this.ownerOnly = ownerOnly || false;
}

isPayableInEGLD(): boolean {
Expand Down Expand Up @@ -77,6 +81,10 @@ export class EndpointModifiers {
isReadonly() {
return this.mutability == "readonly";
}

isOwnerOnly() {
return this.ownerOnly;
}
}

export class EndpointParameterDefinition {
Expand Down
Loading