Skip to content

Commit

Permalink
Add include_tx_pool: Option<bool> to ChainRpc::get_live_cell
Browse files Browse the repository at this point in the history
  • Loading branch information
eval-exec committed May 11, 2024
1 parent b4bb629 commit 504bbd6
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/subcommands/deploy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ fn load_cell_info(
.index(index.pack())
.build();
let cell_with_status = rpc_client
.get_live_cell(out_point, true)
.get_live_cell(out_point, true, None)
.map_err(Error::msg)?;
if cell_with_status.status != "live" {
return Err(anyhow!(
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/mock_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl<'a> MockResourceLoader for Loader<'a> {
) -> Result<Option<(CellOutput, Bytes, Option<Byte32>)>, String> {
let output: Option<CellOutput> = self
.rpc_client
.get_live_cell(out_point.clone(), true)
.get_live_cell(out_point.clone(), true, None)
.map(|resp| resp.cell.map(|info| info.output.into()))?;
if let Some(output) = output {
Ok(self
Expand Down
16 changes: 13 additions & 3 deletions src/subcommands/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ impl<'a> RpcSubCommand<'a> {
.arg(
Arg::with_name("with-data")
.long("with-data")
.about("Get live cell with data")
.about("get live cell with data")
)
.arg(
Arg::with_name("include-tx-pool")
.long("include-tx-pool")
.about("check if it's a live cell in tx pool")
),
App::new("get_tip_block_number").about("Get tip block number"),
App::new("get_tip_header").about("Get tip header")
Expand Down Expand Up @@ -649,6 +654,7 @@ impl<'a> CliSubCommand for RpcSubCommand<'a> {
FixedHashParser::<H256>::default().from_matches(m, "tx-hash")?;
let index: u32 = FromStrParser::<u32>::default().from_matches(m, "index")?;
let with_data = m.is_present("with-data");
let include_tx_pool = m.is_present("include-tx-pool");

let out_point = packed::OutPoint::new_builder()
.tx_hash(tx_hash.pack())
Expand All @@ -657,11 +663,15 @@ impl<'a> CliSubCommand for RpcSubCommand<'a> {
if is_raw_data {
let resp = self
.raw_rpc_client
.get_live_cell(out_point.into(), with_data)
.get_live_cell(out_point.into(), with_data, Some(include_tx_pool))
.map_err(|err| err.to_string())?;
Ok(Output::new_output(resp))
} else {
let resp = self.rpc_client.get_live_cell(out_point, with_data)?;
let resp = self.rpc_client.get_live_cell(
out_point,
with_data,
Some(include_tx_pool),
)?;
Ok(Output::new_output(resp))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/subcommands/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ message = "0x"
.tx_hash(tx_hash.pack())
.index(index.pack())
.build();
let cell_with_status = self.rpc_client.get_live_cell(out_point, true)?;
let cell_with_status = self.rpc_client.get_live_cell(out_point, true, None)?;
if cell_with_status.status != "live" {
Ok(Output::new_output(cell_with_status))
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub fn get_live_cell_internal(
out_point: OutPoint,
with_data: bool,
) -> Result<(CellOutput, Bytes), String> {
let cell = client.get_live_cell(out_point.clone(), with_data)?;
let cell = client.get_live_cell(out_point.clone(), with_data, None)?;
if cell.status != "live" {
return Err(format!(
"Invalid cell status: {}, out_point: {}",
Expand Down
5 changes: 3 additions & 2 deletions src/utils/rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,15 @@ impl HttpRpcClient {
.map(|opt| opt.map(Into::into))
.map_err(|err| err.to_string())
}
// TODO: Make `cell::CellData` public

pub fn get_live_cell(
&mut self,
out_point: packed::OutPoint,
with_data: bool,
include_tx_pool: Option<bool>,
) -> Result<CellWithStatus, String> {
self.client
.get_live_cell(out_point.into(), with_data)
.get_live_cell(out_point.into(), with_data, include_tx_pool)
.map_err(|err| err.to_string())
}
pub fn get_tip_block_number(&mut self) -> Result<u64, String> {
Expand Down

0 comments on commit 504bbd6

Please sign in to comment.