Skip to content

Commit

Permalink
Merge #2251
Browse files Browse the repository at this point in the history
2251: feat: deprecated rpc method by adding `deprecated.` prefix to the rpc name r=doitian,zhangsoledad,yangby-cryptape a=quake

resolve #2247, rpc method can be deprecated by adding `deprecated.` prefix to the rpc name:
```diff
+    #[rpc(name = "deprecated.get_cells_by_lock_hash")]
-    #[rpc(name = "get_cells_by_lock_hash")]
    fn get_cells_by_lock_hash
```

Co-authored-by: quake <quake.wang@gmail.com>
  • Loading branch information
bors[bot] and quake authored Sep 6, 2020
2 parents f032df5 + 51b8f25 commit a2378b5
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 125 deletions.
6 changes: 5 additions & 1 deletion devtools/doc/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def sort_cases_by_module(cases):


def print_title(case):
print("### `{}`".format(case["method"]))
if case.get("deprecated") is None:
print("### `{}`".format(case["method"]))
else:
print("### ~~`{}`~~".format(case["method"]))
print("**DEPRECATED** {}".format(case["deprecated"]))
newline(1)


Expand Down
5 changes: 5 additions & 0 deletions resource/ckb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ modules = ["Net", "Pool", "Miner", "Chain", "Stats", "Subscription", "Experiment
# ws_listen_address = "127.0.0.1:28114"
reject_ill_transactions = true

# By default deprecated rpc methods are disabled.
enable_deprecated_rpc = false # {{
# integration => enable_deprecated_rpc = true
# }}

[tx_pool]
max_mem_size = 20_000_000 # 20mb
max_cycles = 200_000_000_000
Expand Down
21 changes: 14 additions & 7 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ http://localhost:8114
}
```

### `get_cells_by_lock_hash`
### ~~`get_cells_by_lock_hash`~~
**DEPRECATED** This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution

Returns the information about live cells collection by the hash of lock script.

Expand Down Expand Up @@ -1080,7 +1081,8 @@ http://localhost:8114

## Indexer

### `index_lock_hash`
### ~~`index_lock_hash`~~
**DEPRECATED** This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution

Create index for live cells and transactions by the hash of lock script.

Expand Down Expand Up @@ -1118,7 +1120,8 @@ http://localhost:8114
}
```

### `get_lock_hash_index_states`
### ~~`get_lock_hash_index_states`~~
**DEPRECATED** This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution

Get lock hash index states

Expand Down Expand Up @@ -1151,7 +1154,8 @@ http://localhost:8114
}
```

### `get_live_cells_by_lock_hash`
### ~~`get_live_cells_by_lock_hash`~~
**DEPRECATED** This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution

Returns the live cells collection by the hash of lock script.

Expand Down Expand Up @@ -1447,7 +1451,8 @@ http://localhost:8114
}
```

### `get_transactions_by_lock_hash`
### ~~`get_transactions_by_lock_hash`~~
**DEPRECATED** This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution

Returns the transactions collection by the hash of lock script. Returns empty array when the `lock_hash` has not been indexed yet.

Expand Down Expand Up @@ -1597,7 +1602,8 @@ http://localhost:8114
}
```

### `get_capacity_by_lock_hash`
### ~~`get_capacity_by_lock_hash`~~
**DEPRECATED** This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution

Returns the total capacity by the hash of lock script.

Expand Down Expand Up @@ -1638,7 +1644,8 @@ http://localhost:8114
}
```

### `deindex_lock_hash`
### ~~`deindex_lock_hash`~~
**DEPRECATED** This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution

Remove index for live cells and transactions by the hash of lock script.

Expand Down
7 changes: 7 additions & 0 deletions rpc/json/rpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
]
},
{
"deprecated": "This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution",
"description": "Returns the information about live cells collection by the hash of lock script.",
"method": "get_cells_by_lock_hash",
"module": "chain",
Expand Down Expand Up @@ -1171,6 +1172,7 @@
]
},
{
"deprecated": "This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution",
"description": "Create index for live cells and transactions by the hash of lock script.",
"method": "index_lock_hash",
"module": "indexer",
Expand All @@ -1193,6 +1195,7 @@
]
},
{
"deprecated": "This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution",
"description": "Get lock hash index states",
"method": "get_lock_hash_index_states",
"module": "indexer",
Expand All @@ -1206,6 +1209,7 @@
]
},
{
"deprecated": "This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution",
"description": "Returns the live cells collection by the hash of lock script.",
"method": "get_live_cells_by_lock_hash",
"module": "indexer",
Expand Down Expand Up @@ -1498,6 +1502,7 @@
]
},
{
"deprecated": "This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution",
"description": "Returns the transactions collection by the hash of lock script. Returns empty array when the `lock_hash` has not been indexed yet.",
"method": "get_transactions_by_lock_hash",
"module": "indexer",
Expand Down Expand Up @@ -1636,6 +1641,7 @@
]
},
{
"deprecated": "This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution",
"description": "Returns the total capacity by the hash of lock script.",
"method": "get_capacity_by_lock_hash",
"module": "indexer",
Expand Down Expand Up @@ -1665,6 +1671,7 @@
]
},
{
"deprecated": "This method is deprecated since version 0.36.0 for reasons of flexibility, please use [ckb-indexer](https://github.com/nervosnetwork/ckb-indexer) as an alternate solution",
"description": "Remove index for live cells and transactions by the hash of lock script.",
"method": "deindex_lock_hash",
"module": "indexer",
Expand Down
9 changes: 9 additions & 0 deletions rpc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ impl RPCError {
)
)
}

pub fn rpc_method_is_deprecated() -> Error {
Self::custom(
RPCError::Deprecated,
"This RPC method is deprecated, it will be removed in future release. \
Please check the related information in the CKB release notes and RPC document. \
You may enable deprecated methods via adding `enable_deprecated_rpc = true` to the `[rpc]` section in ckb.toml.",
)
}
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/module/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub trait ChainRpc {
verbosity: Option<Uint32>,
) -> Result<ResponseFormat<HeaderView, Header>>;

#[rpc(name = "get_cells_by_lock_hash")]
#[rpc(name = "deprecated.get_cells_by_lock_hash")]
fn get_cells_by_lock_hash(
&self,
_lock_hash: H256,
Expand Down
12 changes: 6 additions & 6 deletions rpc/src/module/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use jsonrpc_derive::rpc;

#[rpc(server)]
pub trait IndexerRpc {
#[rpc(name = "get_live_cells_by_lock_hash")]
#[rpc(name = "deprecated.get_live_cells_by_lock_hash")]
fn get_live_cells_by_lock_hash(
&self,
_lock_hash: H256,
Expand All @@ -17,7 +17,7 @@ pub trait IndexerRpc {
_reverse_order: Option<bool>,
) -> Result<Vec<LiveCell>>;

#[rpc(name = "get_transactions_by_lock_hash")]
#[rpc(name = "deprecated.get_transactions_by_lock_hash")]
fn get_transactions_by_lock_hash(
&self,
_lock_hash: H256,
Expand All @@ -26,20 +26,20 @@ pub trait IndexerRpc {
_reverse_order: Option<bool>,
) -> Result<Vec<CellTransaction>>;

#[rpc(name = "index_lock_hash")]
#[rpc(name = "deprecated.index_lock_hash")]
fn index_lock_hash(
&self,
_lock_hash: H256,
_index_from: Option<BlockNumber>,
) -> Result<LockHashIndexState>;

#[rpc(name = "deindex_lock_hash")]
#[rpc(name = "deprecated.deindex_lock_hash")]
fn deindex_lock_hash(&self, _lock_hash: H256) -> Result<()>;

#[rpc(name = "get_lock_hash_index_states")]
#[rpc(name = "deprecated.get_lock_hash_index_states")]
fn get_lock_hash_index_states(&self) -> Result<Vec<LockHashIndexState>>;

#[rpc(name = "get_capacity_by_lock_hash")]
#[rpc(name = "deprecated.get_capacity_by_lock_hash")]
fn get_capacity_by_lock_hash(&self, _lock_hash: H256) -> Result<Option<LockHashCapacity>>;
}

Expand Down
Loading

0 comments on commit a2378b5

Please sign in to comment.