Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix construct chained transaction failed when the previous transaction is in a pending state. #581

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 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,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" {
Expand Down
Loading