Skip to content

Commit

Permalink
Add execute/scriptJSON and batch info
Browse files Browse the repository at this point in the history
  • Loading branch information
joon9823 committed Apr 9, 2024
1 parent 23cf131 commit 234cabb
Show file tree
Hide file tree
Showing 18 changed files with 1,002 additions and 44 deletions.
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@initia/initia.js",
"version": "0.1.41",
"version": "0.1.42",
"description": "The JavaScript SDK for Initia",
"license": "MIT",
"author": "InitiaLabs",
Expand Down Expand Up @@ -86,8 +86,8 @@
"webpack-cli": "^4.10.0"
},
"dependencies": {
"@initia/initia.proto": "^0.1.31",
"@initia/opinit.proto": "^0.0.3",
"@initia/initia.proto": "^0.1.32",
"@initia/opinit.proto": "^0.0.5",
"@ledgerhq/hw-transport": "^6.27.12",
"@ledgerhq/hw-transport-webhid": "^6.27.12",
"@ledgerhq/hw-transport-webusb": "^6.27.12",
Expand Down
24 changes: 24 additions & 0 deletions src/client/lcd/api/MoveAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,30 @@ export class MoveAPI extends BaseAPI {
.then(d => d.responses);
}

public async viewJSON(
address: AccAddress,
moduleName: string,
functionName: string,
typeArgs: string[] = [],
args: string[] = []
): Promise<ViewResponse> {
return this.c.post<ViewResponse>(`/initia/move/v1/view/json`, {
address,
module_name: moduleName,
function_name: functionName,
type_args: typeArgs,
args,
});
}

public async viewBatchJSON(requests: ViewRequest[]): Promise<ViewResponse[]> {
return this.c
.post<{ responses: ViewResponse[] }>(`/initia/move/v1/view/json/batch`, {
requests,
})
.then(d => d.responses);
}

public async resources(
address: AccAddress,
params: Partial<PaginationOptions & APIParams> = {}
Expand Down
23 changes: 19 additions & 4 deletions src/client/lcd/api/OphostAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ export namespace BridgeInfo {
}

export interface OutputInfo {
bridge_id: number;
bridge_id?: number;
output_index: number;
output_proposal: Output;
}

export namespace OutputInfo {
export interface Data {
bridge_id: string;
bridge_id?: string;
output_index: string;
output_proposal: Output.Data;
}
Expand Down Expand Up @@ -105,6 +105,21 @@ export class OphostAPI extends BaseAPI {
.then(d => d.token_pair);
}

public async lastFinalizedOutput(
bridgeId: number,
params: Partial<PaginationOptions & APIParams> = {}
): Promise<OutputInfo> {
return this.c
.get<OutputInfo.Data>(
`/opinit/ophost/v1/bridges/${bridgeId}/last_finalized_output`,
params
)
.then(d => ({
output_index: Number.parseInt(d.output_index),
output_proposal: Output.fromData(d.output_proposal),
}));
}

public async outputInfos(
bridgeId: number,
params: Partial<PaginationOptions & APIParams> = {}
Expand All @@ -116,7 +131,7 @@ export class OphostAPI extends BaseAPI {
}>(`/opinit/ophost/v1/bridges/${bridgeId}/outputs`, params)
.then(d => [
d.output_proposals.map(info => ({
bridge_id: Number.parseInt(info.bridge_id),
bridge_id: Number.parseInt(info.bridge_id ?? `${bridgeId}`),
output_index: Number.parseInt(info.output_index),
output_proposal: Output.fromData(info.output_proposal),
})),
Expand All @@ -135,7 +150,7 @@ export class OphostAPI extends BaseAPI {
params
)
.then(d => ({
bridge_id: Number.parseInt(d.bridge_id),
bridge_id: Number.parseInt(d.bridge_id ?? `${bridgeId}`),
output_index: Number.parseInt(d.output_index),
output_proposal: Output.fromData(d.output_proposal),
}));
Expand Down
35 changes: 35 additions & 0 deletions src/core/Msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,17 @@ import {
MoveMsg,
MsgPublish,
MsgExecute,
MsgExecuteJSON,
MsgScript,
MsgScriptJSON,
MsgUpdateMoveParams,
MsgWhitelist,
MsgDelist,
MsgGovExecute,
MsgGovExecuteJSON,
MsgGovPublish,
MsgGovScript,
MsgGovScriptJSON,
} from './move';
import {
MstakingMsg,
Expand Down Expand Up @@ -157,6 +161,7 @@ import {
MsgFinalizeTokenWithdrawal,
MsgUpdateProposer,
MsgUpdateChallenger,
MsgUpdateBatchInfo,
MsgUpdateOphostParams,
} from './ophost';
import {
Expand Down Expand Up @@ -493,8 +498,12 @@ export namespace Msg {
return MsgPublish.fromAmino(data);
case 'move/MsgExecute':
return MsgExecute.fromAmino(data);
case 'move/MsgExecuteJSON':
return MsgExecuteJSON.fromAmino(data);
case 'move/MsgScript':
return MsgScript.fromAmino(data);
case 'move/MsgScriptJSON':
return MsgScriptJSON.fromAmino(data);
case 'move/MsgUpdateParams':
return MsgUpdateMoveParams.fromAmino(data);
case 'move/MsgWhitelist':
Expand All @@ -503,10 +512,14 @@ export namespace Msg {
return MsgDelist.fromAmino(data);
case 'move/MsgGovExecute':
return MsgGovExecute.fromAmino(data);
case 'move/MsgGovExecuteJSON':
return MsgGovExecuteJSON.fromAmino(data);
case 'move/MsgGovPublish':
return MsgGovPublish.fromAmino(data);
case 'move/MsgGovScript':
return MsgGovScript.fromAmino(data);
case 'move/MsgGovScriptJSON':
return MsgGovScriptJSON.fromAmino(data);

// mstaking
case 'mstaking/MsgDelegate':
Expand Down Expand Up @@ -555,6 +568,8 @@ export namespace Msg {
return MsgUpdateProposer.fromAmino(data);
case 'ophost/MsgUpdateChallenger':
return MsgUpdateChallenger.fromAmino(data);
case 'ophost/MsgUpdateBatchInfo':
return MsgUpdateBatchInfo.fromAmino(data);
case 'ophost/MsgUpdateParams':
return MsgUpdateOphostParams.fromAmino(data);

Expand Down Expand Up @@ -865,8 +880,12 @@ export namespace Msg {
return MsgPublish.fromData(data);
case '/initia.move.v1.MsgExecute':
return MsgExecute.fromData(data);
case '/initia.move.v1.MsgExecuteJSON':
return MsgExecuteJSON.fromData(data);
case '/initia.move.v1.MsgScript':
return MsgScript.fromData(data);
case '/initia.move.v1.MsgScriptJSON':
return MsgScriptJSON.fromData(data);
case '/initia.move.v1.MsgUpdateParams':
return MsgUpdateMoveParams.fromData(data);
case '/initia.move.v1.MsgWhitelist':
Expand All @@ -875,10 +894,14 @@ export namespace Msg {
return MsgDelist.fromData(data);
case '/initia.move.v1.MsgGovExecute':
return MsgGovExecute.fromData(data);
case '/initia.move.v1.MsgGovExecuteJSON':
return MsgGovExecuteJSON.fromData(data);
case '/initia.move.v1.MsgGovPublish':
return MsgGovPublish.fromData(data);
case '/initia.move.v1.MsgGovScript':
return MsgGovScript.fromData(data);
case '/initia.move.v1.MsgGovScriptJSON':
return MsgGovScriptJSON.fromData(data);

// mstaking
case '/initia.mstaking.v1.MsgDelegate':
Expand Down Expand Up @@ -927,6 +950,8 @@ export namespace Msg {
return MsgUpdateProposer.fromData(data);
case '/opinit.ophost.v1.MsgUpdateChallenger':
return MsgUpdateChallenger.fromData(data);
case '/opinit.ophost.v1.MsgUpdateBatchInfo':
return MsgUpdateBatchInfo.fromData(data);
case '/opinit.ophost.v1.MsgUpdateParams':
return MsgUpdateOphostParams.fromData(data);

Expand Down Expand Up @@ -1240,8 +1265,12 @@ export namespace Msg {
return MsgPublish.unpackAny(proto);
case '/initia.move.v1.MsgExecute':
return MsgExecute.unpackAny(proto);
case '/initia.move.v1.MsgExecuteJSON':
return MsgExecuteJSON.unpackAny(proto);
case '/initia.move.v1.MsgScript':
return MsgScript.unpackAny(proto);
case '/initia.move.v1.MsgScriptJSON':
return MsgScriptJSON.unpackAny(proto);
case '/initia.move.v1.MsgUpdateParams':
return MsgUpdateMoveParams.unpackAny(proto);
case '/initia.move.v1.MsgWhitelist':
Expand All @@ -1250,10 +1279,14 @@ export namespace Msg {
return MsgDelist.unpackAny(proto);
case '/initia.move.v1.MsgGovExecute':
return MsgGovExecute.unpackAny(proto);
case '/initia.move.v1.MsgGovExecuteJSON':
return MsgGovExecuteJSON.unpackAny(proto);
case '/initia.move.v1.MsgGovPublish':
return MsgGovPublish.unpackAny(proto);
case '/initia.move.v1.MsgGovScript':
return MsgGovScript.unpackAny(proto);
case '/initia.move.v1.MsgGovScriptJSON':
return MsgGovScriptJSON.unpackAny(proto);

// mstaking
case '/initia.mstaking.v1.MsgDelegate':
Expand Down Expand Up @@ -1302,6 +1335,8 @@ export namespace Msg {
return MsgUpdateProposer.unpackAny(proto);
case '/opinit.ophost.v1.MsgUpdateChallenger':
return MsgUpdateChallenger.unpackAny(proto);
case '/opinit.ophost.v1.MsgUpdateBatchInfo':
return MsgUpdateBatchInfo.unpackAny(proto);
case '/opinit.ophost.v1.MsgUpdateParams':
return MsgUpdateOphostParams.unpackAny(proto);

Expand Down
Loading

0 comments on commit 234cabb

Please sign in to comment.