Skip to main content

PoolRpc

Trait PoolRpc 

Source
pub trait PoolRpc {
    // Required methods
    fn send_transaction(
        &self,
        tx: Transaction,
        outputs_validator: Option<OutputsValidator>,
    ) -> Result<H256>;
    fn test_tx_pool_accept(
        &self,
        tx: Transaction,
        outputs_validator: Option<OutputsValidator>,
    ) -> Result<EntryCompleted>;
    fn remove_transaction(&self, tx_hash: H256) -> Result<bool>;
    fn tx_pool_info(&self) -> Result<TxPoolInfo>;
    fn clear_tx_pool(&self) -> Result<()>;
    fn clear_tx_verify_queue(&self) -> Result<()>;
    fn get_raw_tx_pool(&self, verbose: Option<bool>) -> Result<RawTxPool>;
    fn get_pool_tx_detail_info(&self, tx_hash: H256) -> Result<PoolTxDetailInfo>;
    fn tx_pool_ready(&self) -> Result<bool>;
}
Expand description

RPC Module Pool for transaction memory pool.

Required Methods§

Source

fn send_transaction( &self, tx: Transaction, outputs_validator: Option<OutputsValidator>, ) -> Result<H256>

Submits a new transaction into the transaction pool. If the transaction is already in the pool, rebroadcast it to peers.

Please note that send_transaction is an asynchronous process. The return of send_transaction does NOT indicate that the transaction have been fully verified. If you want to track the status of the transaction, please use the get_transactionrpc.

§Params
  • transaction - The transaction.
  • outputs_validator - Validates the transaction outputs before entering the tx-pool. (Optional, default is “passthrough”).
§Errors
§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "send_transaction",
  "params": [
    {
      "cell_deps": [
        {
          "dep_type": "code",
          "out_point": {
            "index": "0x0",
            "tx_hash": "0xa4037a893eb48e18ed4ef61034ce26eba9c585f15c9cee102ae58505565eccc3"
          }
        }
      ],
      "header_deps": [
        "0x7978ec7ce5b507cfb52e149e36b1a23f6062ed150503c85bbf825da3599095ed"
      ],
      "inputs": [
        {
          "previous_output": {
            "index": "0x0",
            "tx_hash": "0x365698b50ca0da75dca2c87f9e7b563811d3b5813736b8cc62cc3b106faceb17"
          },
          "since": "0x0"
        }
      ],
      "outputs": [
        {
          "capacity": "0x2540be400",
          "lock": {
            "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5",
            "hash_type": "data",
            "args": "0x"
          },
          "type": null
        }
      ],
      "outputs_data": [
        "0x"
      ],
      "version": "0x0",
      "witnesses": []
    },
    "passthrough"
  ]
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": "0xa0ef4eb5f4ceeb08a4c8524d84c5da95dce2f608e0ca2ec8091191b0f330c6e3"
}
Source

fn test_tx_pool_accept( &self, tx: Transaction, outputs_validator: Option<OutputsValidator>, ) -> Result<EntryCompleted>

Test if a transaction can be accepted by the transaction pool without inserting it into the pool or rebroadcasting it to peers. The parameters and errors of this method are the same as send_transaction.

§Params
  • transaction - The transaction.
  • outputs_validator - Validates the transaction outputs before entering the tx-pool. (Optional, default is “passthrough”).
§Errors
§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "test_tx_pool_accept",
  "params": [
    {
      "cell_deps": [
        {
          "dep_type": "code",
          "out_point": {
            "index": "0x0",
            "tx_hash": "0xa4037a893eb48e18ed4ef61034ce26eba9c585f15c9cee102ae58505565eccc3"
          }
        }
      ],
      "header_deps": [
        "0x7978ec7ce5b507cfb52e149e36b1a23f6062ed150503c85bbf825da3599095ed"
      ],
      "inputs": [
        {
          "previous_output": {
            "index": "0x0",
            "tx_hash": "0x075fe030c1f4725713c5aacf41c2f59b29b284008fdb786e5efd8a058be51d0c"
          },
          "since": "0x0"
        }
      ],
      "outputs": [
        {
          "capacity": "0x2431ac129",
          "lock": {
            "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5",
            "hash_type": "data",
            "args": "0x"
          },
          "type": null
        }
      ],
      "outputs_data": [
        "0x"
      ],
      "version": "0x0",
      "witnesses": []
    },
    "passthrough"
  ]
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": {
    "cycles": "0x219",
    "fee": "0x2a66f36e90"
  }
}

The response looks like below if the transaction pool check fails

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": null,
  "error": {
    "code": -1107,
    "data": "Duplicated(Byte32(0xa0ef4eb5f4ceeb08a4c8524d84c5da95dce2f608e0ca2ec8091191b0f330c6e3))",
    "message": "PoolRejectedDuplicatedTransaction: Transaction(Byte32(0xa0ef4eb5f4ceeb08a4c8524d84c5da95dce2f608e0ca2ec8091191b0f330c6e3)) already exists in transaction_pool"
  }
}
Source

fn remove_transaction(&self, tx_hash: H256) -> Result<bool>

Removes a transaction and all transactions which depends on it from tx pool if it exists.

§Params
  • tx_hash - Hash of a transaction.
§Returns

If the transaction exists, return true; otherwise, return false.

§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "remove_transaction",
  "params": [
    "0xa0ef4eb5f4ceeb08a4c8524d84c5da95dce2f608e0ca2ec8091191b0f330c6e3"
  ]
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": true
}
Source

fn tx_pool_info(&self) -> Result<TxPoolInfo>

Returns the transaction pool information.

§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "tx_pool_info",
  "params": []
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": {
    "last_txs_updated_at": "0x0",
    "min_fee_rate": "0x3e8",
    "min_rbf_rate": "0x5dc",
    "max_tx_pool_size": "0xaba9500",
    "orphan": "0x0",
    "pending": "0x1",
    "proposed": "0x0",
    "tip_hash": "0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40",
    "tip_number": "0x400",
    "total_tx_cycles": "0x219",
    "total_tx_size": "0x112",
    "tx_size_limit": "0x7d000",
    "verify_queue_size": "0x0"
  }
}
Source

fn clear_tx_pool(&self) -> Result<()>

Removes all transactions from the transaction pool.

§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "clear_tx_pool",
  "params": []
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": null
}
Source

fn clear_tx_verify_queue(&self) -> Result<()>

Removes all transactions from the verification queue.

§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "clear_tx_verify_queue",
  "params": []
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": null
}
Source

fn get_raw_tx_pool(&self, verbose: Option<bool>) -> Result<RawTxPool>

Returns all transaction ids in tx pool as a json array of string transaction ids.

§Params
  • verbose - True for a json object, false for array of transaction ids, default=false
§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "get_raw_tx_pool",
  "params": [true]
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result":
   {
       "pending": {
           "0xa0ef4eb5f4ceeb08a4c8524d84c5da95dce2f608e0ca2ec8091191b0f330c6e3": {
               "cycles": "0x219",
               "size": "0x112",
               "fee": "0x16923f7dcf",
               "ancestors_size": "0x112",
               "ancestors_cycles": "0x219",
               "ancestors_count": "0x1",
               "timestamp": "0x17c983e6e44"
           }
       },
       "conflicted": [],
       "proposed": {}
   }
}
Source

fn get_pool_tx_detail_info(&self, tx_hash: H256) -> Result<PoolTxDetailInfo>

Query and returns the details of a transaction in the pool, only for trouble shooting

§Params
  • tx_hash - Hash of a transaction
§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "get_pool_tx_detail_info",
  "params": [
    "0xa0ef4eb5f4ceeb08a4c8524d84c5da95dce2f608e0ca2ec8091191b0f330c6e3"
  ]
}

Response

{
   "jsonrpc": "2.0",
   "result": {
       "ancestors_count": "0x0",
       "descendants_count": "0x0",
       "entry_status": "pending",
       "pending_count": "0x1",
       "proposed_count": "0x0",
       "rank_in_pending": "0x1",
       "score_sortkey": {
           "ancestors_fee": "0x16923f7dcf",
           "ancestors_weight": "0x112",
           "fee": "0x16923f7dcf",
           "weight": "0x112"
       },
       "timestamp": "0x18aa1baa54c"
   },
   "id": 42
}
Source

fn tx_pool_ready(&self) -> Result<bool>

Returns whether tx-pool service is started, ready for request.

§Examples

Request

{
  "id": 42,
  "jsonrpc": "2.0",
  "method": "tx_pool_ready",
  "params": []
}

Response

{
  "id": 42,
  "jsonrpc": "2.0",
  "result": true
}

Implementors§