Add txid to transaction trace

This commit is contained in:
Andrew Poelstra 2014-08-17 17:25:47 -07:00
parent 7059c21ef4
commit d3ef264b44
1 changed files with 12 additions and 9 deletions

View File

@ -119,6 +119,8 @@ pub struct ScriptTrace {
/// A trace of a transaction input's script execution /// A trace of a transaction input's script execution
#[deriving(PartialEq, Eq, Clone, Show)] #[deriving(PartialEq, Eq, Clone, Show)]
pub struct InputTrace { pub struct InputTrace {
input_txid: Sha256dHash,
input_vout: uint,
sig_trace: ScriptTrace, sig_trace: ScriptTrace,
pubkey_trace: Option<ScriptTrace>, pubkey_trace: Option<ScriptTrace>,
p2sh_trace: Option<ScriptTrace>, p2sh_trace: Option<ScriptTrace>,
@ -126,19 +128,17 @@ pub struct InputTrace {
} }
impl_json!(ScriptTrace, script, initial_stack, iterations, error) impl_json!(ScriptTrace, script, initial_stack, iterations, error)
impl_json!(InputTrace, sig_trace, pubkey_trace, p2sh_trace, error) impl_json!(InputTrace, input_txid, input_vout, sig_trace,
pubkey_trace, p2sh_trace, error)
/// A trace of a transaction's execution /// A trace of a transaction's execution
#[deriving(PartialEq, Eq, Clone, Show)] #[deriving(PartialEq, Eq, Clone, Show)]
pub struct TransactionTrace { pub struct TransactionTrace {
input_trace: Vec<InputTrace> txid: Sha256dHash,
inputs: Vec<InputTrace>
} }
impl json::ToJson for TransactionTrace { impl_json!(TransactionTrace, txid, inputs)
fn to_json(&self) -> json::Json {
self.input_trace.to_json()
}
}
impl Transaction { impl Transaction {
/// Check a transaction for validity /// Check a transaction for validity
@ -198,10 +198,13 @@ impl Transaction {
/// Produce a trace of a transaction's execution /// Produce a trace of a transaction's execution
pub fn trace(&self, utxoset: &UtxoSet) -> TransactionTrace { pub fn trace(&self, utxoset: &UtxoSet) -> TransactionTrace {
let mut ret = TransactionTrace { input_trace: Vec::with_capacity(self.input.len()) }; let mut ret = TransactionTrace { txid: self.bitcoin_hash(),
inputs: Vec::with_capacity(self.input.len()) };
for (n, input) in self.input.iter().enumerate() { for (n, input) in self.input.iter().enumerate() {
// Setup trace // Setup trace
let mut trace = InputTrace { let mut trace = InputTrace {
input_txid: input.prev_hash,
input_vout: input.prev_index as uint,
sig_trace: ScriptTrace { sig_trace: ScriptTrace {
script: Script::new(), script: Script::new(),
initial_stack: vec![], initial_stack: vec![],
@ -295,7 +298,7 @@ impl Transaction {
trace.error = Some(InputNotFound(input.prev_hash, input.prev_index)); trace.error = Some(InputNotFound(input.prev_hash, input.prev_index));
} }
} }
ret.input_trace.push(trace); ret.inputs.push(trace);
} }
ret ret
} }