From de9a859ca9bc69f663e3abca8fabf0c11e2a0e30 Mon Sep 17 00:00:00 2001 From: luc10921 Date: Tue, 26 Sep 2023 15:38:26 -0300 Subject: [PATCH] CU-86a0uktwy - Move typeChecker to neon-dappkit-types --- .../neon-dappkit-types/dist/TypeChecker.d.ts | 15 + .../neon-dappkit-types/dist/TypeChecker.js | 60 ++++ packages/neon-dappkit-types/dist/index.d.ts | 1 + packages/neon-dappkit-types/dist/index.js | 1 + packages/neon-dappkit-types/docs/index.html | 3 +- packages/neon-dappkit-types/docs/modules.html | 4 +- .../docs/variables/TypeChecker.html | 256 ++++++++++++++++++ .../neon-dappkit-types/src/TypeChecker.ts | 84 ++++++ packages/neon-dappkit-types/src/index.ts | 1 + packages/neon-dappkit/dist/NeonInvoker.d.ts | 5 +- packages/neon-dappkit/dist/NeonInvoker.js | 29 +- .../neon-dappkit/dist/NeonInvoker.spec.js | 32 +-- packages/neon-dappkit/src/NeonInvoker.spec.ts | 34 +-- packages/neon-dappkit/src/NeonInvoker.ts | 4 +- packages/neon-dappkit/src/typeChecker.ts | 78 ------ 15 files changed, 463 insertions(+), 144 deletions(-) create mode 100644 packages/neon-dappkit-types/dist/TypeChecker.d.ts create mode 100644 packages/neon-dappkit-types/dist/TypeChecker.js create mode 100644 packages/neon-dappkit-types/docs/variables/TypeChecker.html create mode 100644 packages/neon-dappkit-types/src/TypeChecker.ts delete mode 100644 packages/neon-dappkit/src/typeChecker.ts diff --git a/packages/neon-dappkit-types/dist/TypeChecker.d.ts b/packages/neon-dappkit-types/dist/TypeChecker.d.ts new file mode 100644 index 0000000..cfc1b4b --- /dev/null +++ b/packages/neon-dappkit-types/dist/TypeChecker.d.ts @@ -0,0 +1,15 @@ +import { AnyArgType, BooleanArgType, IntegerArgType, ArrayResponseArgType, MapResponseArgType, ByteStringArgType, InteropInterfaceArgType, PointerArgType, BufferArgType, StructArgType, RpcResponseStackItem } from './Neo3Invoker'; +declare const TypeChecker: { + isStackTypeAny(item: any): item is AnyArgType; + isStackTypeBoolean(item: any): item is BooleanArgType; + isStackTypeInteger(item: any): item is IntegerArgType; + isStackTypeArray(item: any): item is ArrayResponseArgType; + isStackTypeMap(item: any): item is MapResponseArgType; + isStackTypeByteString(item: any): item is ByteStringArgType; + isStackTypeInteropInterface(item: any): item is InteropInterfaceArgType; + isStackTypePointer(item: any): item is PointerArgType; + isStackTypeBuffer(item: any): item is BufferArgType; + isStackTypeStruct(item: any): item is StructArgType; + isRpcResponseStackItem(item: any): item is RpcResponseStackItem; +}; +export { TypeChecker }; diff --git a/packages/neon-dappkit-types/dist/TypeChecker.js b/packages/neon-dappkit-types/dist/TypeChecker.js new file mode 100644 index 0000000..de7bc0b --- /dev/null +++ b/packages/neon-dappkit-types/dist/TypeChecker.js @@ -0,0 +1,60 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.TypeChecker = void 0; +const TypeChecker = { + isStackTypeAny(item) { + return typeof item === 'object' && item.type === 'Any'; + }, + isStackTypeBoolean(item) { + return typeof item === 'object' && item.type === 'Boolean' && typeof item.value === 'boolean'; + }, + isStackTypeInteger(item) { + return typeof item === 'object' && item.type === 'Integer' && typeof item.value === 'string'; + }, + isStackTypeArray(item) { + return (typeof item === 'object' && + item.type === 'Array' && + Array.isArray(item.value) && + item.value.every((i) => TypeChecker.isRpcResponseStackItem(i))); + }, + isStackTypeMap(item) { + return (typeof item === 'object' && + item.type === 'Map' && + Array.isArray(item.value) && + item.value.every((i) => TypeChecker.isRpcResponseStackItem(i.key) && TypeChecker.isRpcResponseStackItem(i.value))); + }, + isStackTypeByteString(item) { + return typeof item === 'object' && item.type === 'ByteString' && typeof item.value === 'string'; + }, + isStackTypeInteropInterface(item) { + return (typeof item === 'object' && + item.type === 'InteropInterface' && + typeof item.interface === 'string' && + typeof item.id === 'string'); + }, + isStackTypePointer(item) { + return typeof item === 'object' && item.type === 'Pointer' && typeof item.value === 'string'; + }, + isStackTypeBuffer(item) { + return typeof item === 'object' && item.type === 'Buffer' && typeof item.value === 'string'; + }, + isStackTypeStruct(item) { + return (typeof item === 'object' && + item.type === 'Struct' && + Array.isArray(item.value) && + item.value.every((i) => TypeChecker.isRpcResponseStackItem(i))); + }, + isRpcResponseStackItem(item) { + return (TypeChecker.isStackTypeAny(item) || + TypeChecker.isStackTypeBoolean(item) || + TypeChecker.isStackTypeInteger(item) || + TypeChecker.isStackTypeArray(item) || + TypeChecker.isStackTypeMap(item) || + TypeChecker.isStackTypeByteString(item) || + TypeChecker.isStackTypeInteropInterface(item) || + TypeChecker.isStackTypePointer(item) || + TypeChecker.isStackTypeBuffer(item) || + TypeChecker.isStackTypeStruct(item)); + }, +}; +exports.TypeChecker = TypeChecker; diff --git a/packages/neon-dappkit-types/dist/index.d.ts b/packages/neon-dappkit-types/dist/index.d.ts index 8f90c7c..fcbd930 100644 --- a/packages/neon-dappkit-types/dist/index.d.ts +++ b/packages/neon-dappkit-types/dist/index.d.ts @@ -2,3 +2,4 @@ export * from './Neo3EventListener'; export * from './Neo3Invoker'; export * from './Neo3Parser'; export * from './Neo3Signer'; +export * from './TypeChecker'; diff --git a/packages/neon-dappkit-types/dist/index.js b/packages/neon-dappkit-types/dist/index.js index 41720f6..4ba1924 100644 --- a/packages/neon-dappkit-types/dist/index.js +++ b/packages/neon-dappkit-types/dist/index.js @@ -18,3 +18,4 @@ __exportStar(require("./Neo3EventListener"), exports); __exportStar(require("./Neo3Invoker"), exports); __exportStar(require("./Neo3Parser"), exports); __exportStar(require("./Neo3Signer"), exports); +__exportStar(require("./TypeChecker"), exports); diff --git a/packages/neon-dappkit-types/docs/index.html b/packages/neon-dappkit-types/docs/index.html index 5600693..123a7eb 100644 --- a/packages/neon-dappkit-types/docs/index.html +++ b/packages/neon-dappkit-types/docs/index.html @@ -143,7 +143,8 @@

WitnessCondition
  • ABI_TYPES
  • HINT_TYPES
  • -
  • INTERNAL_TYPES
  • +
  • INTERNAL_TYPES
  • +
  • TypeChecker
  • Generated using TypeDoc

    \ No newline at end of file diff --git a/packages/neon-dappkit-types/docs/modules.html b/packages/neon-dappkit-types/docs/modules.html index 473d0b9..f48a80f 100644 --- a/packages/neon-dappkit-types/docs/modules.html +++ b/packages/neon-dappkit-types/docs/modules.html @@ -89,6 +89,7 @@

    Variables

    ABI_TYPES HINT_TYPES INTERNAL_TYPES +TypeChecker
    +
  • INTERNAL_TYPES
  • +
  • TypeChecker
  • Generated using TypeDoc

    \ No newline at end of file diff --git a/packages/neon-dappkit-types/docs/variables/TypeChecker.html b/packages/neon-dappkit-types/docs/variables/TypeChecker.html new file mode 100644 index 0000000..7e8bf6e --- /dev/null +++ b/packages/neon-dappkit-types/docs/variables/TypeChecker.html @@ -0,0 +1,256 @@ +TypeChecker | @cityofzion/neon-dappkit-types
    +
    + +
    +
    +
    +
    + +

    Variable TypeCheckerConst

    +
    TypeChecker: {
        isRpcResponseStackItem(item: any): item is RpcResponseStackItem;
        isStackTypeAny(item: any): item is AnyArgType;
        isStackTypeArray(item: any): item is ArrayResponseArgType;
        isStackTypeBoolean(item: any): item is BooleanArgType;
        isStackTypeBuffer(item: any): item is BufferArgType;
        isStackTypeByteString(item: any): item is ByteStringArgType;
        isStackTypeInteger(item: any): item is IntegerArgType;
        isStackTypeInteropInterface(item: any): item is InteropInterfaceArgType;
        isStackTypeMap(item: any): item is MapResponseArgType;
        isStackTypePointer(item: any): item is PointerArgType;
        isStackTypeStruct(item: any): item is StructArgType;
    } = ...
    +
    +

    Type declaration

    +
    +
    +
    +

    Generated using TypeDoc

    +
    \ No newline at end of file diff --git a/packages/neon-dappkit-types/src/TypeChecker.ts b/packages/neon-dappkit-types/src/TypeChecker.ts new file mode 100644 index 0000000..f5f2117 --- /dev/null +++ b/packages/neon-dappkit-types/src/TypeChecker.ts @@ -0,0 +1,84 @@ +import { + AnyArgType, + BooleanArgType, + IntegerArgType, + ArrayResponseArgType, + MapResponseArgType, + ByteStringArgType, + InteropInterfaceArgType, + PointerArgType, + BufferArgType, + StructArgType, + RpcResponseStackItem, +} from './Neo3Invoker' + +const TypeChecker = { + isStackTypeAny(item: any): item is AnyArgType { + return typeof item === 'object' && item.type === 'Any' + }, + isStackTypeBoolean(item: any): item is BooleanArgType { + return typeof item === 'object' && item.type === 'Boolean' && typeof item.value === 'boolean' + }, + isStackTypeInteger(item: any): item is IntegerArgType { + return typeof item === 'object' && item.type === 'Integer' && typeof item.value === 'string' + }, + isStackTypeArray(item: any): item is ArrayResponseArgType { + return ( + typeof item === 'object' && + item.type === 'Array' && + Array.isArray(item.value) && + item.value.every((i: any) => TypeChecker.isRpcResponseStackItem(i)) + ) + }, + isStackTypeMap(item: any): item is MapResponseArgType { + return ( + typeof item === 'object' && + item.type === 'Map' && + Array.isArray(item.value) && + item.value.every( + (i: any) => TypeChecker.isRpcResponseStackItem(i.key) && TypeChecker.isRpcResponseStackItem(i.value), + ) + ) + }, + isStackTypeByteString(item: any): item is ByteStringArgType { + return typeof item === 'object' && item.type === 'ByteString' && typeof item.value === 'string' + }, + isStackTypeInteropInterface(item: any): item is InteropInterfaceArgType { + return ( + typeof item === 'object' && + item.type === 'InteropInterface' && + typeof item.interface === 'string' && + typeof item.id === 'string' + ) + }, + isStackTypePointer(item: any): item is PointerArgType { + return typeof item === 'object' && item.type === 'Pointer' && typeof item.value === 'string' + }, + isStackTypeBuffer(item: any): item is BufferArgType { + return typeof item === 'object' && item.type === 'Buffer' && typeof item.value === 'string' + }, + isStackTypeStruct(item: any): item is StructArgType { + return ( + typeof item === 'object' && + item.type === 'Struct' && + Array.isArray(item.value) && + item.value.every((i: any) => TypeChecker.isRpcResponseStackItem(i)) + ) + }, + isRpcResponseStackItem(item: any): item is RpcResponseStackItem { + return ( + TypeChecker.isStackTypeAny(item) || + TypeChecker.isStackTypeBoolean(item) || + TypeChecker.isStackTypeInteger(item) || + TypeChecker.isStackTypeArray(item) || + TypeChecker.isStackTypeMap(item) || + TypeChecker.isStackTypeByteString(item) || + TypeChecker.isStackTypeInteropInterface(item) || + TypeChecker.isStackTypePointer(item) || + TypeChecker.isStackTypeBuffer(item) || + TypeChecker.isStackTypeStruct(item) + ) + }, +} + +export { TypeChecker } diff --git a/packages/neon-dappkit-types/src/index.ts b/packages/neon-dappkit-types/src/index.ts index 1ef618d..f85a4e2 100644 --- a/packages/neon-dappkit-types/src/index.ts +++ b/packages/neon-dappkit-types/src/index.ts @@ -2,3 +2,4 @@ export * from './Neo3EventListener' export * from './Neo3Invoker' export * from './Neo3Parser' export * from './Neo3Signer' +export * from './TypeChecker' diff --git a/packages/neon-dappkit/dist/NeonInvoker.d.ts b/packages/neon-dappkit/dist/NeonInvoker.d.ts index 1b59e7b..1b7fe1b 100644 --- a/packages/neon-dappkit/dist/NeonInvoker.d.ts +++ b/packages/neon-dappkit/dist/NeonInvoker.d.ts @@ -1,7 +1,6 @@ -import { ContractInvocationMulti, Signer, Neo3Invoker, Arg, InvokeResult, RpcResponseStackItem } from '@cityofzion/neon-dappkit-types'; +import { ContractInvocationMulti, Signer, Neo3Invoker, Arg, InvokeResult, RpcResponseStackItem, TypeChecker } from '@cityofzion/neon-dappkit-types'; import { api } from '@cityofzion/neon-js'; import type * as NeonTypes from '@cityofzion/neon-core'; -import * as typeChecker from './typeChecker'; export type RpcConfig = { rpcAddress: string; networkMagic: number; @@ -46,4 +45,4 @@ export declare class NeonInvoker implements Neo3Invoker { static buildMultipleSigner(optionAccounts: (NeonTypes.wallet.Account | undefined)[], signers?: Signer[]): NeonTypes.tx.Signer[]; private normalizeAccountArray; } -export { typeChecker }; +export { TypeChecker }; diff --git a/packages/neon-dappkit/dist/NeonInvoker.js b/packages/neon-dappkit/dist/NeonInvoker.js index 13d5a25..ccca2a0 100644 --- a/packages/neon-dappkit/dist/NeonInvoker.js +++ b/packages/neon-dappkit/dist/NeonInvoker.js @@ -1,27 +1,4 @@ "use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -32,10 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.typeChecker = exports.NeonInvoker = void 0; +exports.TypeChecker = exports.NeonInvoker = void 0; +const neon_dappkit_types_1 = require("@cityofzion/neon-dappkit-types"); +Object.defineProperty(exports, "TypeChecker", { enumerable: true, get: function () { return neon_dappkit_types_1.TypeChecker; } }); const neon_js_1 = require("@cityofzion/neon-js"); -const typeChecker = __importStar(require("./typeChecker")); -exports.typeChecker = typeChecker; class NeonInvoker { constructor(options) { this.options = options; diff --git a/packages/neon-dappkit/dist/NeonInvoker.spec.js b/packages/neon-dappkit/dist/NeonInvoker.spec.js index 0375621..e3f3d34 100644 --- a/packages/neon-dappkit/dist/NeonInvoker.spec.js +++ b/packages/neon-dappkit/dist/NeonInvoker.spec.js @@ -98,7 +98,7 @@ describe('NeonInvoker', function () { ], }); assert_1.default.equal(resp.state, 'HALT', 'success'); - if (index_1.typeChecker.isStackTypeByteString(resp.stack[0])) { + if (index_1.TypeChecker.isStackTypeByteString(resp.stack[0])) { assert_1.default.equal(resp.stack[0].value, 'R0FT', 'correct symbol'); } else { @@ -124,13 +124,13 @@ describe('NeonInvoker', function () { ], }); assert_1.default.equal(resp.state, 'HALT', 'success'); - if (index_1.typeChecker.isStackTypeInteger(resp.stack[0])) { + if (index_1.TypeChecker.isStackTypeInteger(resp.stack[0])) { assert_1.default.equal(resp.stack[0].value, '-100'); } else { assert_1.default.fail('stack return is not Integer'); } - if (index_1.typeChecker.isStackTypeInteger(resp.stack[1])) { + if (index_1.TypeChecker.isStackTypeInteger(resp.stack[1])) { assert_1.default.equal(resp.stack[1].value, '1234'); } else { @@ -166,25 +166,25 @@ describe('NeonInvoker', function () { ], }); assert_1.default.equal(resp.state, 'HALT', 'success'); - if (index_1.typeChecker.isStackTypeBoolean(resp.stack[0])) { + if (index_1.TypeChecker.isStackTypeBoolean(resp.stack[0])) { assert_1.default.equal(resp.stack[0].value, true); } else { assert_1.default.fail('stack return is not Boolean'); } - if (index_1.typeChecker.isStackTypeBoolean(resp.stack[1])) { + if (index_1.TypeChecker.isStackTypeBoolean(resp.stack[1])) { assert_1.default.equal(resp.stack[1].value, false); } else { assert_1.default.fail('stack return is not Boolean'); } - if (index_1.typeChecker.isStackTypeBoolean(resp.stack[2])) { + if (index_1.TypeChecker.isStackTypeBoolean(resp.stack[2])) { assert_1.default.equal(resp.stack[2].value, true); } else { assert_1.default.fail('stack return is not Boolean'); } - if (index_1.typeChecker.isStackTypeBoolean(resp.stack[3])) { + if (index_1.TypeChecker.isStackTypeBoolean(resp.stack[3])) { assert_1.default.equal(resp.stack[3].value, false); } else { @@ -220,25 +220,25 @@ describe('NeonInvoker', function () { ], }); assert_1.default.equal(resp.state, 'HALT', 'success'); - if (index_1.typeChecker.isStackTypeBoolean(resp.stack[0])) { + if (index_1.TypeChecker.isStackTypeBoolean(resp.stack[0])) { assert_1.default.equal(resp.stack[0].value, true); } else { assert_1.default.fail('stack return is not Boolean'); } - if (index_1.typeChecker.isStackTypeBoolean(resp.stack[1])) { + if (index_1.TypeChecker.isStackTypeBoolean(resp.stack[1])) { assert_1.default.equal(resp.stack[1].value, false); } else { assert_1.default.fail('stack return is not Boolean'); } - if (index_1.typeChecker.isStackTypeBoolean(resp.stack[2])) { + if (index_1.TypeChecker.isStackTypeBoolean(resp.stack[2])) { assert_1.default.equal(resp.stack[2].value, true); } else { assert_1.default.fail('stack return is not Boolean'); } - if (index_1.typeChecker.isStackTypeBoolean(resp.stack[3])) { + if (index_1.TypeChecker.isStackTypeBoolean(resp.stack[3])) { assert_1.default.equal(resp.stack[3].value, false); } else { @@ -259,7 +259,7 @@ describe('NeonInvoker', function () { ], }); assert_1.default.equal(resp.state, 'HALT', 'success'); - if (index_1.typeChecker.isStackTypeArray(resp.stack[0])) { + if (index_1.TypeChecker.isStackTypeArray(resp.stack[0])) { assert_1.default.deepEqual(resp.stack[0].value, [ { type: 'Integer', @@ -302,13 +302,13 @@ describe('NeonInvoker', function () { ], }); assert_1.default.equal(resp.state, 'HALT', 'success'); - if (index_1.typeChecker.isStackTypeByteString(resp.stack[0])) { + if (index_1.TypeChecker.isStackTypeByteString(resp.stack[0])) { assert_1.default.deepEqual(resp.stack[0].value, 'dGVzdGluZyBzdHJpbmcgcmV0dXJu'); } else { assert_1.default.fail('stack return is not ByteString'); } - if (index_1.typeChecker.isStackTypeByteString(resp.stack[1])) { + if (index_1.TypeChecker.isStackTypeByteString(resp.stack[1])) { assert_1.default.deepEqual(resp.stack[1].value, 'dGVzdGluZyBzdHJpbmcgcmV0dXJu'); } else { @@ -329,7 +329,7 @@ describe('NeonInvoker', function () { ], }); assert_1.default.equal(resp.state, 'HALT', 'success'); - if (index_1.typeChecker.isStackTypeArray(resp.stack[0])) { + if (index_1.TypeChecker.isStackTypeArray(resp.stack[0])) { assert_1.default.deepEqual(resp.stack[0].value, [ { type: 'Integer', @@ -367,7 +367,7 @@ describe('NeonInvoker', function () { ], }); assert_1.default.equal(resp.state, 'HALT', 'success'); - if (index_1.typeChecker.isStackTypeMap(resp.stack[0])) { + if (index_1.TypeChecker.isStackTypeMap(resp.stack[0])) { assert_1.default.deepEqual(resp.stack[0].value, [ { key: { diff --git a/packages/neon-dappkit/src/NeonInvoker.spec.ts b/packages/neon-dappkit/src/NeonInvoker.spec.ts index 166abdc..3c5d8d8 100644 --- a/packages/neon-dappkit/src/NeonInvoker.spec.ts +++ b/packages/neon-dappkit/src/NeonInvoker.spec.ts @@ -1,5 +1,5 @@ import { ContractInvocationMulti } from '@cityofzion/neon-dappkit-types' -import { NeonInvoker, typeChecker } from './index' +import { NeonInvoker, TypeChecker } from './index' import { wallet, tx } from '@cityofzion/neon-js' import assert from 'assert' @@ -108,7 +108,7 @@ describe('NeonInvoker', function () { }) assert.equal(resp.state, 'HALT', 'success') - if (typeChecker.isStackTypeByteString(resp.stack[0])) { + if (TypeChecker.isStackTypeByteString(resp.stack[0])) { assert.equal(resp.stack[0].value, 'R0FT', 'correct symbol') } else { assert.fail('stack return is not ByteString') @@ -136,13 +136,13 @@ describe('NeonInvoker', function () { }) assert.equal(resp.state, 'HALT', 'success') - if (typeChecker.isStackTypeInteger(resp.stack[0])) { + if (TypeChecker.isStackTypeInteger(resp.stack[0])) { assert.equal(resp.stack[0].value, '-100') } else { assert.fail('stack return is not Integer') } - if (typeChecker.isStackTypeInteger(resp.stack[1])) { + if (TypeChecker.isStackTypeInteger(resp.stack[1])) { assert.equal(resp.stack[1].value, '1234') } else { assert.fail('stack return is not Integer') @@ -180,22 +180,22 @@ describe('NeonInvoker', function () { }) assert.equal(resp.state, 'HALT', 'success') - if (typeChecker.isStackTypeBoolean(resp.stack[0])) { + if (TypeChecker.isStackTypeBoolean(resp.stack[0])) { assert.equal(resp.stack[0].value, true) } else { assert.fail('stack return is not Boolean') } - if (typeChecker.isStackTypeBoolean(resp.stack[1])) { + if (TypeChecker.isStackTypeBoolean(resp.stack[1])) { assert.equal(resp.stack[1].value, false) } else { assert.fail('stack return is not Boolean') } - if (typeChecker.isStackTypeBoolean(resp.stack[2])) { + if (TypeChecker.isStackTypeBoolean(resp.stack[2])) { assert.equal(resp.stack[2].value, true) } else { assert.fail('stack return is not Boolean') } - if (typeChecker.isStackTypeBoolean(resp.stack[3])) { + if (TypeChecker.isStackTypeBoolean(resp.stack[3])) { assert.equal(resp.stack[3].value, false) } else { assert.fail('stack return is not Boolean') @@ -233,22 +233,22 @@ describe('NeonInvoker', function () { }) assert.equal(resp.state, 'HALT', 'success') - if (typeChecker.isStackTypeBoolean(resp.stack[0])) { + if (TypeChecker.isStackTypeBoolean(resp.stack[0])) { assert.equal(resp.stack[0].value, true) } else { assert.fail('stack return is not Boolean') } - if (typeChecker.isStackTypeBoolean(resp.stack[1])) { + if (TypeChecker.isStackTypeBoolean(resp.stack[1])) { assert.equal(resp.stack[1].value, false) } else { assert.fail('stack return is not Boolean') } - if (typeChecker.isStackTypeBoolean(resp.stack[2])) { + if (TypeChecker.isStackTypeBoolean(resp.stack[2])) { assert.equal(resp.stack[2].value, true) } else { assert.fail('stack return is not Boolean') } - if (typeChecker.isStackTypeBoolean(resp.stack[3])) { + if (TypeChecker.isStackTypeBoolean(resp.stack[3])) { assert.equal(resp.stack[3].value, false) } else { assert.fail('stack return is not Boolean') @@ -271,7 +271,7 @@ describe('NeonInvoker', function () { }) assert.equal(resp.state, 'HALT', 'success') - if (typeChecker.isStackTypeArray(resp.stack[0])) { + if (TypeChecker.isStackTypeArray(resp.stack[0])) { assert.deepEqual(resp.stack[0].value, [ { type: 'Integer', @@ -316,13 +316,13 @@ describe('NeonInvoker', function () { }) assert.equal(resp.state, 'HALT', 'success') - if (typeChecker.isStackTypeByteString(resp.stack[0])) { + if (TypeChecker.isStackTypeByteString(resp.stack[0])) { assert.deepEqual(resp.stack[0].value, 'dGVzdGluZyBzdHJpbmcgcmV0dXJu') } else { assert.fail('stack return is not ByteString') } - if (typeChecker.isStackTypeByteString(resp.stack[1])) { + if (TypeChecker.isStackTypeByteString(resp.stack[1])) { assert.deepEqual(resp.stack[1].value, 'dGVzdGluZyBzdHJpbmcgcmV0dXJu') } else { assert.fail('stack return is not ByteString') @@ -345,7 +345,7 @@ describe('NeonInvoker', function () { }) assert.equal(resp.state, 'HALT', 'success') - if (typeChecker.isStackTypeArray(resp.stack[0])) { + if (TypeChecker.isStackTypeArray(resp.stack[0])) { assert.deepEqual(resp.stack[0].value, [ { type: 'Integer', @@ -385,7 +385,7 @@ describe('NeonInvoker', function () { }) assert.equal(resp.state, 'HALT', 'success') - if (typeChecker.isStackTypeMap(resp.stack[0])) { + if (TypeChecker.isStackTypeMap(resp.stack[0])) { assert.deepEqual(resp.stack[0].value, [ { key: { diff --git a/packages/neon-dappkit/src/NeonInvoker.ts b/packages/neon-dappkit/src/NeonInvoker.ts index cda47b4..a61e8e0 100644 --- a/packages/neon-dappkit/src/NeonInvoker.ts +++ b/packages/neon-dappkit/src/NeonInvoker.ts @@ -5,10 +5,10 @@ import { Arg, InvokeResult, RpcResponseStackItem, + TypeChecker, } from '@cityofzion/neon-dappkit-types' import { tx, u, rpc, sc, api, wallet } from '@cityofzion/neon-js' import type * as NeonTypes from '@cityofzion/neon-core' -import * as typeChecker from './typeChecker' export type RpcConfig = { rpcAddress: string @@ -267,4 +267,4 @@ export class NeonInvoker implements Neo3Invoker { } } -export { typeChecker } +export { TypeChecker } diff --git a/packages/neon-dappkit/src/typeChecker.ts b/packages/neon-dappkit/src/typeChecker.ts deleted file mode 100644 index 6c6f391..0000000 --- a/packages/neon-dappkit/src/typeChecker.ts +++ /dev/null @@ -1,78 +0,0 @@ -import { - AnyArgType, - BooleanArgType, - IntegerArgType, - ArrayResponseArgType, - MapResponseArgType, - ByteStringArgType, - InteropInterfaceArgType, - PointerArgType, - BufferArgType, - StructArgType, - RpcResponseStackItem, -} from '@cityofzion/neon-dappkit-types' - -export function isStackTypeAny(item: any): item is AnyArgType { - return typeof item === 'object' && item.type === 'Any' -} -export function isStackTypeBoolean(item: any): item is BooleanArgType { - return typeof item === 'object' && item.type === 'Boolean' && typeof item.value === 'boolean' -} -export function isStackTypeInteger(item: any): item is IntegerArgType { - return typeof item === 'object' && item.type === 'Integer' && typeof item.value === 'string' -} -export function isStackTypeArray(item: any): item is ArrayResponseArgType { - return ( - typeof item === 'object' && - item.type === 'Array' && - Array.isArray(item.value) && - item.value.every((i: any) => isRpcResponseStackItem(i)) - ) -} -export function isStackTypeMap(item: any): item is MapResponseArgType { - return ( - typeof item === 'object' && - item.type === 'Map' && - Array.isArray(item.value) && - item.value.every((i: any) => isRpcResponseStackItem(i.key) && isRpcResponseStackItem(i.value)) - ) -} -export function isStackTypeByteString(item: any): item is ByteStringArgType { - return typeof item === 'object' && item.type === 'ByteString' && typeof item.value === 'string' -} -export function isStackTypeInteropInterface(item: any): item is InteropInterfaceArgType { - return ( - typeof item === 'object' && - item.type === 'InteropInterface' && - typeof item.interface === 'string' && - typeof item.id === 'string' - ) -} -export function isStackTypePointer(item: any): item is PointerArgType { - return typeof item === 'object' && item.type === 'Pointer' && typeof item.value === 'string' -} -export function isStackTypeBuffer(item: any): item is BufferArgType { - return typeof item === 'object' && item.type === 'Buffer' && typeof item.value === 'string' -} -export function isStackTypeStruct(item: any): item is StructArgType { - return ( - typeof item === 'object' && - item.type === 'Struct' && - Array.isArray(item.value) && - item.value.every((i: any) => isRpcResponseStackItem(i)) - ) -} -export function isRpcResponseStackItem(item: any): item is RpcResponseStackItem { - return ( - isStackTypeAny(item) || - isStackTypeBoolean(item) || - isStackTypeInteger(item) || - isStackTypeArray(item) || - isStackTypeMap(item) || - isStackTypeByteString(item) || - isStackTypeInteropInterface(item) || - isStackTypePointer(item) || - isStackTypeBuffer(item) || - isStackTypeStruct(item) - ) -}