Skip to content

Commit

Permalink
Sketch loading of "upgradeConstructor" from the ABI.json file.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreibancioiu committed May 27, 2024
1 parent b877bbe commit c65ba7a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 26 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.1.0",
"version": "13.1.1",
"description": "MultiversX SDK for JavaScript and TypeScript",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
11 changes: 11 additions & 0 deletions src/smartcontracts/typesystem/abiRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ const interfaceNamePlaceholder = "?";
export class AbiRegistry {
readonly name: string;
readonly constructorDefinition: EndpointDefinition;
readonly upgradeConstructorDefinition?: EndpointDefinition;
readonly endpoints: EndpointDefinition[] = [];
readonly customTypes: CustomType[] = [];
readonly events: EventDefinition[] = [];

private constructor(options: {
name: string;
constructorDefinition: EndpointDefinition;
upgradeConstructorDefinition?: EndpointDefinition;
endpoints: EndpointDefinition[];
customTypes: CustomType[];
events?: EventDefinition[];
}) {
this.name = options.name;
this.constructorDefinition = options.constructorDefinition;
this.upgradeConstructorDefinition = options.upgradeConstructorDefinition;
this.endpoints = options.endpoints;
this.customTypes = options.customTypes;
this.events = options.events || [];
Expand All @@ -33,18 +36,25 @@ export class AbiRegistry {
static create(options: {
name?: string;
constructor?: any;
upgradeConstructor?: any;
endpoints?: any[];
types?: Record<string, any>;
events?: any[];
}): AbiRegistry {
const name = options.name || interfaceNamePlaceholder;
const constructor = options.constructor || {};
const upgradeConstructor = options.upgradeConstructor || {};
const endpoints = options.endpoints || [];
const types = options.types || {};
const events = options.events || [];

// Load arbitrary input parameters into properly-defined objects (e.g. EndpointDefinition and CustomType).
const constructorDefinition = EndpointDefinition.fromJSON({ name: "constructor", ...constructor });
const upgradeConstructorDefinition = EndpointDefinition.fromJSON({
name: "upgradeConstructor",
...upgradeConstructor,
});

const endpointDefinitions = endpoints.map((item) => EndpointDefinition.fromJSON(item));
const customTypes: CustomType[] = [];

Expand All @@ -65,6 +75,7 @@ export class AbiRegistry {
const registry = new AbiRegistry({
name: name,
constructorDefinition: constructorDefinition,
upgradeConstructorDefinition: upgradeConstructorDefinition,
endpoints: endpointDefinitions,
customTypes: customTypes,
events: eventDefinitions,
Expand Down
39 changes: 16 additions & 23 deletions src/testdata/adder.abi.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"buildInfo": {
"rustc": {
"version": "1.71.0-nightly",
"commitHash": "a2b1646c597329d0a25efa3889b66650f65de1de",
"commitDate": "2023-05-25",
"version": "1.76.0-nightly",
"commitHash": "d86d65bbc19b928387f68427fcc3a0da498d8a19",
"commitDate": "2023-12-10",
"channel": "Nightly",
"short": "rustc 1.71.0-nightly (a2b1646c5 2023-05-25)"
"short": "rustc 1.76.0-nightly (d86d65bbc 2023-12-10)"
},
"contractCrate": {
"name": "adder",
"version": "0.0.0",
"gitVersion": "v0.45.2.1-reproducible-169-g37d970c"
"gitVersion": "v0.50.1-3-gbed74682a"
},
"framework": {
"name": "multiversx-sc",
"version": "0.47.2"
"version": "0.50.1"
}
},
"docs": [
Expand All @@ -31,6 +31,15 @@
],
"outputs": []
},
"upgradeConstructor": {
"inputs": [
{
"name": "initial_value",
"type": "BigUint"
}
],
"outputs": []
},
"endpoints": [
{
"name": "getSum",
Expand All @@ -43,25 +52,9 @@
]
},
{
"name": "upgrade",
"mutability": "mutable",
"inputs": [
{
"name": "new_value",
"type": "BigUint"
}
],
"outputs": []
},
{
"docs": [
"Add desired amount to the storage variable."
],
"docs": ["Add desired amount to the storage variable."],
"name": "add",
"mutability": "mutable",
"payableInTokens": [
"*"
],
"inputs": [
{
"name": "value",
Expand Down

0 comments on commit c65ba7a

Please sign in to comment.