Skip to content

Commit

Permalink
Merge #2470
Browse files Browse the repository at this point in the history
2470: docs: fix reject tx subscription RPC doc r=quake,yangby-cryptape a=doitian

Fix RPC doc added in #2365

Co-authored-by: ian <[email protected]>
  • Loading branch information
bors[bot] and doitian authored Dec 30, 2020
2 parents 6e34d89 + c907432 commit f0999f0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
26 changes: 25 additions & 1 deletion devtools/doc/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
def camel_to_snake(name):
return CAMEL_TO_SNAKE_PATTERN.sub('_', name).lower()

def snake_to_camel(name):
return name.title().replace('_', '')


def transform_href(href):
if href.startswith(HREF_PREFIX_RPCERROR):
Expand Down Expand Up @@ -501,6 +504,10 @@ def handle_data(self, data):
self.variant_parser.handle_data(data)

def write(self, file):
if self.name == 'PoolTransactionReject':
self.write_pool_transaction_reject(file)
return

file.write('`{}` is equivalent to `"{}"`.\n\n'.format(
self.name, '" | "'.join(v[0] for v in self.variants)))

Expand All @@ -511,6 +518,22 @@ def write(self, file):
file.write(out.getvalue().lstrip())
file.write('\n')

# PoolTransactionReject
def write_pool_transaction_reject(self, file):
file.write('`{}` is a JSON object with following fields.\n\n'.format(self.name))

file.write('* `type`: `"{}"` - Reject type.\n'.format(
'" | "'.join(snake_to_camel(v[0]) for v in self.variants)))
file.write('* `description`: `string` - Detailed description about why the transaction is rejected.\n\n')
file.write('Different reject types:\n\n')

for (name, v) in self.variants:
file.write('* `{}`: '.format(snake_to_camel(name)))
out = io.StringIO()
v.write(out)
file.write(out.getvalue().lstrip())
file.write('\n')


class StructSchema(HTMLParser):
def __init__(self, name):
Expand Down Expand Up @@ -678,8 +701,9 @@ def collect(self):
for path in pending:
self.collect_type(path)

# PoolTransactionEntry is not used in RPC but in the Subscription events.
# Referenced by subscription RPC.
self.collect_type('ckb_jsonrpc_types/struct.PoolTransactionEntry.html')
self.collect_type('ckb_jsonrpc_types/enum.PoolTransactionReject.html')
# Referenced by RawTxPool
self.collect_type('ckb_jsonrpc_types/struct.TxPoolIds.html')
self.collect_type('ckb_jsonrpc_types/struct.TxPoolVerbosity.html')
Expand Down
27 changes: 25 additions & 2 deletions rpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ The crate `ckb-rpc`'s minimum supported rustc version is 1.46.0.
* [Type `PeerState`](#type-peerstate)
* [Type `PeerSyncState`](#type-peersyncstate)
* [Type `PoolTransactionEntry`](#type-pooltransactionentry)
* [Type `PoolTransactionReject`](#type-pooltransactionreject)
* [Type `ProposalShortId`](#type-proposalshortid)
* [Type `ProposalWindow`](#type-proposalwindow)
* [Type `RationalU256`](#type-rationalu256)
Expand Down Expand Up @@ -3500,9 +3501,11 @@ Subscribers will get notified when a pending transaction is rejected by tx-pool.

The type of the `params.result` in the push message is an array contain:

* [`PoolTransactionEntry`](#type-pooltransactionentry).
The type of the `params.result` in the push message is a two-elements array, where

* [`PoolTransactionReject`](#type-pooltransactionreject).
* the first item type is [`PoolTransactionEntry`](#type-pooltransactionentry), and

* the second item type is [`PoolTransactionReject`](#type-pooltransactionreject).

##### Examples

Expand Down Expand Up @@ -4901,6 +4904,26 @@ The transaction entry in the pool.
* `fee`: [`Capacity`](#type-capacity) - The transaction fee.


### Type `PoolTransactionReject`

TX reject message

`PoolTransactionReject` is a JSON object with following fields.

* `type`: `"LowFeeRate" | "ExceededMaximumAncestorsCount" | "Full" | "Duplicated" | "Malformed" | "Resolve" | "Verification"` - Reject type.
* `description`: `string` - Detailed description about why the transaction is rejected.

Different reject types:

* `LowFeeRate`: Transaction fee lower than config
* `ExceededMaximumAncestorsCount`: Transaction exceeded maximum ancestors count limit
* `Full`: Transaction pool exceeded maximum size or cycles limit,
* `Duplicated`: Transaction already exist in transaction_pool
* `Malformed`: Malformed transaction
* `Resolve`: Resolve failed
* `Verification`: Verification failed


### Type `ProposalShortId`

The 10-byte fixed-length binary encoded as a 0x-prefixed hex string in JSON.
Expand Down
6 changes: 4 additions & 2 deletions rpc/src/module/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ pub trait SubscriptionRpc {
///
/// The type of the `params.result` in the push message is an array contain:
///
/// - [`PoolTransactionEntry`](../../ckb_jsonrpc_types/struct.PoolTransactionEntry.html).
/// - [`PoolTransactionReject`](../../ckb_jsonrpc_types/struct.PoolTransactionReject.html).
/// The type of the `params.result` in the push message is a two-elements array, where
///
/// - the first item type is [`PoolTransactionEntry`](../../ckb_jsonrpc_types/struct.PoolTransactionEntry.html), and
/// - the second item type is [`PoolTransactionReject`](../../ckb_jsonrpc_types/struct.PoolTransactionReject.html).
///
/// ## Examples
///
Expand Down

0 comments on commit f0999f0

Please sign in to comment.