This commit is contained in:
hinto.janai 2024-12-13 15:16:26 -05:00
parent a359eed8be
commit ab4822c660
No known key found for this signature in database
GPG key ID: D47CE05FA175A499

View file

@ -142,19 +142,26 @@ async fn get_transactions(
txpool::txs_by_hash(&mut state.txpool_read, missed_txs, include_sensitive_txs).await? txpool::txs_by_hash(&mut state.txpool_read, missed_txs, include_sensitive_txs).await?
}; };
let (txs, txs_as_json) = { let (txs, txs_as_json, txs_as_hex) = {
// Prepare the final JSON output. // Prepare the final JSON output.
let len = txs_in_blockchain.len() + txs_in_pool.len(); let len = txs_in_blockchain.len() + txs_in_pool.len();
let mut txs = Vec::with_capacity(len); let mut txs = Vec::with_capacity(len);
let mut txs_as_json = Vec::with_capacity(if request.decode_as_json { len } else { 0 }); let mut txs_as_json = Vec::with_capacity(if request.decode_as_json { len } else { 0 });
let mut txs_as_hex = vec![];
// Map all blockchain transactions. // Map all blockchain transactions.
for tx in txs_in_blockchain { for tx in txs_in_blockchain {
let tx_hash = Hex(tx.tx_hash); let tx_hash = Hex(tx.tx_hash);
let pruned_as_hex = hex::encode(tx.pruned_blob);
let prunable_as_hex = hex::encode(tx.prunable_blob);
let prunable_hash = Hex(tx.prunable_hash); let prunable_hash = Hex(tx.prunable_hash);
let (pruned_as_hex, prunable_as_hex) = if tx.pruned_blob.is_empty() {
(String::new(), String::new())
} else {
(hex::encode(tx.pruned_blob), hex::encode(tx.prunable_blob))
};
txs_as_hex.push(pruned_as_hex.clone());
let as_json = if request.decode_as_json { let as_json = if request.decode_as_json {
let tx = Transaction::read(&mut tx.tx_blob.as_slice())?; let tx = Transaction::read(&mut tx.tx_blob.as_slice())?;
let json_type = cuprate_types::json::tx::Transaction::from(tx); let json_type = cuprate_types::json::tx::Transaction::from(tx);
@ -204,6 +211,7 @@ async fn get_transactions(
let pruned_as_hex = String::new(); let pruned_as_hex = String::new();
let prunable_as_hex = String::new(); let prunable_as_hex = String::new();
let prunable_hash = Hex([0; 32]); let prunable_hash = Hex([0; 32]);
txs_as_hex.push(pruned_as_hex.clone());
let as_json = if request.decode_as_json { let as_json = if request.decode_as_json {
let json_type = cuprate_types::json::tx::Transaction::from(tx); let json_type = cuprate_types::json::tx::Transaction::from(tx);
@ -234,12 +242,12 @@ async fn get_transactions(
txs.push(tx); txs.push(tx);
} }
(txs, txs_as_json) (txs, txs_as_json, txs_as_hex)
}; };
Ok(GetTransactionsResponse { Ok(GetTransactionsResponse {
base: AccessResponseBase::OK, base: AccessResponseBase::OK,
txs_as_hex: vec![], txs_as_hex,
txs_as_json, txs_as_json,
missed_tx, missed_tx,
txs, txs,