Skip to content

Commit

Permalink
Add title to abi endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
danielailie committed Oct 14, 2024
1 parent 6f76303 commit 21bec13
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/smartcontracts/typesystem/abiRegistry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,12 @@ describe("test abi registry", () => {
assert.deepEqual(enumType.variants[1].name, "interrupted");
assert.deepEqual(enumType.variants[1].discriminant, 1);
});

it("should load abi with title for endpoint", async () => {
const registry = await loadAbiRegistry("src/testdata/lottery-esdt.abi.json");

const endpoint = registry.getEndpoint("createLotteryPool");

assert.equal(endpoint.title, "Create lottery pool");
});
});
2 changes: 1 addition & 1 deletion src/smartcontracts/typesystem/abiRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function mapEndpoint(endpoint: EndpointDefinition, mapper: TypeMapper): Endpoint
(e) => new EndpointParameterDefinition(e.name, e.description, mapper.mapType(e.type)),
);

return new EndpointDefinition(endpoint.name, newInput, newOutput, endpoint.modifiers);
return new EndpointDefinition(endpoint.name, newInput, newOutput, endpoint.modifiers, endpoint.title);
}

function mapEvent(event: EventDefinition, mapper: TypeMapper): EventDefinition {
Expand Down
7 changes: 6 additions & 1 deletion src/smartcontracts/typesystem/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const DescriptionPlaceholder = "N / A";

export class EndpointDefinition {
readonly name: string;
readonly title: string;
readonly input: EndpointParameterDefinition[] = [];
readonly output: EndpointParameterDefinition[] = [];
readonly modifiers: EndpointModifiers;
Expand All @@ -15,8 +16,10 @@ export class EndpointDefinition {
input: EndpointParameterDefinition[],
output: EndpointParameterDefinition[],
modifiers: EndpointModifiers,
title?: string,
) {
this.name = name;
this.title = title || "";
this.input = input || [];
this.output = output || [];
this.modifiers = modifiers;
Expand All @@ -28,6 +31,7 @@ export class EndpointDefinition {

static fromJSON(json: {
name: string;
title?: string;
onlyOwner?: boolean;
mutability: string;
payableInTokens: string[];
Expand All @@ -36,6 +40,7 @@ export class EndpointDefinition {
}): EndpointDefinition {
json.name = json.name == null ? NamePlaceholder : json.name;
json.onlyOwner = json.onlyOwner || false;
json.title = json.title || "";
json.payableInTokens = json.payableInTokens || [];
json.inputs = json.inputs || [];
json.outputs = json.outputs || [];
Expand All @@ -44,7 +49,7 @@ export class EndpointDefinition {
let output = json.outputs.map((param) => EndpointParameterDefinition.fromJSON(param));
let modifiers = new EndpointModifiers(json.mutability, json.payableInTokens, json.onlyOwner);

return new EndpointDefinition(json.name, input, output, modifiers);
return new EndpointDefinition(json.name, input, output, modifiers, json.title);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/testdata/lottery-esdt.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
},
{
"name": "createLotteryPool",
"title": "Create lottery pool",
"mutability": "mutable",
"inputs": [
{
Expand Down

0 comments on commit 21bec13

Please sign in to comment.