Skip to content

Commit

Permalink
refactor: get_node_info rpc for more useful configs (#674)
Browse files Browse the repository at this point in the history
* refactor: get_node_info rpc for more configs

* fix(NodeInfo): add missing stateValidator script

* fix(NodeInfo): chain_id type Uint64

* refactor: rename rullupCell script to type_script
  • Loading branch information
RetricSu committed May 6, 2022
1 parent 75a610d commit 9c0a2d9
Show file tree
Hide file tree
Showing 4 changed files with 357 additions and 30 deletions.
2 changes: 2 additions & 0 deletions crates/block-producer/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,8 @@ pub async fn run(config: Config, skip_config_check: bool) -> Result<()> {
generator,
tests_rpc_impl: test_mode_control.map(Box::new),
rollup_config,
chain_config: config.chain.to_owned(),
consensus_config: config.consensus.to_owned(),
mem_pool_config: config.mem_pool.clone(),
node_mode: config.node_mode,
rpc_client: rpc_client.clone(),
Expand Down
103 changes: 102 additions & 1 deletion crates/jsonrpc-types/src/godwoken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,9 +1176,27 @@ impl From<offchain::RunResult> for RunResult {
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug, Default)]
#[serde(rename_all = "snake_case")]
pub struct NodeInfo {
// godwoken current version
pub mode: NodeMode,
pub version: String,
pub backends: Vec<BackendInfo>,
pub eoa_scripts: Vec<EoaScript>,
pub gw_scripts: Vec<GwScript>,
pub rollup_cell: RollupCell,
pub rollup_config: NodeRollupConfig,
}

#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)]
#[serde(rename_all = "lowercase")]
pub enum NodeMode {
FullNode,
Test,
ReadOnly,
}

impl Default for NodeMode {
fn default() -> Self {
NodeMode::ReadOnly
}
}

#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug, Default)]
Expand All @@ -1187,8 +1205,91 @@ pub struct BackendInfo {
pub validator_code_hash: H256,
pub generator_code_hash: H256,
pub validator_script_type_hash: H256,
pub backend_type: BackendType,
}

#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)]
#[serde(rename_all = "snake_case")]
pub enum BackendType {
Unknown,
Meta,
Sudt,
Polyjuice,
EthAddrReg,
}

impl Default for BackendType {
fn default() -> Self {
BackendType::Unknown
}
}

#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug, Default)]
#[serde(rename_all = "snake_case")]
pub struct GwScript {
pub type_hash: H256,
pub script: Script,
pub script_type: GwScriptType,
}

#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)]
#[serde(rename_all = "snake_case")]
pub enum GwScriptType {
Unknown,
Deposit,
Withdraw,
StateValidator,
StakeLock,
CustodianLock,
ChallengeLock,
L1Sudt,
L2Sudt,
OmniLock,
}

impl Default for GwScriptType {
fn default() -> Self {
GwScriptType::Unknown
}
}

#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug, Default)]
#[serde(rename_all = "snake_case")]
pub struct RollupCell {
pub type_hash: H256,
pub type_script: Script,
}

#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug, Default)]
#[serde(rename_all = "snake_case")]
pub struct NodeRollupConfig {
pub required_staking_capacity: Uint64,
pub challenge_maturity_blocks: Uint64,
pub finality_blocks: Uint64,
pub reward_burn_rate: Uint32,
pub chain_id: Uint64,
}

#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug, Default)]
#[serde(rename_all = "snake_case")]
pub struct EoaScript {
pub type_hash: H256,
pub script: Script,
pub eoa_type: EoaScriptType,
}

#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug)]
#[serde(rename_all = "snake_case")]
pub enum EoaScriptType {
Unknown,
Eth,
}

impl Default for EoaScriptType {
fn default() -> Self {
EoaScriptType::Unknown
}
}
#[derive(Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Debug, Default)]
#[serde(rename_all = "snake_case")]
pub struct ErrorTxReceipt {
Expand Down
Loading

0 comments on commit 9c0a2d9

Please sign in to comment.