From c907432ef68ac5bad6c3b33754b882779c5dccfb Mon Sep 17 00:00:00 2001 From: ian Date: Thu, 24 Dec 2020 10:41:07 +0800 Subject: [PATCH] docs: fix reject tx subscription RPC doc --- devtools/doc/rpc.py | 26 +++++++++++++++++++++++++- rpc/README.md | 27 +++++++++++++++++++++++++-- rpc/src/module/subscription.rs | 6 ++++-- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/devtools/doc/rpc.py b/devtools/doc/rpc.py index 1b72594476..5988034564 100755 --- a/devtools/doc/rpc.py +++ b/devtools/doc/rpc.py @@ -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): @@ -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))) @@ -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): @@ -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') diff --git a/rpc/README.md b/rpc/README.md index e4f5acb549..5d58d647da 100644 --- a/rpc/README.md +++ b/rpc/README.md @@ -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) @@ -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 @@ -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. diff --git a/rpc/src/module/subscription.rs b/rpc/src/module/subscription.rs index 8b1ff65910..7f397bd9da 100644 --- a/rpc/src/module/subscription.rs +++ b/rpc/src/module/subscription.rs @@ -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 ///