pub trait ExperimentRpc {
// Required methods
fn dry_run_transaction(&self, tx: Transaction) -> Result<EstimateCycles>;
fn calculate_dao_maximum_withdraw(
&self,
out_point: OutPoint,
kind: DaoWithdrawingCalculationKind,
) -> Result<Capacity>;
fn estimate_fee_rate(
&self,
estimate_mode: Option<EstimateMode>,
enable_fallback: Option<bool>,
) -> Result<Uint64>;
}Expand description
RPC Module Experiment for experimenting methods.
EXPERIMENTAL warning
The methods here may be removed or changed in future releases without prior notifications.
Required Methods§
Sourcefn dry_run_transaction(&self, tx: Transaction) -> Result<EstimateCycles>
👎Deprecated since 0.105.1: Please use the RPC method estimate_cycles instead
fn dry_run_transaction(&self, tx: Transaction) -> Result<EstimateCycles>
estimate_cycles insteadDry run a transaction and return the execution cycles.
This method will not check the transaction validity, but only run the lock script and type script and then return the execution cycles.
It is used to debug transaction scripts and query how many cycles the scripts consume.
§Errors
TransactionFailedToResolve (-301)- Failed to resolve the referenced cells and headers used in the transaction, as inputs or dependencies.TransactionFailedToVerify (-302)- There is a script returns with an error.
§Examples
Request
{
"id": 42,
"jsonrpc": "2.0",
"method": "dry_run_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": []
}
]
}Response
{
"id": 42,
"jsonrpc": "2.0",
"result": {
"cycles": "0x219"
}
}Sourcefn calculate_dao_maximum_withdraw(
&self,
out_point: OutPoint,
kind: DaoWithdrawingCalculationKind,
) -> Result<Capacity>
fn calculate_dao_maximum_withdraw( &self, out_point: OutPoint, kind: DaoWithdrawingCalculationKind, ) -> Result<Capacity>
Calculates the maximum withdrawal one can get, given a referenced DAO cell, and a withdrawing block hash.
§Params
out_point- Reference to the DAO cell, the depositing transaction’s output.kind- Two kinds of dao withdrawal amount calculation option.
option 1, the assumed reference block hash for withdrawing phase 1 transaction, this block must be in the canonical chain, the calculation of occupied capacity will be based on the depositing transaction’s output, assuming the output of phase 1 transaction is the same as the depositing transaction’s output.
option 2, the out point of the withdrawing phase 1 transaction, the calculation of occupied capacity will be based on corresponding phase 1 transaction’s output.
§Returns
The RPC returns the final capacity when the cell out_point is withdrawn using the block hash or withdrawing phase 1 transaction out point as the reference.
In CKB, scripts cannot get the information about in which block the transaction is committed. A workaround is letting the transaction reference a block hash so the script knows that the transaction is committed at least after the reference block.
§Errors
DaoError (-5)- The given out point is not a valid cell for DAO computation.CKBInternalError (-1)- Mathematics overflow.
§Examples
Request
{
"id": 42,
"jsonrpc": "2.0",
"method": "calculate_dao_maximum_withdraw",
"params": [
{
"index": "0x0",
"tx_hash": "0xa4037a893eb48e18ed4ef61034ce26eba9c585f15c9cee102ae58505565eccc3"
},
"0xa5f5c85987a15de25661e5a214f2c1449cd803f071acc7999820f25246471f40"
]
}Response
{
"id": 42,
"jsonrpc": "2.0",
"result": "0x4a8b4e8a4"
}Sourcefn estimate_fee_rate(
&self,
estimate_mode: Option<EstimateMode>,
enable_fallback: Option<bool>,
) -> Result<Uint64>
fn estimate_fee_rate( &self, estimate_mode: Option<EstimateMode>, enable_fallback: Option<bool>, ) -> Result<Uint64>
Get fee estimates.
§Params
-
estimate_mode- The fee estimate mode.Default:
no_priority. -
enable_fallback- True to enable a simple fallback algorithm, when lack of historical empirical data to estimate fee rates with configured algorithm.Default:
true.
§The fallback algorithm
Since CKB transaction confirmation involves a two-step process—1) propose and 2) commit, it is complex to predict the transaction fee accurately with the expectation that it will be included within a certain block height.
This algorithm relies on two assumptions and uses a simple strategy to estimate the transaction fee: 1) all transactions in the pool are waiting to be proposed, and 2) no new transactions will be added to the pool.
In practice, this simple algorithm should achieve good accuracy fee rate and running performance.
§Returns
The estimated fee rate in shannons per kilobyte.
§Examples
Request
{
"id": 42,
"jsonrpc": "2.0",
"method": "estimate_fee_rate",
"params": []
}Response
{
"id": 42,
"jsonrpc": "2.0",
"result": "0x3e8"
}