Skip to content

Commit

Permalink
Merge pull request #506 from multiversx/TOOL-272-add-title-to-abi-end…
Browse files Browse the repository at this point in the history
…points

Add title to abi endpoint
  • Loading branch information
danielailie authored Oct 14, 2024
2 parents 6f76303 + adc447a commit 13b4d1c
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-core",
"version": "13.8.0",
"version": "13.9.0",
"description": "MultiversX SDK for JavaScript and TypeScript",
"author": "MultiversX",
"homepage": "https://multiversx.com",
Expand Down
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 13b4d1c

Please sign in to comment.