Skip to content

Commit

Permalink
Add MsgUpdateOracle and update OpchildParams
Browse files Browse the repository at this point in the history
  • Loading branch information
joon9823 committed Apr 19, 2024
1 parent 40b29bb commit b8d68a0
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 13 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@initia/initia.js",
"version": "0.1.44",
"version": "0.1.45",
"description": "The JavaScript SDK for Initia",
"license": "MIT",
"author": "InitiaLabs",
Expand Down Expand Up @@ -87,7 +87,7 @@
},
"dependencies": {
"@initia/initia.proto": "^0.1.33",
"@initia/opinit.proto": "^0.0.6",
"@initia/opinit.proto": "^0.0.7",
"@ledgerhq/hw-transport": "^6.27.12",
"@ledgerhq/hw-transport-webhid": "^6.27.12",
"@ledgerhq/hw-transport-webusb": "^6.27.12",
Expand Down
7 changes: 7 additions & 0 deletions src/core/Msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ import {
MsgExecuteMessages,
MsgSpendFeePool,
MsgSetBridgeInfo,
MsgUpdateOracle,
MsgUpdateOpchildParams,
} from './opchild';
import {
Expand Down Expand Up @@ -566,6 +567,8 @@ export namespace Msg {
return MsgSpendFeePool.fromAmino(data);
case 'opchild/MsgSetBridgeInfo':
return MsgSetBridgeInfo.fromAmino(data);
case 'opchild/MsgUpdateOracle':
return MsgUpdateOracle.fromAmino(data);
case 'opchild/MsgUpdateParams':
return MsgUpdateOpchildParams.fromAmino(data);

Expand Down Expand Up @@ -956,6 +959,8 @@ export namespace Msg {
return MsgSpendFeePool.fromData(data);
case '/opinit.opchild.v1.MsgSetBridgeInfo':
return MsgSetBridgeInfo.fromData(data);
case '/opinit.opchild.v1.MsgUpdateOracle':
return MsgUpdateOracle.fromData(data);
case '/opinit.opchild.v1.MsgUpdateParams':
return MsgUpdateOpchildParams.fromData(data);

Expand Down Expand Up @@ -1349,6 +1354,8 @@ export namespace Msg {
return MsgSpendFeePool.unpackAny(proto);
case '/opinit.opchild.v1.MsgSetBridgeInfo':
return MsgSetBridgeInfo.unpackAny(proto);
case '/opinit.opchild.v1.MsgUpdateOracle':
return MsgUpdateOracle.unpackAny(proto);
case '/opinit.opchild.v1.MsgUpdateParams':
return MsgUpdateOpchildParams.unpackAny(proto);

Expand Down
40 changes: 35 additions & 5 deletions src/core/opchild/OpchildParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ 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
* @param host_chain_id the host(l1) chain id
* @param admin the account address of admin who can execute permissioned cosmos messages
* @param fee_whitelist the list of addresses that are allowed to pay zero fee
*/
constructor(
public max_validators: number,
public historical_entries: number,
min_gas_prices: Coins.Input,
public bridge_executor: AccAddress,
public admin: AccAddress
public host_chain_id: string,
public admin: AccAddress,
public fee_whitelist: string[]
) {
super();
this.min_gas_prices = new Coins(min_gas_prices);
Expand All @@ -35,7 +39,9 @@ export class OpchildParams extends JSONSerializable<
historical_entries,
min_gas_prices,
bridge_executor,
host_chain_id,
admin,
fee_whitelist,
},
} = data;

Expand All @@ -44,7 +50,9 @@ export class OpchildParams extends JSONSerializable<
historical_entries,
Coins.fromAmino(min_gas_prices),
bridge_executor,
admin
host_chain_id,
admin,
fee_whitelist
);
}

Expand All @@ -54,7 +62,9 @@ export class OpchildParams extends JSONSerializable<
historical_entries,
min_gas_prices,
bridge_executor,
host_chain_id,
admin,
fee_whitelist,
} = this;

return {
Expand All @@ -64,7 +74,9 @@ export class OpchildParams extends JSONSerializable<
historical_entries,
min_gas_prices: min_gas_prices.toAmino(),
bridge_executor,
host_chain_id,
admin,
fee_whitelist,
},
};
}
Expand All @@ -75,15 +87,19 @@ export class OpchildParams extends JSONSerializable<
historical_entries,
min_gas_prices,
bridge_executor,
host_chain_id,
admin,
fee_whitelist,
} = data;

return new OpchildParams(
max_validators,
historical_entries,
Coins.fromData(min_gas_prices),
bridge_executor,
admin
host_chain_id,
admin,
fee_whitelist
);
}

Expand All @@ -93,7 +109,9 @@ export class OpchildParams extends JSONSerializable<
historical_entries,
min_gas_prices,
bridge_executor,
host_chain_id,
admin,
fee_whitelist,
} = this;

return {
Expand All @@ -102,7 +120,9 @@ export class OpchildParams extends JSONSerializable<
historical_entries,
min_gas_prices: min_gas_prices.toData(),
bridge_executor,
host_chain_id,
admin,
fee_whitelist,
};
}

Expand All @@ -112,7 +132,9 @@ export class OpchildParams extends JSONSerializable<
data.historicalEntries,
Coins.fromProto(data.minGasPrices),
data.bridgeExecutor,
data.admin
data.hostChainId,
data.admin,
data.feeWhitelist
);
}

Expand All @@ -122,15 +144,19 @@ export class OpchildParams extends JSONSerializable<
historical_entries,
min_gas_prices,
bridge_executor,
host_chain_id,
admin,
fee_whitelist,
} = this;

return Params_pb.fromPartial({
maxValidators: max_validators,
historicalEntries: historical_entries,
minGasPrices: min_gas_prices.toProto(),
bridgeExecutor: bridge_executor,
hostChainId: host_chain_id,
admin,
feeWhitelist: fee_whitelist,
});
}
}
Expand All @@ -143,7 +169,9 @@ export namespace OpchildParams {
historical_entries: number;
min_gas_prices: Coins.Amino;
bridge_executor: AccAddress;
host_chain_id: string;
admin: AccAddress;
fee_whitelist: string[];
};
}

Expand All @@ -153,7 +181,9 @@ export namespace OpchildParams {
historical_entries: number;
min_gas_prices: Coins.Data;
bridge_executor: AccAddress;
host_chain_id: string;
admin: AccAddress;
fee_whitelist: string[];
}

export type Proto = Params_pb;
Expand Down
110 changes: 110 additions & 0 deletions src/core/opchild/msgs/MsgUpdateOracle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { JSONSerializable } from '../../../util/json';
import { AccAddress } from '../../bech32';
import { MsgUpdateOracle as MsgUpdateOracle_pb } from '@initia/opinit.proto/opinit/opchild/v1/tx';
import { Any } from '@initia/initia.proto/google/protobuf/any';
import Long from 'long';

export class MsgUpdateOracle extends JSONSerializable<
MsgUpdateOracle.Amino,
MsgUpdateOracle.Data,
MsgUpdateOracle.Proto
> {
/**
* @param sender the sender address
* @param height the height of l1 which is including the oracle message
* @param data oracle votes bytes
*/
constructor(
public sender: AccAddress,
public height: number,
public data: string
) {
super();
}

public static fromAmino(data: MsgUpdateOracle.Amino): MsgUpdateOracle {
return new MsgUpdateOracle(
data.value.sender,
Number.parseInt(data.value.height),
data.value.data
);
}

public toAmino(): MsgUpdateOracle.Amino {
const { sender, height, data } = this;
return {
type: 'opchild/MsgUpdateOracle',
value: {
sender,
height: height.toString(),
data,
},
};
}

public static fromData(data: MsgUpdateOracle.Data): MsgUpdateOracle {
return new MsgUpdateOracle(
data.sender,
Number.parseInt(data.height),
data.data
);
}

public toData(): MsgUpdateOracle.Data {
const { sender, height, data } = this;
return {
'@type': '/opinit.opchild.v1.MsgUpdateOracle',
sender,
height: height.toString(),
data,
};
}

public static fromProto(data: MsgUpdateOracle.Proto): MsgUpdateOracle {
return new MsgUpdateOracle(
data.sender,
data.height.toNumber(),
Buffer.from(data.data).toString('base64')
);
}

public toProto(): MsgUpdateOracle.Proto {
const { sender, height, data } = this;
return MsgUpdateOracle_pb.fromPartial({
sender,
height: Long.fromNumber(height),
data: Buffer.from(data, 'base64'),
});
}

public packAny(): Any {
return Any.fromPartial({
typeUrl: '/opinit.opchild.v1.MsgUpdateOracle',
value: MsgUpdateOracle_pb.encode(this.toProto()).finish(),
});
}

public static unpackAny(msgAny: Any): MsgUpdateOracle {
return MsgUpdateOracle.fromProto(MsgUpdateOracle_pb.decode(msgAny.value));
}
}

export namespace MsgUpdateOracle {
export interface Amino {
type: 'opchild/MsgUpdateOracle';
value: {
sender: AccAddress;
height: string;
data: string;
};
}

export interface Data {
'@type': '/opinit.opchild.v1.MsgUpdateOracle';
sender: AccAddress;
height: string;
data: string;
}

export type Proto = MsgUpdateOracle_pb;
}
6 changes: 6 additions & 0 deletions src/core/opchild/msgs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MsgInitiateTokenWithdrawal } from './MsgInitiateTokenWithdrawal';
import { MsgExecuteMessages } from './MsgExecuteMessages';
import { MsgSpendFeePool } from './MsgSpendFeePool';
import { MsgSetBridgeInfo } from './MsgSetBridgeInfo';
import { MsgUpdateOracle } from './MsgUpdateOracle';
import { MsgUpdateOpchildParams } from './MsgUpdateOpchildParams';

export * from './MsgAddValidator';
Expand All @@ -14,6 +15,7 @@ export * from './MsgInitiateTokenWithdrawal';
export * from './MsgExecuteMessages';
export * from './MsgSpendFeePool';
export * from './MsgSetBridgeInfo';
export * from './MsgUpdateOracle';
export * from './MsgUpdateOpchildParams';

export type OpchildMsg =
Expand All @@ -24,6 +26,7 @@ export type OpchildMsg =
| MsgExecuteMessages
| MsgSpendFeePool
| MsgSetBridgeInfo
| MsgUpdateOracle
| MsgUpdateOpchildParams;

export namespace OpchildMsg {
Expand All @@ -35,6 +38,7 @@ export namespace OpchildMsg {
| MsgExecuteMessages.Amino
| MsgSpendFeePool.Amino
| MsgSetBridgeInfo.Amino
| MsgUpdateOracle.Amino
| MsgUpdateOpchildParams.Amino;

export type Data =
Expand All @@ -45,6 +49,7 @@ export namespace OpchildMsg {
| MsgExecuteMessages.Data
| MsgSpendFeePool.Data
| MsgSetBridgeInfo.Data
| MsgUpdateOracle.Data
| MsgUpdateOpchildParams.Data;

export type Proto =
Expand All @@ -55,5 +60,6 @@ export namespace OpchildMsg {
| MsgExecuteMessages.Proto
| MsgSpendFeePool.Proto
| MsgSetBridgeInfo.Proto
| MsgUpdateOracle.Proto
| MsgUpdateOpchildParams.Proto;
}

0 comments on commit b8d68a0

Please sign in to comment.