From 33db47243a0259ea12702b5ac317d7f262b093e4 Mon Sep 17 00:00:00 2001 From: joon9823 Date: Mon, 25 Mar 2024 13:58:07 +0900 Subject: [PATCH] Add view and view batch endpoints --- package-lock.json | 4 ++-- package.json | 2 +- src/client/lcd/api/MoveAPI.ts | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index dc7171d..b6efb6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@initia/initia.js", - "version": "0.1.36", + "version": "0.1.37", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@initia/initia.js", - "version": "0.1.36", + "version": "0.1.37", "license": "MIT", "dependencies": { "@initia/initia.proto": "^0.1.27", diff --git a/package.json b/package.json index 4be3529..0bd8f28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@initia/initia.js", - "version": "0.1.36", + "version": "0.1.37", "description": "The JavaScript SDK for Initia", "license": "MIT", "author": "InitiaLabs", diff --git a/src/client/lcd/api/MoveAPI.ts b/src/client/lcd/api/MoveAPI.ts index 2c2ac90..d09eba1 100644 --- a/src/client/lcd/api/MoveAPI.ts +++ b/src/client/lcd/api/MoveAPI.ts @@ -35,6 +35,25 @@ export interface TableInfo { value_type: string; } +export interface ViewRequest { + address: AccAddress; + module_name: string; + function_name: string; + type_args: string[]; + args: string[]; +} + +export interface ViewResponse { + data: string; + events: VMEvent[]; + gas_used: string; +} + +export interface VMEvent { + type_tag: string; + data: string; +} + export class MoveAPI extends BaseAPI { public async modules( address: AccAddress, @@ -133,6 +152,30 @@ export class MoveAPI extends BaseAPI { ); } + public async view( + address: AccAddress, + moduleName: string, + functionName: string, + typeArgs: string[] = [], + args: string[] = [] + ): Promise { + return this.c.post(`/initia/move/v1/view`, { + address, + module_name: moduleName, + function_name: functionName, + type_args: typeArgs, + args, + }); + } + + public async viewBatch(requests: ViewRequest[]): Promise { + return this.c + .post<{ responses: ViewResponse[] }>(`/initia/move/v1/view/batch`, { + requests, + }) + .then(d => d.responses); + } + public async resources( address: AccAddress, params: Partial = {}