From 96a4899334b075fbf088608648f70aef48a53a49 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 12 May 2023 17:28:56 +0800 Subject: [PATCH 1/4] jsonrpc: use jsonrpc::Ratio as type of `Deployment.threshold` --- util/jsonrpc-types/src/blockchain.rs | 21 ++++++++++++++++++++- util/jsonrpc-types/src/lib.rs | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/util/jsonrpc-types/src/blockchain.rs b/util/jsonrpc-types/src/blockchain.rs index a546e31e75..b330f46dc7 100644 --- a/util/jsonrpc-types/src/blockchain.rs +++ b/util/jsonrpc-types/src/blockchain.rs @@ -1438,6 +1438,25 @@ pub struct Rfc0043 { pub rfc0043: Deployment, } +/// Represents the ratio `numerator / denominator`, where `numerator` and `denominator` are both +/// unsigned 64-bit integers. +#[derive(Clone, Serialize, Deserialize, Debug)] +pub struct Ratio { + /// Numerator. + pub numer: Uint64, + /// Denominator. + pub denom: Uint64, +} + +impl From for Ratio { + fn from(value: core::Ratio) -> Self { + Ratio { + numer: value.numer().into(), + denom: value.denom().into(), + } + } +} + /// RFC0043 deployment params #[derive(Clone, Serialize, Deserialize, Debug)] pub struct Deployment { @@ -1456,7 +1475,7 @@ pub struct Deployment { pub period: EpochNumber, /// Specifies the minimum ratio of block per `period`, /// which indicate the locked_in of the softfork during the `period`. - pub threshold: core::Ratio, + pub threshold: Ratio, } fn convert(number: core::EpochNumber) -> Option { diff --git a/util/jsonrpc-types/src/lib.rs b/util/jsonrpc-types/src/lib.rs index b1a24e8068..6b09f47c38 100644 --- a/util/jsonrpc-types/src/lib.rs +++ b/util/jsonrpc-types/src/lib.rs @@ -28,7 +28,7 @@ pub use self::blockchain::{ Block, BlockEconomicState, BlockFilter, BlockIssuance, BlockResponse, BlockView, BlockWithCyclesResponse, CellDep, CellInput, CellOutput, Consensus, DepType, Deployment, EpochView, FeeRateStatistics, HardForkFeature, Header, HeaderView, MerkleProof, MinerReward, - OutPoint, ProposalWindow, Script, ScriptHashType, SoftFork, Status, Transaction, + OutPoint, ProposalWindow, Ratio, Script, ScriptHashType, SoftFork, Status, Transaction, TransactionAndWitnessProof, TransactionProof, TransactionView, TransactionWithStatusResponse, TxStatus, UncleBlock, UncleBlockView, }; From c212c23f00452fc3e135e7248defda356d14746a Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 12 May 2023 17:29:53 +0800 Subject: [PATCH 2/4] jsonrpc: use jsonrpc::Ratio as type of `DeploymentInfo.threshold` --- spec/src/versionbits/convert.rs | 4 ++-- util/jsonrpc-types/src/info.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/src/versionbits/convert.rs b/spec/src/versionbits/convert.rs index 26660f8bdd..53bbad04ee 100644 --- a/spec/src/versionbits/convert.rs +++ b/spec/src/versionbits/convert.rs @@ -23,7 +23,7 @@ impl From for DeploymentInfo { timeout: deployment.timeout.into(), min_activation_epoch: deployment.min_activation_epoch.into(), period: deployment.period.into(), - threshold: deployment.threshold, + threshold: deployment.threshold.into(), state: DeploymentState::Defined, since: 0.into(), } @@ -38,7 +38,7 @@ impl From for ckb_jsonrpc_types::Deployment { timeout: deployment.timeout.into(), min_activation_epoch: deployment.min_activation_epoch.into(), period: deployment.period.into(), - threshold: deployment.threshold, + threshold: deployment.threshold.into(), } } } diff --git a/util/jsonrpc-types/src/info.rs b/util/jsonrpc-types/src/info.rs index 5f985be3e4..57996d4524 100644 --- a/util/jsonrpc-types/src/info.rs +++ b/util/jsonrpc-types/src/info.rs @@ -1,5 +1,5 @@ -use crate::{AlertMessage, EpochNumber, EpochNumberWithFraction, Timestamp}; -use ckb_types::{core::Ratio, H256, U256}; +use crate::{AlertMessage, EpochNumber, EpochNumberWithFraction, Ratio, Timestamp}; +use ckb_types::{H256, U256}; use serde::{Deserialize, Serialize}; use std::collections::BTreeMap; From 1d3442bc7c3dee96dbb7c918a9dedf931f7271a5 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 12 May 2023 17:33:31 +0800 Subject: [PATCH 3/4] Rpc:: fix rpc example for `get_deployments_info` and `get_consensus` --- rpc/src/module/chain.rs | 4 ++-- rpc/src/module/stats.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rpc/src/module/chain.rs b/rpc/src/module/chain.rs index 66d95ac4ad..1274dd04d0 100644 --- a/rpc/src/module/chain.rs +++ b/rpc/src/module/chain.rs @@ -1374,8 +1374,8 @@ pub trait ChainRpc { /// "period": "0xa", /// "start": "0x0", /// "threshold": { - /// "denom": 4, - /// "numer": 3 + /// "denom": "0x4", + /// "numer": "0x3" /// }, /// "timeout": "0x0" /// } diff --git a/rpc/src/module/stats.rs b/rpc/src/module/stats.rs index bf0441835c..b4162b0e40 100644 --- a/rpc/src/module/stats.rs +++ b/rpc/src/module/stats.rs @@ -87,8 +87,8 @@ pub trait StatsRpc { /// "state": "failed", /// "timeout": "0x0", /// "threshold": { - /// "numer": 3, - /// "denom": 4 + /// "numer": "0x3", + /// "denom": "0x4" /// } /// } /// } From 8ca73e570ba75ea37c08b8d6f231f55cc1f0af47 Mon Sep 17 00:00:00 2001 From: Eval EXEC Date: Fri, 12 May 2023 17:34:51 +0800 Subject: [PATCH 4/4] docs: re-execute `make gen-rpc-doc` --- rpc/README.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/rpc/README.md b/rpc/README.md index 112b924b57..033594e7e4 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -1692,8 +1692,8 @@ Response "period": "0xa", "start": "0x0", "threshold": { - "denom": 4, - "numer": 3 + "denom": "0x4", + "numer": "0x3" }, "timeout": "0x0" } @@ -4730,8 +4730,8 @@ Response "state": "failed", "timeout": "0x0", "threshold": { - "numer": 3, - "denom": 4 + "numer": "0x3", + "denom": "0x4" } } } @@ -6494,6 +6494,13 @@ A non-cellbase transaction is committed at height h_c if all of the following co Represents the ratio `numerator / denominator`, where `numerator` and `denominator` are both unsigned 64-bit integers. +#### Fields + +`Ratio` is a JSON object with the following fields. + +* `numer`: [`Uint64`](#type-uint64) - Numerator. + +* `denom`: [`Uint64`](#type-uint64) - Denominator. ### Type `RationalU256`