From 234cabb957ee51d3186485c79e10f2b21dd70287 Mon Sep 17 00:00:00 2001 From: joon9823 Date: Tue, 9 Apr 2024 13:00:42 +0900 Subject: [PATCH] Add execute/scriptJSON and batch info --- package-lock.json | 20 +- package.json | 6 +- src/client/lcd/api/MoveAPI.ts | 24 +++ src/client/lcd/api/OphostAPI.ts | 23 ++- src/core/Msg.ts | 35 ++++ src/core/gov/GovParams.ts | 23 ++- src/core/move/MoveParams.ts | 15 -- src/core/move/msgs/MsgExecuteJSON.ts | 184 ++++++++++++++++++ src/core/move/msgs/MsgGovExecuteJSON.ts | 205 +++++++++++++++++++++ src/core/move/msgs/MsgGovScriptJSON.ts | 133 +++++++++++++ src/core/move/msgs/MsgScriptJSON.ts | 119 ++++++++++++ src/core/move/msgs/index.ts | 33 +++- src/core/opchild/OpchildParams.ts | 23 ++- src/core/ophost/BatchInfo.ts | 62 +++++++ src/core/ophost/BridgeConfig.ts | 16 ++ src/core/ophost/index.ts | 1 + src/core/ophost/msgs/MsgUpdateBatchInfo.ts | 118 ++++++++++++ src/core/ophost/msgs/index.ts | 6 + 18 files changed, 1002 insertions(+), 44 deletions(-) create mode 100644 src/core/move/msgs/MsgExecuteJSON.ts create mode 100644 src/core/move/msgs/MsgGovExecuteJSON.ts create mode 100644 src/core/move/msgs/MsgGovScriptJSON.ts create mode 100644 src/core/move/msgs/MsgScriptJSON.ts create mode 100644 src/core/ophost/BatchInfo.ts create mode 100644 src/core/ophost/msgs/MsgUpdateBatchInfo.ts diff --git a/package-lock.json b/package-lock.json index 7ee9aef..1841a77 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,16 @@ { "name": "@initia/initia.js", - "version": "0.1.41", + "version": "0.1.42", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@initia/initia.js", - "version": "0.1.41", + "version": "0.1.42", "license": "MIT", "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", @@ -883,9 +883,9 @@ } }, "node_modules/@initia/initia.proto": { - "version": "0.1.31", - "resolved": "https://registry.npmjs.org/@initia/initia.proto/-/initia.proto-0.1.31.tgz", - "integrity": "sha512-jCGI6ToowfoeecJL4mG26aNg99UETUovcJFOeTl6+Z0BvqHCAgb0tbO2fpD9lFBzTe2sYEVjAJh3X4QJu6Cxtg==", + "version": "0.1.32", + "resolved": "https://registry.npmjs.org/@initia/initia.proto/-/initia.proto-0.1.32.tgz", + "integrity": "sha512-Ue0Kzrpdg6p5p0EREiYEcBScAr3Dz/QGyrPiJEjrC5SROTHK5vLljPjMUUqkaF5L8NR98wW/8sDgKj3+DmrkuA==", "dependencies": { "@improbable-eng/grpc-web": "^0.15.0", "google-protobuf": "^3.21.0", @@ -894,9 +894,9 @@ } }, "node_modules/@initia/opinit.proto": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/@initia/opinit.proto/-/opinit.proto-0.0.3.tgz", - "integrity": "sha512-JDZz9124Y+WvjTl+jXQgq0CczqGwbaxSEsyfo/Gt/7wbh34GWbhZhKFiAzD8ABTLT3NIxxfw0BBlXOKHj2xfVw==", + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/@initia/opinit.proto/-/opinit.proto-0.0.5.tgz", + "integrity": "sha512-5ocJFUscR7okn7hA8YyfE5TB58Cs9+X/z3JSNppGx1Y7abDW0vTMBpRgFYn9y6A5vTscuAqrWjJhuIK7RDy4hQ==", "dependencies": { "@improbable-eng/grpc-web": "^0.15.0", "google-protobuf": "^3.21.0", diff --git a/package.json b/package.json index 0692a37..a560a17 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/client/lcd/api/MoveAPI.ts b/src/client/lcd/api/MoveAPI.ts index d09eba1..2b1f611 100644 --- a/src/client/lcd/api/MoveAPI.ts +++ b/src/client/lcd/api/MoveAPI.ts @@ -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 { + return this.c.post(`/initia/move/v1/view/json`, { + address, + module_name: moduleName, + function_name: functionName, + type_args: typeArgs, + args, + }); + } + + public async viewBatchJSON(requests: ViewRequest[]): Promise { + return this.c + .post<{ responses: ViewResponse[] }>(`/initia/move/v1/view/json/batch`, { + requests, + }) + .then(d => d.responses); + } + public async resources( address: AccAddress, params: Partial = {} diff --git a/src/client/lcd/api/OphostAPI.ts b/src/client/lcd/api/OphostAPI.ts index a2cbe6f..c057b09 100644 --- a/src/client/lcd/api/OphostAPI.ts +++ b/src/client/lcd/api/OphostAPI.ts @@ -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; } @@ -105,6 +105,21 @@ export class OphostAPI extends BaseAPI { .then(d => d.token_pair); } + public async lastFinalizedOutput( + bridgeId: number, + params: Partial = {} + ): Promise { + return this.c + .get( + `/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 = {} @@ -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), })), @@ -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), })); diff --git a/src/core/Msg.ts b/src/core/Msg.ts index 015457e..bad4db8 100644 --- a/src/core/Msg.ts +++ b/src/core/Msg.ts @@ -120,13 +120,17 @@ import { MoveMsg, MsgPublish, MsgExecute, + MsgExecuteJSON, MsgScript, + MsgScriptJSON, MsgUpdateMoveParams, MsgWhitelist, MsgDelist, MsgGovExecute, + MsgGovExecuteJSON, MsgGovPublish, MsgGovScript, + MsgGovScriptJSON, } from './move'; import { MstakingMsg, @@ -157,6 +161,7 @@ import { MsgFinalizeTokenWithdrawal, MsgUpdateProposer, MsgUpdateChallenger, + MsgUpdateBatchInfo, MsgUpdateOphostParams, } from './ophost'; import { @@ -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': @@ -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': @@ -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); @@ -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': @@ -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': @@ -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); @@ -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': @@ -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': @@ -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); diff --git a/src/core/gov/GovParams.ts b/src/core/gov/GovParams.ts index 87813f7..afe46e6 100644 --- a/src/core/gov/GovParams.ts +++ b/src/core/gov/GovParams.ts @@ -32,6 +32,7 @@ export class GovParams extends JSONSerializable< * @param min_deposit_ratio the proportion of the deposit value minimum that must be met when making a deposit. Default value: 0.01 * @param emergency_min_deposit minimum deposit for a emergency proposal to enter voting period * @param emergency_tally_interval tally interval for emergency proposal + * @param low_threshold_functions low threshold functions for emergency and expedited proposal */ constructor( min_deposit: Coins.Input, @@ -51,7 +52,8 @@ export class GovParams extends JSONSerializable< public burn_vote_veto: boolean, public min_deposit_ratio: string, emergency_min_deposit: Coins.Input, - public emergency_tally_interval: Duration + public emergency_tally_interval: Duration, + public low_threshold_functions: string[] ) { super(); this.min_deposit = new Coins(min_deposit); @@ -79,6 +81,7 @@ export class GovParams extends JSONSerializable< min_deposit_ratio, emergency_min_deposit, emergency_tally_interval, + low_threshold_functions, } = data; return new GovParams( @@ -99,7 +102,8 @@ export class GovParams extends JSONSerializable< burn_vote_veto, min_deposit_ratio, Coins.fromAmino(emergency_min_deposit), - Duration.fromAmino(emergency_tally_interval) + Duration.fromAmino(emergency_tally_interval), + low_threshold_functions ); } @@ -123,6 +127,7 @@ export class GovParams extends JSONSerializable< min_deposit_ratio, emergency_min_deposit, emergency_tally_interval, + low_threshold_functions, } = this; return { @@ -144,6 +149,7 @@ export class GovParams extends JSONSerializable< min_deposit_ratio, emergency_min_deposit: emergency_min_deposit.toAmino(), emergency_tally_interval: emergency_tally_interval.toAmino(), + low_threshold_functions, }; } @@ -167,6 +173,7 @@ export class GovParams extends JSONSerializable< min_deposit_ratio, emergency_min_deposit, emergency_tally_interval, + low_threshold_functions, } = data; return new GovParams( @@ -187,7 +194,8 @@ export class GovParams extends JSONSerializable< burn_vote_veto, min_deposit_ratio, Coins.fromData(emergency_min_deposit), - Duration.fromData(emergency_tally_interval) + Duration.fromData(emergency_tally_interval), + low_threshold_functions ); } @@ -211,6 +219,7 @@ export class GovParams extends JSONSerializable< min_deposit_ratio, emergency_min_deposit, emergency_tally_interval, + low_threshold_functions, } = this; return { @@ -232,6 +241,7 @@ export class GovParams extends JSONSerializable< min_deposit_ratio, emergency_min_deposit: emergency_min_deposit.toData(), emergency_tally_interval: emergency_tally_interval.toData(), + low_threshold_functions, }; } @@ -254,7 +264,8 @@ export class GovParams extends JSONSerializable< data.burnVoteVeto, data.minDepositRatio, Coins.fromProto(data.emergencyMinDeposit), - Duration.fromProto(data.emergencyTallyInterval as Duration.Proto) + Duration.fromProto(data.emergencyTallyInterval as Duration.Proto), + data.lowThresholdFunctions ); } @@ -278,6 +289,7 @@ export class GovParams extends JSONSerializable< min_deposit_ratio, emergency_min_deposit, emergency_tally_interval, + low_threshold_functions, } = this; return Params_pb.fromPartial({ @@ -299,6 +311,7 @@ export class GovParams extends JSONSerializable< minDepositRatio: min_deposit_ratio, emergencyMinDeposit: emergency_min_deposit.toProto(), emergencyTallyInterval: emergency_tally_interval.toProto(), + lowThresholdFunctions: low_threshold_functions, }); } } @@ -323,6 +336,7 @@ export namespace GovParams { min_deposit_ratio: string; emergency_min_deposit: Coins.Amino; emergency_tally_interval: Duration.Amino; + low_threshold_functions: string[]; } export interface Data { @@ -344,6 +358,7 @@ export namespace GovParams { min_deposit_ratio: string; emergency_min_deposit: Coins.Data; emergency_tally_interval: Duration.Data; + low_threshold_functions: string[]; } export type Proto = Params_pb; diff --git a/src/core/move/MoveParams.ts b/src/core/move/MoveParams.ts index c159b30..91a8247 100644 --- a/src/core/move/MoveParams.ts +++ b/src/core/move/MoveParams.ts @@ -9,14 +9,12 @@ export class MoveParams extends JSONSerializable< /** * @param base_denom * @param base_min_gas_price - * @param arbitrary_enabled * @param contract_shared_revenue_ratio the percentage of fees distributed to developers * @param allowed_publishers list of addresses with permission to distribute contracts, empty list is interpreted as allowing anyone to distribute */ constructor( public base_denom: string, public base_min_gas_price: string, - public arbitrary_enabled: boolean, public contract_shared_revenue_ratio: string, public allowed_publishers: string[] ) { @@ -28,7 +26,6 @@ export class MoveParams extends JSONSerializable< value: { base_denom, base_min_gas_price, - arbitrary_enabled, contract_shared_revenue_ratio, allowed_publishers, }, @@ -36,7 +33,6 @@ export class MoveParams extends JSONSerializable< return new MoveParams( base_denom, base_min_gas_price, - arbitrary_enabled, contract_shared_revenue_ratio, allowed_publishers ); @@ -46,7 +42,6 @@ export class MoveParams extends JSONSerializable< const { base_denom, base_min_gas_price, - arbitrary_enabled, contract_shared_revenue_ratio, allowed_publishers, } = this; @@ -55,7 +50,6 @@ export class MoveParams extends JSONSerializable< value: { base_denom, base_min_gas_price, - arbitrary_enabled, contract_shared_revenue_ratio, allowed_publishers, }, @@ -66,14 +60,12 @@ export class MoveParams extends JSONSerializable< const { base_denom, base_min_gas_price, - arbitrary_enabled, contract_shared_revenue_ratio, allowed_publishers, } = data; return new MoveParams( base_denom, base_min_gas_price, - arbitrary_enabled, contract_shared_revenue_ratio, allowed_publishers ); @@ -83,7 +75,6 @@ export class MoveParams extends JSONSerializable< const { base_denom, base_min_gas_price, - arbitrary_enabled, contract_shared_revenue_ratio, allowed_publishers, } = this; @@ -91,7 +82,6 @@ export class MoveParams extends JSONSerializable< '@type': '/initia.move.v1.Params', base_denom, base_min_gas_price, - arbitrary_enabled, contract_shared_revenue_ratio, allowed_publishers, }; @@ -101,7 +91,6 @@ export class MoveParams extends JSONSerializable< return new MoveParams( data.baseDenom, data.baseMinGasPrice, - data.arbitraryEnabled, data.contractSharedRevenueRatio, data.allowedPublishers ); @@ -111,14 +100,12 @@ export class MoveParams extends JSONSerializable< const { base_denom, base_min_gas_price, - arbitrary_enabled, contract_shared_revenue_ratio, allowed_publishers, } = this; return Params_pb.fromPartial({ baseDenom: base_denom, baseMinGasPrice: base_min_gas_price, - arbitraryEnabled: arbitrary_enabled, contractSharedRevenueRatio: contract_shared_revenue_ratio, allowedPublishers: allowed_publishers, }); @@ -131,7 +118,6 @@ export namespace MoveParams { value: { base_denom: string; base_min_gas_price: string; - arbitrary_enabled: boolean; contract_shared_revenue_ratio: string; allowed_publishers: string[]; }; @@ -141,7 +127,6 @@ export namespace MoveParams { '@type': '/initia.move.v1.Params'; base_denom: string; base_min_gas_price: string; - arbitrary_enabled: boolean; contract_shared_revenue_ratio: string; allowed_publishers: string[]; } diff --git a/src/core/move/msgs/MsgExecuteJSON.ts b/src/core/move/msgs/MsgExecuteJSON.ts new file mode 100644 index 0000000..3e8e133 --- /dev/null +++ b/src/core/move/msgs/MsgExecuteJSON.ts @@ -0,0 +1,184 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgExecuteJSON as MsgExecuteJSON_pb } from '@initia/initia.proto/initia/move/v1/tx'; + +export class MsgExecuteJSON extends JSONSerializable< + MsgExecuteJSON.Amino, + MsgExecuteJSON.Data, + MsgExecuteJSON.Proto +> { + public type_args: string[]; + public args: string[]; + + /** + * @param sender the actor that signed the messages + * @param module_address the address of the module deployer + * @param module_name the name of module to execute + * @param function_name the name of function to execute + * @param type_args the type arguments of a function to execute + * @param args the arguments of a function to execute in json stringify format + */ + constructor( + public sender: AccAddress, + public module_address: AccAddress, + public module_name: string, + public function_name: string, + type_args: string[] = [], + args: string[] = [] + ) { + super(); + this.type_args = type_args; + this.args = args; + } + + public static fromAmino(data: MsgExecuteJSON.Amino): MsgExecuteJSON { + const { + value: { + sender, + module_address, + module_name, + function_name, + type_args, + args, + }, + } = data; + return new MsgExecuteJSON( + sender, + module_address, + module_name, + function_name, + type_args ?? [], + args ?? [] + ); + } + + public toAmino(): MsgExecuteJSON.Amino { + const { + sender, + module_address, + module_name, + function_name, + type_args, + args, + } = this; + + return { + type: 'move/MsgExecuteJSON', + value: { + sender, + module_address, + module_name, + function_name, + type_args: type_args.length === 0 ? undefined : type_args, + args: args.length === 0 ? undefined : args, + }, + }; + } + + public static fromData(data: MsgExecuteJSON.Data): MsgExecuteJSON { + const { + sender, + module_address, + module_name, + function_name, + type_args, + args, + } = data; + return new MsgExecuteJSON( + sender, + module_address, + module_name, + function_name, + type_args, + args + ); + } + + public toData(): MsgExecuteJSON.Data { + const { + sender, + module_address, + module_name, + function_name, + type_args, + args, + } = this; + return { + '@type': '/initia.move.v1.MsgExecuteJSON', + sender, + module_address, + module_name, + function_name, + type_args, + args, + }; + } + + public static fromProto(data: MsgExecuteJSON.Proto): MsgExecuteJSON { + return new MsgExecuteJSON( + data.sender, + data.moduleAddress, + data.moduleName, + data.functionName, + data.typeArgs, + data.args + ); + } + + public toProto(): MsgExecuteJSON.Proto { + const { + sender, + module_address, + module_name, + function_name, + type_args, + args, + } = this; + return MsgExecuteJSON_pb.fromPartial({ + sender, + moduleAddress: module_address, + moduleName: module_name, + functionName: function_name, + typeArgs: type_args, + args, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/initia.move.v1.MsgExecuteJSON', + value: MsgExecuteJSON_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgExecuteJSON { + return MsgExecuteJSON.fromProto(MsgExecuteJSON_pb.decode(msgAny.value)); + } +} + +export namespace MsgExecuteJSON { + export interface Amino { + type: 'move/MsgExecuteJSON'; + value: { + sender: AccAddress; + module_address: AccAddress; + module_name: string; + function_name: string; + type_args?: string[]; + args?: string[]; + }; + } + + export interface Data { + '@type': '/initia.move.v1.MsgExecuteJSON'; + sender: AccAddress; + module_address: AccAddress; + module_name: string; + function_name: string; + type_args: string[]; + args: string[]; + } + + export type Proto = MsgExecuteJSON_pb; +} diff --git a/src/core/move/msgs/MsgGovExecuteJSON.ts b/src/core/move/msgs/MsgGovExecuteJSON.ts new file mode 100644 index 0000000..44b904f --- /dev/null +++ b/src/core/move/msgs/MsgGovExecuteJSON.ts @@ -0,0 +1,205 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgGovExecuteJSON as MsgGovExecuteJSON_pb } from '@initia/initia.proto/initia/move/v1/tx'; + +export class MsgGovExecuteJSON extends JSONSerializable< + MsgGovExecuteJSON.Amino, + MsgGovExecuteJSON.Data, + MsgGovExecuteJSON.Proto +> { + public type_args: string[]; + public args: string[]; + + /** + * @param authority the address that controls the module + * @param sender the actor that signed the messages + * @param module_address module deployer address + * @param module_name name of module to execute + * @param function_name name of function to execute + * @param type_args type arguments of function to execute + * @param args arguments of function to execute + */ + constructor( + public authority: AccAddress, + public sender: AccAddress, + public module_address: AccAddress, + public module_name: string, + public function_name: string, + type_args: string[] = [], + args: string[] = [] + ) { + super(); + this.type_args = type_args; + this.args = args; + } + + public static fromAmino(data: MsgGovExecuteJSON.Amino): MsgGovExecuteJSON { + const { + value: { + authority, + sender, + module_address, + module_name, + function_name, + type_args, + args, + }, + } = data; + + return new MsgGovExecuteJSON( + authority, + sender, + module_address, + module_name, + function_name, + type_args ?? [], + args ?? [] + ); + } + + public toAmino(): MsgGovExecuteJSON.Amino { + const { + authority, + sender, + module_address, + module_name, + function_name, + type_args, + args, + } = this; + + return { + type: 'move/MsgGovExecuteJSON', + value: { + authority, + sender, + module_address, + module_name, + function_name, + type_args: type_args.length === 0 ? undefined : type_args, + args: args.length === 0 ? undefined : args, + }, + }; + } + + public static fromData(data: MsgGovExecuteJSON.Data): MsgGovExecuteJSON { + const { + authority, + sender, + module_address, + module_name, + function_name, + type_args, + args, + } = data; + + return new MsgGovExecuteJSON( + authority, + sender, + module_address, + module_name, + function_name, + type_args, + args + ); + } + + public toData(): MsgGovExecuteJSON.Data { + const { + authority, + sender, + module_address, + module_name, + function_name, + type_args, + args, + } = this; + + return { + '@type': '/initia.move.v1.MsgGovExecuteJSON', + authority, + sender, + module_address, + module_name, + function_name, + type_args, + args, + }; + } + + public static fromProto(data: MsgGovExecuteJSON.Proto): MsgGovExecuteJSON { + return new MsgGovExecuteJSON( + data.authority, + data.sender, + data.moduleAddress, + data.moduleName, + data.functionName, + data.typeArgs, + data.args + ); + } + + public toProto(): MsgGovExecuteJSON.Proto { + const { + authority, + sender, + module_address, + module_name, + function_name, + type_args, + args, + } = this; + + return MsgGovExecuteJSON_pb.fromPartial({ + authority, + sender, + moduleAddress: module_address, + moduleName: module_name, + functionName: function_name, + typeArgs: type_args, + args, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/initia.move.v1.MsgGovExecuteJSON', + value: MsgGovExecuteJSON_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgGovExecuteJSON { + return MsgGovExecuteJSON.fromProto( + MsgGovExecuteJSON_pb.decode(msgAny.value) + ); + } +} + +export namespace MsgGovExecuteJSON { + export interface Amino { + type: 'move/MsgGovExecuteJSON'; + value: { + authority: AccAddress; + sender: AccAddress; + module_address: AccAddress; + module_name: string; + function_name: string; + type_args?: string[]; + args?: string[]; + }; + } + + export interface Data { + '@type': '/initia.move.v1.MsgGovExecuteJSON'; + authority: AccAddress; + sender: AccAddress; + module_address: AccAddress; + module_name: string; + function_name: string; + type_args: string[]; + args: string[]; + } + + export type Proto = MsgGovExecuteJSON_pb; +} diff --git a/src/core/move/msgs/MsgGovScriptJSON.ts b/src/core/move/msgs/MsgGovScriptJSON.ts new file mode 100644 index 0000000..65729c6 --- /dev/null +++ b/src/core/move/msgs/MsgGovScriptJSON.ts @@ -0,0 +1,133 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgGovScriptJSON as MsgGovScriptJSON_pb } from '@initia/initia.proto/initia/move/v1/tx'; + +export class MsgGovScriptJSON extends JSONSerializable< + MsgGovScriptJSON.Amino, + MsgGovScriptJSON.Data, + MsgGovScriptJSON.Proto +> { + public type_args: string[]; + public args: string[]; + + /** + * @param authority the address that controls the module + * @param sender the actor that signed the messages + * @param code_bytes the script bytes code to execute + * @param type_args type arguments of function to execute + * @param args arguments of function to execute + */ + constructor( + public authority: AccAddress, + public sender: AccAddress, + public code_bytes: string, + type_args: string[] = [], + args: string[] = [] + ) { + super(); + this.type_args = type_args; + this.args = args; + } + + public static fromAmino(data: MsgGovScriptJSON.Amino): MsgGovScriptJSON { + const { + value: { authority, sender, code_bytes, type_args, args }, + } = data; + + return new MsgGovScriptJSON( + authority, + sender, + code_bytes, + type_args ?? [], + args ?? [] + ); + } + + public toAmino(): MsgGovScriptJSON.Amino { + const { authority, sender, code_bytes, type_args, args } = this; + return { + type: 'move/MsgGovScriptJSON', + value: { + authority, + sender, + code_bytes, + type_args: type_args.length === 0 ? undefined : type_args, + args: args.length === 0 ? undefined : args, + }, + }; + } + + public static fromData(data: MsgGovScriptJSON.Data): MsgGovScriptJSON { + const { authority, sender, code_bytes, type_args, args } = data; + return new MsgGovScriptJSON(authority, sender, code_bytes, type_args, args); + } + + public toData(): MsgGovScriptJSON.Data { + const { authority, sender, code_bytes, type_args, args } = this; + return { + '@type': '/initia.move.v1.MsgGovScriptJSON', + authority, + sender, + code_bytes, + type_args, + args, + }; + } + + public static fromProto(data: MsgGovScriptJSON.Proto): MsgGovScriptJSON { + return new MsgGovScriptJSON( + data.authority, + data.sender, + Buffer.from(data.codeBytes).toString('base64'), + data.typeArgs, + data.args + ); + } + + public toProto(): MsgGovScriptJSON.Proto { + const { authority, sender, code_bytes, type_args, args } = this; + return MsgGovScriptJSON_pb.fromPartial({ + authority, + sender, + codeBytes: Buffer.from(code_bytes, 'base64'), + typeArgs: type_args, + args, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/initia.move.v1.MsgGovScriptJSON', + value: MsgGovScriptJSON_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgGovScriptJSON { + return MsgGovScriptJSON.fromProto(MsgGovScriptJSON_pb.decode(msgAny.value)); + } +} + +export namespace MsgGovScriptJSON { + export interface Amino { + type: 'move/MsgGovScriptJSON'; + value: { + authority: AccAddress; + sender: AccAddress; + code_bytes: string; + type_args?: string[]; + args?: string[]; + }; + } + + export interface Data { + '@type': '/initia.move.v1.MsgGovScriptJSON'; + authority: AccAddress; + sender: AccAddress; + code_bytes: string; + type_args: string[]; + args: string[]; + } + + export type Proto = MsgGovScriptJSON_pb; +} diff --git a/src/core/move/msgs/MsgScriptJSON.ts b/src/core/move/msgs/MsgScriptJSON.ts new file mode 100644 index 0000000..803a45a --- /dev/null +++ b/src/core/move/msgs/MsgScriptJSON.ts @@ -0,0 +1,119 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgScriptJSON as MsgScriptJSON_pb } from '@initia/initia.proto/initia/move/v1/tx'; + +export class MsgScriptJSON extends JSONSerializable< + MsgScriptJSON.Amino, + MsgScriptJSON.Data, + MsgScriptJSON.Proto +> { + public type_args: string[]; + public args: string[]; + + /** + * @param sender the actor that signed the messages + * @param code_bytes the script bytes code to execute + * @param type_args the type arguments of a function to execute + * @param args the arguments of a function to execute in json stringify format + */ + constructor( + public sender: AccAddress, + public code_bytes: string, + type_args: string[] = [], + args: string[] = [] + ) { + super(); + this.type_args = type_args; + this.args = args; + } + + public static fromAmino(data: MsgScriptJSON.Amino): MsgScriptJSON { + const { + value: { sender, code_bytes, type_args, args }, + } = data; + return new MsgScriptJSON(sender, code_bytes, type_args ?? [], args ?? []); + } + + public toAmino(): MsgScriptJSON.Amino { + const { sender, code_bytes, type_args, args } = this; + + return { + type: 'move/MsgScriptJSON', + value: { + sender, + code_bytes, + type_args: type_args.length === 0 ? undefined : type_args, + args: args.length === 0 ? undefined : args, + }, + }; + } + + public static fromData(data: MsgScriptJSON.Data): MsgScriptJSON { + const { sender, code_bytes, type_args, args } = data; + return new MsgScriptJSON(sender, code_bytes, type_args, args); + } + + public toData(): MsgScriptJSON.Data { + const { sender, code_bytes, type_args, args } = this; + return { + '@type': '/initia.move.v1.MsgScriptJSON', + sender, + code_bytes, + type_args, + args, + }; + } + + public static fromProto(data: MsgScriptJSON.Proto): MsgScriptJSON { + return new MsgScriptJSON( + data.sender, + Buffer.from(data.codeBytes).toString('base64'), + data.typeArgs, + data.args + ); + } + + public toProto(): MsgScriptJSON.Proto { + const { sender, code_bytes, type_args, args } = this; + return MsgScriptJSON_pb.fromPartial({ + sender, + codeBytes: Buffer.from(code_bytes, 'base64'), + typeArgs: type_args, + args, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/initia.move.v1.MsgScriptJSON', + value: MsgScriptJSON_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgScriptJSON { + return MsgScriptJSON.fromProto(MsgScriptJSON_pb.decode(msgAny.value)); + } +} + +export namespace MsgScriptJSON { + export interface Amino { + type: 'move/MsgScriptJSON'; + value: { + sender: AccAddress; + code_bytes: string; + type_args?: string[]; + args?: string[]; + }; + } + + export interface Data { + '@type': '/initia.move.v1.MsgScriptJSON'; + sender: AccAddress; + code_bytes: string; + type_args: string[]; + args: string[]; + } + + export type Proto = MsgScriptJSON_pb; +} diff --git a/src/core/move/msgs/index.ts b/src/core/move/msgs/index.ts index 4137c12..4065863 100644 --- a/src/core/move/msgs/index.ts +++ b/src/core/move/msgs/index.ts @@ -1,64 +1,89 @@ import { MsgPublish } from './MsgPublish'; import { MsgExecute } from './MsgExecute'; +import { MsgExecuteJSON } from './MsgExecuteJSON'; import { MsgScript } from './MsgScript'; +import { MsgScriptJSON } from './MsgScriptJSON'; import { MsgUpdateMoveParams } from './MsgUpdateMoveParams'; import { MsgWhitelist } from './MsgWhitelist'; import { MsgDelist } from './MsgDelist'; import { MsgGovExecute } from './MsgGovExecute'; +import { MsgGovExecuteJSON } from './MsgGovExecuteJSON'; import { MsgGovPublish } from './MsgGovPublish'; import { MsgGovScript } from './MsgGovScript'; +import { MsgGovScriptJSON } from './MsgGovScriptJSON'; export * from './MsgPublish'; export * from './MsgExecute'; +export * from './MsgExecuteJSON'; export * from './MsgScript'; +export * from './MsgScriptJSON'; export * from './MsgUpdateMoveParams'; export * from './MsgWhitelist'; export * from './MsgDelist'; export * from './MsgGovExecute'; +export * from './MsgGovExecuteJSON'; export * from './MsgGovPublish'; export * from './MsgGovScript'; +export * from './MsgGovScriptJSON'; export type MoveMsg = | MsgPublish | MsgExecute + | MsgExecuteJSON | MsgScript + | MsgScriptJSON | MsgUpdateMoveParams | MsgWhitelist | MsgDelist | MsgGovExecute + | MsgGovExecuteJSON | MsgGovPublish - | MsgGovScript; + | MsgGovScript + | MsgGovScriptJSON; export namespace MoveMsg { export type Amino = | MsgPublish.Amino | MsgExecute.Amino + | MsgExecuteJSON.Amino | MsgScript.Amino + | MsgScriptJSON.Amino | MsgUpdateMoveParams.Amino | MsgWhitelist.Amino | MsgDelist.Amino | MsgGovExecute.Amino + | MsgGovExecuteJSON.Amino | MsgGovPublish.Amino - | MsgGovScript.Amino; + | MsgGovScript.Amino + | MsgGovScriptJSON.Amino; + export type Data = | MsgPublish.Data | MsgExecute.Data + | MsgExecuteJSON.Data | MsgScript.Data + | MsgScriptJSON.Data | MsgUpdateMoveParams.Data | MsgWhitelist.Data | MsgDelist.Data | MsgGovExecute.Data + | MsgGovExecuteJSON.Data | MsgGovPublish.Data - | MsgGovScript.Data; + | MsgGovScript.Data + | MsgGovScriptJSON.Data; export type Proto = | MsgPublish.Proto | MsgExecute.Proto + | MsgExecuteJSON.Proto | MsgScript.Proto + | MsgScriptJSON.Proto | MsgUpdateMoveParams.Proto | MsgWhitelist.Proto | MsgDelist.Proto | MsgGovExecute.Proto + | MsgGovExecuteJSON.Proto | MsgGovPublish.Proto - | MsgGovScript.Proto; + | MsgGovScript.Proto + | MsgGovScriptJSON.Proto; } diff --git a/src/core/opchild/OpchildParams.ts b/src/core/opchild/OpchildParams.ts index 662ef34..432a812 100644 --- a/src/core/opchild/OpchildParams.ts +++ b/src/core/opchild/OpchildParams.ts @@ -15,12 +15,14 @@ export class OpchildParams extends JSONSerializable< * @param historical_entries the number of historical entries to persist * @param min_gas_prices * @param bridge_executor the account address of bridge executor who can execute permissioned bridge messages + * @param admin */ constructor( public max_validators: number, public historical_entries: number, min_gas_prices: Coins.Input, - public bridge_executor: AccAddress + public bridge_executor: AccAddress, + public admin: AccAddress ) { super(); this.min_gas_prices = new Coins(min_gas_prices); @@ -33,6 +35,7 @@ export class OpchildParams extends JSONSerializable< historical_entries, min_gas_prices, bridge_executor, + admin, }, } = data; @@ -40,7 +43,8 @@ export class OpchildParams extends JSONSerializable< max_validators, historical_entries, Coins.fromAmino(min_gas_prices), - bridge_executor + bridge_executor, + admin ); } @@ -50,6 +54,7 @@ export class OpchildParams extends JSONSerializable< historical_entries, min_gas_prices, bridge_executor, + admin, } = this; return { @@ -59,6 +64,7 @@ export class OpchildParams extends JSONSerializable< historical_entries, min_gas_prices: min_gas_prices.toAmino(), bridge_executor, + admin, }, }; } @@ -69,13 +75,15 @@ export class OpchildParams extends JSONSerializable< historical_entries, min_gas_prices, bridge_executor, + admin, } = data; return new OpchildParams( max_validators, historical_entries, Coins.fromData(min_gas_prices), - bridge_executor + bridge_executor, + admin ); } @@ -85,6 +93,7 @@ export class OpchildParams extends JSONSerializable< historical_entries, min_gas_prices, bridge_executor, + admin, } = this; return { @@ -93,6 +102,7 @@ export class OpchildParams extends JSONSerializable< historical_entries, min_gas_prices: min_gas_prices.toData(), bridge_executor, + admin, }; } @@ -101,7 +111,8 @@ export class OpchildParams extends JSONSerializable< data.maxValidators, data.historicalEntries, Coins.fromProto(data.minGasPrices), - data.bridgeExecutor + data.bridgeExecutor, + data.admin ); } @@ -111,6 +122,7 @@ export class OpchildParams extends JSONSerializable< historical_entries, min_gas_prices, bridge_executor, + admin, } = this; return Params_pb.fromPartial({ @@ -118,6 +130,7 @@ export class OpchildParams extends JSONSerializable< historicalEntries: historical_entries, minGasPrices: min_gas_prices.toProto(), bridgeExecutor: bridge_executor, + admin, }); } } @@ -130,6 +143,7 @@ export namespace OpchildParams { historical_entries: number; min_gas_prices: Coins.Amino; bridge_executor: AccAddress; + admin: AccAddress; }; } @@ -139,6 +153,7 @@ export namespace OpchildParams { historical_entries: number; min_gas_prices: Coins.Data; bridge_executor: AccAddress; + admin: AccAddress; } export type Proto = Params_pb; diff --git a/src/core/ophost/BatchInfo.ts b/src/core/ophost/BatchInfo.ts new file mode 100644 index 0000000..ac0091d --- /dev/null +++ b/src/core/ophost/BatchInfo.ts @@ -0,0 +1,62 @@ +import { JSONSerializable } from '../../util/json'; +import { BatchInfo as BatchInfo_pb } from '@initia/opinit.proto/opinit/ophost/v1/types'; + +export class BatchInfo extends JSONSerializable< + BatchInfo.Amino, + BatchInfo.Data, + BatchInfo.Proto +> { + /** + * @param submitter the address of the batch submitter + * @param chain the target chain + */ + constructor(public submitter: string, public chain: string) { + super(); + } + + public static fromAmino(data: BatchInfo.Amino): BatchInfo { + const { submitter, chain } = data; + return new BatchInfo(submitter, chain); + } + + public toAmino(): BatchInfo.Amino { + const { submitter, chain } = this; + return { submitter, chain }; + } + + public static fromData(data: BatchInfo.Data): BatchInfo { + const { submitter, chain } = data; + return new BatchInfo(submitter, chain); + } + + public toData(): BatchInfo.Data { + const { submitter, chain } = this; + return { submitter, chain }; + } + + public static fromProto(data: BatchInfo.Proto): BatchInfo { + return new BatchInfo(data.submitter, data.chain); + } + + public toProto(): BatchInfo.Proto { + const { submitter, chain } = this; + return BatchInfo_pb.fromPartial({ + submitter, + chain, + }); + } +} + +export namespace BatchInfo { + export interface Amino { + submitter: string; + chain: string; + } + + export interface Data { + submitter: string; + chain: string; + } + + export type Proto = BatchInfo_pb; +} diff --git a/src/core/ophost/BridgeConfig.ts b/src/core/ophost/BridgeConfig.ts index fe88967..480191d 100644 --- a/src/core/ophost/BridgeConfig.ts +++ b/src/core/ophost/BridgeConfig.ts @@ -2,6 +2,7 @@ import { JSONSerializable } from '../../util/json'; import { AccAddress } from '../bech32'; import { Duration } from '../Duration'; import { BridgeConfig as BridgeConfig_pb } from '@initia/opinit.proto/opinit/ophost/v1/types'; +import { BatchInfo } from './BatchInfo'; export class BridgeConfig extends JSONSerializable< BridgeConfig.Amino, @@ -11,6 +12,7 @@ export class BridgeConfig extends JSONSerializable< /** * @param challenger the address of the challenger * @param proposer the address of the proposer + * @param batch_info the information about batch submission * @param submission_interval the time interval at which checkpoints must be submitted * @param finalization_period the minium time duration that must elapse before a withdrawal can be finalized * @param submission_start_time the time of the first l2 block recorded @@ -19,6 +21,7 @@ export class BridgeConfig extends JSONSerializable< constructor( public challenger: AccAddress, public proposer: AccAddress, + public batch_info: BatchInfo, public submission_interval: Duration, public finalization_period: Duration, public submission_start_time: Date, @@ -31,6 +34,7 @@ export class BridgeConfig extends JSONSerializable< const { challenger, proposer, + batch_info, submission_interval, finalization_period, submission_start_time, @@ -40,6 +44,7 @@ export class BridgeConfig extends JSONSerializable< return new BridgeConfig( challenger, proposer, + BatchInfo.fromAmino(batch_info), Duration.fromAmino(submission_interval), Duration.fromAmino(finalization_period), new Date(submission_start_time), @@ -51,6 +56,7 @@ export class BridgeConfig extends JSONSerializable< const { challenger, proposer, + batch_info, submission_interval, finalization_period, submission_start_time, @@ -60,6 +66,7 @@ export class BridgeConfig extends JSONSerializable< return { challenger, proposer, + batch_info: batch_info.toAmino(), submission_interval: submission_interval.toAmino(), finalization_period: finalization_period.toAmino(), submission_start_time: submission_start_time.toISOString(), @@ -71,6 +78,7 @@ export class BridgeConfig extends JSONSerializable< const { challenger, proposer, + batch_info, submission_interval, finalization_period, submission_start_time, @@ -80,6 +88,7 @@ export class BridgeConfig extends JSONSerializable< return new BridgeConfig( challenger, proposer, + BatchInfo.fromData(batch_info), Duration.fromData(submission_interval), Duration.fromData(finalization_period), new Date(submission_start_time), @@ -91,6 +100,7 @@ export class BridgeConfig extends JSONSerializable< const { challenger, proposer, + batch_info, submission_interval, finalization_period, submission_start_time, @@ -100,6 +110,7 @@ export class BridgeConfig extends JSONSerializable< return { challenger, proposer, + batch_info: batch_info.toData(), submission_interval: submission_interval.toData(), finalization_period: finalization_period.toData(), submission_start_time: submission_start_time.toISOString(), @@ -111,6 +122,7 @@ export class BridgeConfig extends JSONSerializable< return new BridgeConfig( data.challenger, data.proposer, + BatchInfo.fromProto(data.batchInfo as BatchInfo.Proto), Duration.fromProto(data.submissionInterval as Duration.Proto), Duration.fromProto(data.finalizationPeriod as Duration.Proto), data.submissionStartTime as Date, @@ -122,6 +134,7 @@ export class BridgeConfig extends JSONSerializable< const { challenger, proposer, + batch_info, submission_interval, finalization_period, submission_start_time, @@ -131,6 +144,7 @@ export class BridgeConfig extends JSONSerializable< return BridgeConfig_pb.fromPartial({ challenger, proposer, + batchInfo: batch_info.toProto(), submissionInterval: submission_interval.toProto(), finalizationPeriod: finalization_period.toProto(), submissionStartTime: submission_start_time, @@ -143,6 +157,7 @@ export namespace BridgeConfig { export interface Amino { challenger: AccAddress; proposer: AccAddress; + batch_info: BatchInfo.Amino; submission_interval: Duration.Amino; finalization_period: Duration.Amino; submission_start_time: string; @@ -152,6 +167,7 @@ export namespace BridgeConfig { export interface Data { challenger: AccAddress; proposer: AccAddress; + batch_info: BatchInfo.Data; submission_interval: Duration.Data; finalization_period: Duration.Data; submission_start_time: string; diff --git a/src/core/ophost/index.ts b/src/core/ophost/index.ts index 5eebf11..042c398 100644 --- a/src/core/ophost/index.ts +++ b/src/core/ophost/index.ts @@ -1,4 +1,5 @@ export * from './msgs'; +export * from './BatchInfo'; export * from './BridgeConfig'; export * from './OphostParams'; export * from './Output'; diff --git a/src/core/ophost/msgs/MsgUpdateBatchInfo.ts b/src/core/ophost/msgs/MsgUpdateBatchInfo.ts new file mode 100644 index 0000000..1756b03 --- /dev/null +++ b/src/core/ophost/msgs/MsgUpdateBatchInfo.ts @@ -0,0 +1,118 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { MsgUpdateBatchInfo as MsgUpdateBatchInfo_pb } from '@initia/opinit.proto/opinit/ophost/v1/tx'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { BatchInfo } from '../BatchInfo'; +import Long from 'long'; + +export class MsgUpdateBatchInfo extends JSONSerializable< + MsgUpdateBatchInfo.Amino, + MsgUpdateBatchInfo.Data, + MsgUpdateBatchInfo.Proto +> { + /** + * @param authority the address that controls the module + * @param bridge_id + * @param new_batch_info + */ + constructor( + public authority: AccAddress, + public bridge_id: number, + public new_batch_info: BatchInfo + ) { + super(); + } + + public static fromAmino(data: MsgUpdateBatchInfo.Amino): MsgUpdateBatchInfo { + const { + value: { authority, bridge_id, new_batch_info }, + } = data; + + return new MsgUpdateBatchInfo( + authority, + Number.parseInt(bridge_id), + BatchInfo.fromAmino(new_batch_info) + ); + } + + public toAmino(): MsgUpdateBatchInfo.Amino { + const { authority, bridge_id, new_batch_info } = this; + return { + type: 'ophost/MsgUpdateBatchInfo', + value: { + authority, + bridge_id: bridge_id.toString(), + new_batch_info: new_batch_info.toAmino(), + }, + }; + } + + public static fromData(data: MsgUpdateBatchInfo.Data): MsgUpdateBatchInfo { + const { authority, bridge_id, new_batch_info } = data; + return new MsgUpdateBatchInfo( + authority, + Number.parseInt(bridge_id), + BatchInfo.fromData(new_batch_info) + ); + } + + public toData(): MsgUpdateBatchInfo.Data { + const { authority, bridge_id, new_batch_info } = this; + return { + '@type': '/opinit.ophost.v1.MsgUpdateBatchInfo', + authority, + bridge_id: bridge_id.toString(), + new_batch_info: new_batch_info.toData(), + }; + } + + public static fromProto(data: MsgUpdateBatchInfo.Proto): MsgUpdateBatchInfo { + return new MsgUpdateBatchInfo( + data.authority, + data.bridgeId.toNumber(), + BatchInfo.fromProto(data.newBatchInfo as BatchInfo.Proto) + ); + } + + public toProto(): MsgUpdateBatchInfo.Proto { + const { authority, bridge_id, new_batch_info } = this; + return MsgUpdateBatchInfo_pb.fromPartial({ + authority, + bridgeId: Long.fromNumber(bridge_id), + newBatchInfo: new_batch_info.toProto(), + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/opinit.ophost.v1.MsgUpdateBatchInfo', + value: MsgUpdateBatchInfo_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgUpdateBatchInfo { + return MsgUpdateBatchInfo.fromProto( + MsgUpdateBatchInfo_pb.decode(msgAny.value) + ); + } +} + +export namespace MsgUpdateBatchInfo { + export interface Amino { + type: 'ophost/MsgUpdateBatchInfo'; + value: { + authority: AccAddress; + bridge_id: string; + new_batch_info: BatchInfo.Amino; + }; + } + + export interface Data { + '@type': '/opinit.ophost.v1.MsgUpdateBatchInfo'; + authority: AccAddress; + bridge_id: string; + new_batch_info: BatchInfo.Data; + } + + export type Proto = MsgUpdateBatchInfo_pb; +} diff --git a/src/core/ophost/msgs/index.ts b/src/core/ophost/msgs/index.ts index 2853033..5da1f88 100644 --- a/src/core/ophost/msgs/index.ts +++ b/src/core/ophost/msgs/index.ts @@ -7,6 +7,7 @@ import { MsgFinalizeTokenWithdrawal } from './MsgFinalizeTokenWithdrawal'; import { MsgUpdateProposer } from './MsgUpdateProposer'; import { MsgUpdateChallenger } from './MsgUpdateChallenger'; import { MsgUpdateOphostParams } from './MsgUpdateOphostParams'; +import { MsgUpdateBatchInfo } from './MsgUpdateBatchInfo'; export * from './MsgRecordBatch'; export * from './MsgCreateBridge'; @@ -17,6 +18,7 @@ export * from './MsgFinalizeTokenWithdrawal'; export * from './MsgUpdateProposer'; export * from './MsgUpdateChallenger'; export * from './MsgUpdateOphostParams'; +export * from './MsgUpdateBatchInfo'; export type OphostMsg = | MsgRecordBatch @@ -27,6 +29,7 @@ export type OphostMsg = | MsgFinalizeTokenWithdrawal | MsgUpdateProposer | MsgUpdateChallenger + | MsgUpdateBatchInfo | MsgUpdateOphostParams; export namespace OphostMsg { @@ -39,6 +42,7 @@ export namespace OphostMsg { | MsgFinalizeTokenWithdrawal.Amino | MsgUpdateProposer.Amino | MsgUpdateChallenger.Amino + | MsgUpdateBatchInfo.Amino | MsgUpdateOphostParams.Amino; export type Data = @@ -50,6 +54,7 @@ export namespace OphostMsg { | MsgFinalizeTokenWithdrawal.Data | MsgUpdateProposer.Data | MsgUpdateChallenger.Data + | MsgUpdateBatchInfo.Data | MsgUpdateOphostParams.Data; export type Proto = @@ -61,5 +66,6 @@ export namespace OphostMsg { | MsgFinalizeTokenWithdrawal.Proto | MsgUpdateProposer.Proto | MsgUpdateChallenger.Proto + | MsgUpdateBatchInfo.Proto | MsgUpdateOphostParams.Proto; }