From 1e8d3ed9074872bb646ae0da3e1e577dfb8ff20b Mon Sep 17 00:00:00 2001 From: gpBlockchain <32102187+gpBlockchain@users.noreply.github.com> Date: Wed, 7 Feb 2024 11:10:24 +0800 Subject: [PATCH 1/3] add-input when cell --- src/utils/other.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/utils/other.rs b/src/utils/other.rs index 9a6bd9a8..142153c2 100644 --- a/src/utils/other.rs +++ b/src/utils/other.rs @@ -8,6 +8,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use ckb_hash::{blake2b_256, new_blake2b}; use ckb_jsonrpc_types as rpc_types; +use ckb_jsonrpc_types::Status; use ckb_sdk::{ constants::{MIN_SECP_CELL_CAPACITY, ONE_CKB}, traits::LiveCell, @@ -184,6 +185,38 @@ pub fn get_live_cell( client: &mut HttpRpcClient, out_point: OutPoint, with_data: bool, +) -> Result<(CellOutput, Bytes), String> { + let transaction = client + .get_transaction(out_point.clone().tx_hash().unpack()) + .map_err(|err| format!("Error retrieving transaction: {}", err))? + .ok_or("Transaction not found")?; + + match transaction.tx_status.status { + Status::Pending | Status::Proposed => { + let tx = transaction + .transaction + .ok_or("Transaction not found")?; + + let id: usize = out_point.clone().index().unpack(); + let output = tx.inner.outputs.get(id) + .cloned() + .ok_or("Output not found")?; + + Ok((output.into(), Bytes::new())) + } + Status::Committed => { + get_live_cell_internal(client, out_point, with_data) + } + Status::Unknown | Status::Rejected => { + Err(format!("Transaction status is unknown or rejected")) + } + } +} + +pub fn get_live_cell_internal( + client: &mut HttpRpcClient, + out_point: OutPoint, + with_data: bool, ) -> Result<(CellOutput, Bytes), String> { let cell = client.get_live_cell(out_point.clone(), with_data)?; if cell.status != "live" { From d21a45b644d6dc225bcee141d0f72f6288bdcc5a Mon Sep 17 00:00:00 2001 From: gpBlockchain <744158715@qq.com> Date: Sun, 18 Feb 2024 16:51:46 +0800 Subject: [PATCH 2/3] style: format code --- src/utils/other.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/utils/other.rs b/src/utils/other.rs index 142153c2..b3a72665 100644 --- a/src/utils/other.rs +++ b/src/utils/other.rs @@ -193,20 +193,17 @@ pub fn get_live_cell( match transaction.tx_status.status { Status::Pending | Status::Proposed => { - let tx = transaction - .transaction - .ok_or("Transaction not found")?; - + let tx = transaction.transaction.ok_or("Transaction not found")?; let id: usize = out_point.clone().index().unpack(); - let output = tx.inner.outputs.get(id) + let output = tx + .inner + .outputs + .get(id) .cloned() .ok_or("Output not found")?; - Ok((output.into(), Bytes::new())) } - Status::Committed => { - get_live_cell_internal(client, out_point, with_data) - } + Status::Committed => get_live_cell_internal(client, out_point, with_data), Status::Unknown | Status::Rejected => { Err(format!("Transaction status is unknown or rejected")) } From c9c9aa632a296e78860515f49170cb22b4ea3a1f Mon Sep 17 00:00:00 2001 From: gpBlockchain <744158715@qq.com> Date: Tue, 20 Feb 2024 09:53:10 +0800 Subject: [PATCH 3/3] style: fix fix the CI linters error --- src/utils/other.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/utils/other.rs b/src/utils/other.rs index b3a72665..0ce89d19 100644 --- a/src/utils/other.rs +++ b/src/utils/other.rs @@ -204,9 +204,10 @@ pub fn get_live_cell( Ok((output.into(), Bytes::new())) } Status::Committed => get_live_cell_internal(client, out_point, with_data), - Status::Unknown | Status::Rejected => { - Err(format!("Transaction status is unknown or rejected")) - } + Status::Unknown | Status::Rejected => Err(format!( + "Invalid Transaction status: {:?}", + transaction.tx_status.status + )), } }