Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the changed syntax of the ABCI query #129

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/provider/jsonrpc/jsonrpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import {
} from '@gnolang/tm2-js-client';
import { FunctionSignature } from '../types';
import { VMEndpoint } from '../endpoints';
import { extractStringFromResponse, prepareVMABCIQuery } from '../utility';
import {
extractStringFromResponse,
prepareVMABCIEvaluateExpressionQuery,
prepareVMABCIQuery,
prepareVMABCIRenderQuery,
} from '../utility';

/**
* Provider based on JSON-RPC HTTP requests
Expand All @@ -32,7 +37,7 @@ export class GnoJSONRPCProvider extends JSONRPCProvider implements GnoProvider {
{
request: newRequest(ABCIEndpoint.ABCI_QUERY, [
`vm/${VMEndpoint.EVALUATE}`,
prepareVMABCIQuery([packagePath, expression]),
prepareVMABCIEvaluateExpressionQuery([packagePath, expression]),
'0', // Height; not supported > 0 for now
false,
]),
Expand Down Expand Up @@ -92,7 +97,7 @@ export class GnoJSONRPCProvider extends JSONRPCProvider implements GnoProvider {
{
request: newRequest(ABCIEndpoint.ABCI_QUERY, [
`vm/${VMEndpoint.RENDER}`,
prepareVMABCIQuery([packagePath, path]),
prepareVMABCIRenderQuery([packagePath, path]),
'0', // Height; not supported > 0 for now
false,
]),
Expand Down
32 changes: 29 additions & 3 deletions src/provider/utility/provider.utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,41 @@ import { stringToBase64 } from '@gnolang/tm2-js-client';

/**
* Prepares the VM ABCI query params by concatenating them
* with a newline separation and encoding them to base64
* with new line or "." or ":" characters separation and encoding them to base64
* `evaluateExpression` uses the "." character to separate parameters.
* `getRenderOutput` uses the ":" character to separate parameters.
* @param {string[]} params the params for the ABCI call
* @param {string} separator the separator for ABCI call parameters (default: "\n")
*/
export const prepareVMABCIQuery = (params: string[]): string => {
export const prepareVMABCIQuery = (
params: string[],
separator = '\n'
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
): string => {
if (params.length == 1) {
return stringToBase64(params[0]);
}

return stringToBase64(params.join('\n'));
return stringToBase64(params.join(separator));
};

/**
* Prepare the VM ABCI `evaluateExpression` query parameters by concatenating them
* with the "." character delimiter and encoding them with base64.
* @param {string[]} params the params for the ABCI call
*/
export const prepareVMABCIEvaluateExpressionQuery = (
params: string[]
): string => {
return prepareVMABCIQuery(params, '.');
};

/**
* Prepare the VM ABCI `render` query parameters by concatenating them
* with the ":" character delimiter and encoding them with base64.
* @param {string[]} params the params for the ABCI call
*/
export const prepareVMABCIRenderQuery = (params: string[]): string => {
return prepareVMABCIQuery(params, ':');
};

export const extractStringFromResponse = (abciData: string | null): string => {
Expand Down
11 changes: 8 additions & 3 deletions src/provider/websocket/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import {
} from '@gnolang/tm2-js-client';
import { FunctionSignature } from '../types';
import { VMEndpoint } from '../endpoints';
import { extractStringFromResponse, prepareVMABCIQuery } from '../utility';
import {
extractStringFromResponse,
prepareVMABCIEvaluateExpressionQuery,
prepareVMABCIQuery,
prepareVMABCIRenderQuery,
} from '../utility';

export class GnoWSProvider extends WSProvider implements GnoProvider {
/**
Expand All @@ -27,7 +32,7 @@ export class GnoWSProvider extends WSProvider implements GnoProvider {
const response = await this.sendRequest<ABCIResponse>(
newRequest(ABCIEndpoint.ABCI_QUERY, [
`vm/${VMEndpoint.EVALUATE}`,
prepareVMABCIQuery([packagePath, expression]),
prepareVMABCIEvaluateExpressionQuery([packagePath, expression]),
'0', // Height; not supported > 0 for now
false,
])
Expand Down Expand Up @@ -87,7 +92,7 @@ export class GnoWSProvider extends WSProvider implements GnoProvider {
const response = await this.sendRequest<ABCIResponse>(
newRequest(ABCIEndpoint.ABCI_QUERY, [
`vm/${VMEndpoint.RENDER}`,
prepareVMABCIQuery([packagePath, path]),
prepareVMABCIRenderQuery([packagePath, path]),
'0', // Height; not supported > 0 for now
false,
])
Expand Down