Skip to content

Commit

Permalink
A few CLI rpc query fixes (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsutton authored Sep 19, 2024
1 parent b14537f commit 4d03153
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
5 changes: 3 additions & 2 deletions cli/src/modules/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ impl Rpc {
}
let hash = argv.remove(0);
let hash = RpcHash::from_hex(hash.as_str())?;
let result = rpc.get_block_call(None, GetBlockRequest { hash, include_transactions: true }).await?;
let include_transactions = argv.first().and_then(|x| x.parse::<bool>().ok()).unwrap_or(true);
let result = rpc.get_block_call(None, GetBlockRequest { hash, include_transactions }).await?;
self.println(&ctx, result);
}
// RpcApiOps::GetSubnetwork => {
Expand All @@ -126,7 +127,7 @@ impl Rpc {
return Err(Error::custom("Missing startHash argument"));
};
let start_hash = RpcHash::from_hex(argv.remove(0).as_str())?;
let include_accepted_transaction_ids = argv.remove(0).parse::<bool>().unwrap_or_default();
let include_accepted_transaction_ids = argv.first().and_then(|x| x.parse::<bool>().ok()).unwrap_or_default();
let result = rpc
.get_virtual_chain_from_block_call(
None,
Expand Down
34 changes: 31 additions & 3 deletions rpc/core/src/model/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use kaspa_consensus_core::tx::{
ScriptPublicKey, ScriptVec, TransactionId, TransactionIndexType, TransactionInput, TransactionOutpoint, TransactionOutput,
UtxoEntry,
};
use kaspa_utils::serde_bytes_fixed_ref;
use kaspa_utils::{hex::ToHex, serde_bytes_fixed_ref};
use serde::{Deserialize, Serialize};
use workflow_serializer::prelude::*;

Expand Down Expand Up @@ -131,7 +131,7 @@ impl Deserializer for RpcTransactionOutpoint {
}

/// Represents a Kaspa transaction input
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcTransactionInput {
pub previous_outpoint: RpcTransactionOutpoint,
Expand All @@ -142,6 +142,18 @@ pub struct RpcTransactionInput {
pub verbose_data: Option<RpcTransactionInputVerboseData>,
}

impl std::fmt::Debug for RpcTransactionInput {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RpcTransactionInput")
.field("previous_outpoint", &self.previous_outpoint)
.field("signature_script", &self.signature_script.to_hex())
.field("sequence", &self.sequence)
.field("sig_op_count", &self.sig_op_count)
.field("verbose_data", &self.verbose_data)
.finish()
}
}

impl From<TransactionInput> for RpcTransactionInput {
fn from(input: TransactionInput) -> Self {
Self {
Expand Down Expand Up @@ -277,7 +289,7 @@ impl Deserializer for RpcTransactionOutputVerboseData {
}

/// Represents a Kaspa transaction
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcTransaction {
pub version: u16,
Expand All @@ -292,6 +304,22 @@ pub struct RpcTransaction {
pub verbose_data: Option<RpcTransactionVerboseData>,
}

impl std::fmt::Debug for RpcTransaction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RpcTransaction")
.field("version", &self.version)
.field("lock_time", &self.lock_time)
.field("subnetwork_id", &self.subnetwork_id)
.field("gas", &self.gas)
.field("payload", &self.payload.to_hex())
.field("mass", &self.mass)
.field("inputs", &self.inputs) // Inputs and outputs are placed purposely at the end for better debug visibility
.field("outputs", &self.outputs)
.field("verbose_data", &self.verbose_data)
.finish()
}
}

impl Serializer for RpcTransaction {
fn serialize<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
store!(u16, &1, writer)?;
Expand Down

0 comments on commit 4d03153

Please sign in to comment.