Skip to content

Commit

Permalink
Refctorize some part of code to apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
KaffinPX committed May 30, 2024
1 parent 9e56856 commit 4f4167f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions rpc/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ async-trait.workspace = true
log.workspace = true
tokio.workspace = true
triggered.workspace = true
itertools.workspace = true
workflow-rpc.workspace = true
26 changes: 14 additions & 12 deletions rpc/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::collector::{CollectorFromConsensus, CollectorFromIndex};
use crate::converter::{consensus::ConsensusConverter, index::IndexConverter, protocol::ProtocolConverter};
use crate::service::NetworkType::{Mainnet, Testnet};
use async_trait::async_trait;
use itertools::Itertools;
use kaspa_consensus_core::api::counters::ProcessingCounters;
use kaspa_consensus_core::errors::block::RuleError;
use kaspa_consensus_core::{
Expand Down Expand Up @@ -64,6 +65,7 @@ use kaspa_txscript::{extract_script_pub_key_address, pay_to_address_script};
use kaspa_utils::{channel::Channel, triggers::SingleTrigger};
use kaspa_utils_tower::counters::TowerConnectionCounters;
use kaspa_utxoindex::api::UtxoIndexProxy;
use std::iter;
use std::{
collections::HashMap,
iter::once,
Expand Down Expand Up @@ -495,24 +497,24 @@ NOTE: This error usually indicates an RPC conversion error between the node and
let transaction_id = transaction.id();
let inputs = &transaction.inputs;

let empty_indices = inputs
.iter()
.enumerate()
.filter_map(|(index, input)| (input.signature_script.is_empty()).then_some(index.to_string()))
.collect::<Vec<_>>();
if !empty_indices.is_empty() {
Err(RpcError::EmptySignatureScript(transaction_id, empty_indices.join(", ")))
let mut empty_indices =
inputs.iter().enumerate().filter_map(|(index, input)| (input.signature_script.is_empty()).then_some(index.to_string()));
let first_empty = empty_indices.next();
if let Some(first_empty) = first_empty {
Err(RpcError::EmptySignatureScript(transaction_id, iter::once(first_empty).chain(empty_indices).join(", ")))
} else {
let session = self.consensus_manager.consensus().unguarded_session();
let orphan = match allow_orphan {
true => Orphan::Allowed,
false => Orphan::Forbidden,
};
self.flow_context.submit_rpc_transaction(&session, transaction, orphan).await.map_err(|err| {
let err = RpcError::RejectedTransaction(transaction_id, err.to_string());
debug!("{err}");
err
})?;
self.flow_context
.submit_rpc_transaction(&session, transaction, orphan)
.await
.as_ref()
.map_err(ToString::to_string)
.map_err(|err| RpcError::RejectedTransaction(transaction_id, err))
.inspect_err(|err| debug!("{err}"))?;
Ok(SubmitTransactionResponse::new(transaction_id))
}
}
Expand Down

0 comments on commit 4f4167f

Please sign in to comment.