Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions devtools/doc/rpc-gen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ fn resolve_type_name(name: &str) -> String {
.unwrap_or_else(|| name.to_string())
}

/// Convert a generic type name to an anchor-safe string
/// e.g. "ResponseFormat<BlockView>" -> "responseformat_for_blockview"
/// Convert a type name to the slug GitHub uses for markdown heading anchors.
/// e.g. "ResponseFormat<BlockView>" -> "responseformatblockview"
fn type_name_to_anchor(name: &str) -> String {
name.to_lowercase().replace('<', "_for_").replace('>', "")
name.chars()
.filter_map(|c| match c {
'A'..='Z' => Some(c.to_ascii_lowercase()),
'a'..='z' | '0'..='9' | '_' | '-' => Some(c),
' ' => Some('-'),
_ => None,
})
.collect()
}

/// Build a mapping from numbered type names (e.g. "ResponseFormat2") to their
Expand Down Expand Up @@ -751,3 +758,26 @@ This is a 64-bit unsigned integer type encoded as the 0x-prefixed hex string in
("RationalU256", "The ratio which numerator and denominator are both 256-bit unsigned integers.")
].iter().map(|&(x, y)| (x.to_string(), y.to_string()))
}

#[cfg(test)]
mod tests {
use super::type_name_to_anchor;

#[test]
fn type_name_anchor_matches_github_for_generic_types() {
assert_eq!(
type_name_to_anchor("ResponseFormat<HeaderView>"),
"responseformatheaderview"
);
assert_eq!(
type_name_to_anchor("IndexerPagination<IndexerCell>"),
"indexerpaginationindexercell"
);
}

#[test]
fn type_name_anchor_preserves_simple_names() {
assert_eq!(type_name_to_anchor("Uint32"), "uint32");
assert_eq!(type_name_to_anchor("ScriptHashType"), "scripthashtype");
}
}
28 changes: 14 additions & 14 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1.
* [Type `IndexerCellType`](#type-indexercelltype)
* [Type `IndexerCellsCapacity`](#type-indexercellscapacity)
* [Type `IndexerOrder`](#type-indexerorder)
* [Type `IndexerPagination<IndexerCell>`](#type-indexerpagination_for_indexercell)
* [Type `IndexerPagination<IndexerTx>`](#type-indexerpagination_for_indexertx)
* [Type `IndexerPagination<IndexerCell>`](#type-indexerpaginationindexercell)
* [Type `IndexerPagination<IndexerTx>`](#type-indexerpaginationindexertx)
* [Type `IndexerRange`](#type-indexerrange)
* [Type `IndexerScriptType`](#type-indexerscripttype)
* [Type `IndexerSearchKey`](#type-indexersearchkey)
Expand Down Expand Up @@ -226,9 +226,9 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.71.1.
* [Type `RawTxPool`](#type-rawtxpool)
* [Type `RemoteNode`](#type-remotenode)
* [Type `RemoteNodeProtocol`](#type-remotenodeprotocol)
* [Type `ResponseFormat<BlockView>`](#type-responseformat_for_blockview)
* [Type `ResponseFormat<HeaderView>`](#type-responseformat_for_headerview)
* [Type `ResponseFormat<TransactionView>`](#type-responseformat_for_transactionview)
* [Type `ResponseFormat<BlockView>`](#type-responseformatblockview)
* [Type `ResponseFormat<HeaderView>`](#type-responseformatheaderview)
* [Type `ResponseFormat<TransactionView>`](#type-responseformattransactionview)
* [Type `Rfc0043`](#type-rfc0043)
* [Type `Script`](#type-script)
* [Type `ScriptHashType`](#type-scripthashtype)
Expand Down Expand Up @@ -630,7 +630,7 @@ When specifying with_cycles, the response object will be different like below:
* `get_header(block_hash, verbosity)`
* `block_hash`: [`H256`](#type-h256)
* `verbosity`: [`Uint32`](#type-uint32) `|` `null`
* result: [`ResponseFormat<HeaderView>`](#type-responseformat_for_headerview) `|` `null`
* result: [`ResponseFormat<HeaderView>`](#type-responseformatheaderview) `|` `null`

Returns the information about a block header by hash.

Expand Down Expand Up @@ -709,7 +709,7 @@ The response looks like below when `verbosity` is 0.
* `get_header_by_number(block_number, verbosity)`
* `block_number`: [`Uint64`](#type-uint64)
* `verbosity`: [`Uint32`](#type-uint32) `|` `null`
* result: [`ResponseFormat<HeaderView>`](#type-responseformat_for_headerview) `|` `null`
* result: [`ResponseFormat<HeaderView>`](#type-responseformatheaderview) `|` `null`

Returns the block header in the [canonical chain](#canonical-chain) with the specific block
number.
Expand Down Expand Up @@ -1022,7 +1022,7 @@ Response
#### Method `get_tip_header`
* `get_tip_header(verbosity)`
* `verbosity`: [`Uint32`](#type-uint32) `|` `null`
* result: [`ResponseFormat<HeaderView>`](#type-responseformat_for_headerview)
* result: [`ResponseFormat<HeaderView>`](#type-responseformatheaderview)

Returns the header with the highest block number in the [canonical chain](#canonical-chain).

Expand Down Expand Up @@ -1552,7 +1552,7 @@ Response
* `get_fork_block(block_hash, verbosity)`
* `block_hash`: [`H256`](#type-h256)
* `verbosity`: [`Uint32`](#type-uint32) `|` `null`
* result: [`ResponseFormat<BlockView>`](#type-responseformat_for_blockview) `|` `null`
* result: [`ResponseFormat<BlockView>`](#type-responseformatblockview) `|` `null`

Returns the information about a fork block by hash.

Expand Down Expand Up @@ -2290,7 +2290,7 @@ Response
* `order`: [`IndexerOrder`](#type-indexerorder)
* `limit`: [`Uint32`](#type-uint32)
* `after`: [`JsonBytes`](#type-jsonbytes) `|` `null`
* result: [`IndexerPagination<IndexerCell>`](#type-indexerpagination_for_indexercell)
* result: [`IndexerPagination<IndexerCell>`](#type-indexerpaginationindexercell)

Returns the live cells collection by the lock or type script.

Expand Down Expand Up @@ -2648,7 +2648,7 @@ Response
* `order`: [`IndexerOrder`](#type-indexerorder)
* `limit`: [`Uint32`](#type-uint32)
* `after`: [`JsonBytes`](#type-jsonbytes) `|` `null`
* result: [`IndexerPagination<IndexerTx>`](#type-indexerpagination_for_indexertx)
* result: [`IndexerPagination<IndexerTx>`](#type-indexerpaginationindexertx)

Returns the transactions collection by the lock or type script.

Expand Down Expand Up @@ -5011,7 +5011,7 @@ Same as CKB Indexer.
* `order`: [`IndexerOrder`](#type-indexerorder)
* `limit`: [`Uint32`](#type-uint32)
* `after`: [`JsonBytes`](#type-jsonbytes) `|` `null`
* result: [`IndexerPagination<IndexerCell>`](#type-indexerpagination_for_indexercell)
* result: [`IndexerPagination<IndexerCell>`](#type-indexerpaginationindexercell)

Returns the live cells collection by the lock or type script.

Expand Down Expand Up @@ -5059,7 +5059,7 @@ Same as CKB Indexer.
* `order`: [`IndexerOrder`](#type-indexerorder)
* `limit`: [`Uint32`](#type-uint32)
* `after`: [`JsonBytes`](#type-jsonbytes) `|` `null`
* result: [`IndexerPagination<IndexerTx>`](#type-indexerpagination_for_indexertx)
* result: [`IndexerPagination<IndexerTx>`](#type-indexerpaginationindexertx)

Returns the transactions collection by the lock or type script.

Expand Down Expand Up @@ -5867,7 +5867,7 @@ BlockResponse with cycles format wrapper

`BlockWithCyclesResponse` is a JSON object with the following fields.

* `block`: [`ResponseFormat<BlockView>`](#type-responseformat_for_blockview) - The block structure
* `block`: [`ResponseFormat<BlockView>`](#type-responseformatblockview) - The block structure

### Type `Buried`
Represent soft fork deployments where the activation epoch is
Expand Down
Loading