Skip to content

Commit

Permalink
Merge pull request #581 from gpBlockchain/develop
Browse files Browse the repository at this point in the history
fix construct chained transaction failed when the previous transaction is in a pending state.
  • Loading branch information
quake authored Feb 27, 2024
2 parents 77e96e1 + c9c9aa6 commit 6a2ccb1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/utils/other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -184,6 +185,36 @@ 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!(
"Invalid Transaction status: {:?}",
transaction.tx_status.status
)),
}
}

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" {
Expand Down

0 comments on commit 6a2ccb1

Please sign in to comment.