Skip to content

Commit

Permalink
Abstract QuerierBase (#59)
Browse files Browse the repository at this point in the history
* introduce new abstract QuerierBase

* bump to v0.2.15
  • Loading branch information
Kiruse committed Nov 1, 2022
1 parent 511ac92 commit 3f64c2b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
12 changes: 10 additions & 2 deletions src/backend/querier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.`)
}
Expand Down

0 comments on commit 3f64c2b

Please sign in to comment.