From c65ba7af52dc8cc88df637e0d0b73c268982a9da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 27 May 2024 09:19:26 +0300 Subject: [PATCH] Sketch loading of "upgradeConstructor" from the ABI.json file. --- package-lock.json | 4 +- package.json | 2 +- src/smartcontracts/typesystem/abiRegistry.ts | 11 ++++++ src/testdata/adder.abi.json | 39 ++++++++------------ 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index b74e4578..8e1c3580 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@multiversx/sdk-core", - "version": "13.1.0", + "version": "13.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@multiversx/sdk-core", - "version": "13.1.0", + "version": "13.1.1", "license": "MIT", "dependencies": { "@multiversx/sdk-transaction-decoder": "1.0.2", diff --git a/package.json b/package.json index df883f36..7b5549a2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/smartcontracts/typesystem/abiRegistry.ts b/src/smartcontracts/typesystem/abiRegistry.ts index 601b65be..08c1b877 100644 --- a/src/smartcontracts/typesystem/abiRegistry.ts +++ b/src/smartcontracts/typesystem/abiRegistry.ts @@ -12,6 +12,7 @@ const interfaceNamePlaceholder = "?"; export class AbiRegistry { readonly name: string; readonly constructorDefinition: EndpointDefinition; + readonly upgradeConstructorDefinition?: EndpointDefinition; readonly endpoints: EndpointDefinition[] = []; readonly customTypes: CustomType[] = []; readonly events: EventDefinition[] = []; @@ -19,12 +20,14 @@ export class AbiRegistry { 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 || []; @@ -33,18 +36,25 @@ export class AbiRegistry { static create(options: { name?: string; constructor?: any; + upgradeConstructor?: any; endpoints?: any[]; types?: Record; 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[] = []; @@ -65,6 +75,7 @@ export class AbiRegistry { const registry = new AbiRegistry({ name: name, constructorDefinition: constructorDefinition, + upgradeConstructorDefinition: upgradeConstructorDefinition, endpoints: endpointDefinitions, customTypes: customTypes, events: eventDefinitions, diff --git a/src/testdata/adder.abi.json b/src/testdata/adder.abi.json index 7aba85f5..fd809ce9 100644 --- a/src/testdata/adder.abi.json +++ b/src/testdata/adder.abi.json @@ -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": [ @@ -31,6 +31,15 @@ ], "outputs": [] }, + "upgradeConstructor": { + "inputs": [ + { + "name": "initial_value", + "type": "BigUint" + } + ], + "outputs": [] + }, "endpoints": [ { "name": "getSum", @@ -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",