From 3f64c2baccbeac327970557374f12546e6bb98a7 Mon Sep 17 00:00:00 2001 From: Kiruse <26940742+Kiruse@users.noreply.github.com> Date: Tue, 1 Nov 2022 18:31:13 +0300 Subject: [PATCH] Abstract QuerierBase (#59) * introduce new abstract QuerierBase * bump to v0.2.15 --- package.json | 2 +- src/backend/querier.ts | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index eaa0094..df75ea7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@terran-one/cosmwasm-vm-js", - "version": "0.2.14", + "version": "0.2.15", "license": "MIT", "author": "TerranOne", "main": "dist/index.js", diff --git a/src/backend/querier.ts b/src/backend/querier.ts index 33bb5d4..148fb5a 100644 --- a/src/backend/querier.ts +++ b/src/backend/querier.ts @@ -2,8 +2,10 @@ export interface IQuerier { query_raw(request: Uint8Array, gas_limit: number /* Uint64 */): Uint8Array; } -export class BasicQuerier implements IQuerier { - +/** Basic implementation of `IQuerier` with standardized `query_raw` + * which delegates to a new, abstract `handleQuery` method. + */ +export abstract class QuerierBase implements IQuerier { // eslint-disable-next-line @typescript-eslint/no-unused-vars query_raw(request: Uint8Array, gas_limit: number): Uint8Array { const queryRequest = parseQuery(request); @@ -13,7 +15,13 @@ export class BasicQuerier implements IQuerier { return objectToUint8Array({ ok: { ok: objectToBase64(this.handleQuery(queryRequest)) }}); } + + /** Handle a specific JSON query message. */ + abstract handleQuery(queryRequest: any): any; +} +/** Basic implementation which does not actually implement `handleQuery`. Intended for testing. */ +export class BasicQuerier extends QuerierBase { handleQuery(queryRequest: any): any { throw new Error(`Unimplemented - subclass BasicQuerier and provide handleQuery() implementation.`) }