From ab89e65841aec4c5dbe1010d8c77c6884e0724df Mon Sep 17 00:00:00 2001 From: Serhii Volovyk Date: Tue, 30 Aug 2022 12:42:04 +0300 Subject: [PATCH] Babel calls use NearBindgen static methods --- lib/build-tools/near-bindgen-exporter.js | 8 ++++---- lib/near-bindgen.d.ts | 2 +- lib/near-bindgen.js | 4 ++-- src/build-tools/near-bindgen-exporter.js | 8 ++++---- src/near-bindgen.ts | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/build-tools/near-bindgen-exporter.js b/lib/build-tools/near-bindgen-exporter.js index 501abdfc0..ac8aec0c2 100644 --- a/lib/build-tools/near-bindgen-exporter.js +++ b/lib/build-tools/near-bindgen-exporter.js @@ -45,13 +45,13 @@ export default function () { // let _result = _contract.method(args); t.variableDeclaration('let', [t.variableDeclarator(t.identifier('_result'), t.callExpression(t.memberExpression(t.identifier('_contract'), t.identifier(method)), [t.identifier('_args')]))]), contractMethods[method] === 'initialize' || contractMethods[method] === 'call' ? - // _contract._saveToStorage(); - t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('_contract'), t.identifier('_saveToStorage')), [])) + // Counter._saveToStorage(_contract); + t.expressionStatement(t.callExpression(t.memberExpression(classId, t.identifier('_saveToStorage')), [t.identifier('_contract')])) : t.emptyStatement(), // if (_result !== undefined) near.valueReturn(_contract._serialize(result)); - t.ifStatement(t.binaryExpression('!==', t.identifier('_result'), t.identifier('undefined')), t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('near'), t.identifier('valueReturn')), [t.callExpression(t.memberExpression(t.identifier('_contract'), t.identifier('_serialize')), [t.identifier('_result')])]))), + t.ifStatement(t.binaryExpression('!==', t.identifier('_result'), t.identifier('undefined')), t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('near'), t.identifier('valueReturn')), [t.callExpression(t.memberExpression(classId, t.identifier('_serialize')), [t.identifier('_result')])]))), ])))); - console.log('Near bindgen export done'); + console.log(`Babel ${method} method export done`); } } } diff --git a/lib/near-bindgen.d.ts b/lib/near-bindgen.d.ts index 36d3a55ad..859abb370 100644 --- a/lib/near-bindgen.d.ts +++ b/lib/near-bindgen.d.ts @@ -7,7 +7,7 @@ export declare function NearBindgen(target: T) { return rawState ? this._deserialize(rawState) : null; } - static _saveToStorage(): void { - near.storageWrite("STATE", this._serialize(this)); + static _saveToStorage(obj: Object): void { + near.storageWrite("STATE", this._serialize(obj)); } static _getArgs(): JSON {