Unify tracing interface into a single call.
This commit is contained in:
parent
a132fefcc7
commit
7dc05f1bcc
@ -28,7 +28,7 @@ use ethcore::state_diff::StateDiff;
|
|||||||
use ethcore::account_diff::{Diff, Existance};
|
use ethcore::account_diff::{Diff, Existance};
|
||||||
use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action};
|
use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action};
|
||||||
use v1::traits::Traces;
|
use v1::traits::Traces;
|
||||||
use v1::types::{TraceFilter, LocalizedTrace, Trace, BlockNumber, Index, CallRequest};
|
use v1::types::{TraceFilter, LocalizedTrace, Trace, BlockNumber, Index, CallRequest, Bytes};
|
||||||
|
|
||||||
/// Traces api implementation.
|
/// Traces api implementation.
|
||||||
pub struct TracesClient<C, M> where C: BlockChainClient, M: MinerService {
|
pub struct TracesClient<C, M> where C: BlockChainClient, M: MinerService {
|
||||||
@ -195,46 +195,31 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trace_call(&self, params: Params) -> Result<Value, Error> {
|
fn call(&self, params: Params) -> Result<Value, Error> {
|
||||||
trace!(target: "jsonrpc", "trace_call: {:?}", params);
|
trace!(target: "jsonrpc", "call: {:?}", params);
|
||||||
from_params(params)
|
from_params(params)
|
||||||
.and_then(|(request,)| {
|
.and_then(|(request, flags)| {
|
||||||
|
let flags: Vec<String> = flags;
|
||||||
|
let analytics = CallAnalytics {
|
||||||
|
transaction_tracing: flags.contains(&("trace".to_owned())),
|
||||||
|
vm_tracing: flags.contains(&("vmTrace".to_owned())),
|
||||||
|
state_diffing: flags.contains(&("stateDiff".to_owned())),
|
||||||
|
};
|
||||||
let signed = try!(self.sign_call(request));
|
let signed = try!(self.sign_call(request));
|
||||||
let r = take_weak!(self.client).call(&signed, CallAnalytics{ transaction_tracing: true, vm_tracing: false, state_diffing: false });
|
let r = take_weak!(self.client).call(&signed, analytics);
|
||||||
if let Ok(executed) = r {
|
if let Ok(executed) = r {
|
||||||
|
// TODO maybe add other stuff to this?
|
||||||
|
let mut ret = map!["output".to_owned() => to_value(&Bytes(executed.output)).unwrap()];
|
||||||
if let Some(trace) = executed.trace {
|
if let Some(trace) = executed.trace {
|
||||||
return to_value(&Trace::from(trace));
|
ret.insert("trace".to_owned(), to_value(&Trace::from(trace)).unwrap());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(Value::Null)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn vm_trace_call(&self, params: Params) -> Result<Value, Error> {
|
|
||||||
trace!(target: "jsonrpc", "vm_trace_call: {:?}", params);
|
|
||||||
from_params(params)
|
|
||||||
.and_then(|(request,)| {
|
|
||||||
let signed = try!(self.sign_call(request));
|
|
||||||
let r = take_weak!(self.client).call(&signed, CallAnalytics{ transaction_tracing: false, vm_tracing: true, state_diffing: false });
|
|
||||||
if let Ok(executed) = r {
|
|
||||||
if let Some(vm_trace) = executed.vm_trace {
|
if let Some(vm_trace) = executed.vm_trace {
|
||||||
return Ok(vm_trace_to_object(&vm_trace));
|
ret.insert("vmTrace".to_owned(), vm_trace_to_object(&vm_trace));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Ok(Value::Null)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn state_diff_call(&self, params: Params) -> Result<Value, Error> {
|
|
||||||
trace!(target: "jsonrpc", "state_diff_call: {:?}", params);
|
|
||||||
from_params(params)
|
|
||||||
.and_then(|(request,)| {
|
|
||||||
let signed = try!(self.sign_call(request));
|
|
||||||
let r = take_weak!(self.client).call(&signed, CallAnalytics{ transaction_tracing: false, vm_tracing: false, state_diffing: true });
|
|
||||||
if let Ok(executed) = r {
|
|
||||||
if let Some(state_diff) = executed.state_diff {
|
if let Some(state_diff) = executed.state_diff {
|
||||||
return Ok(state_diff_to_object(&state_diff));
|
ret.insert("stateDiff".to_owned(), state_diff_to_object(&state_diff));
|
||||||
}
|
}
|
||||||
|
return Ok(Value::Object(ret))
|
||||||
}
|
}
|
||||||
Ok(Value::Null)
|
Ok(Value::Null)
|
||||||
})
|
})
|
||||||
|
@ -32,14 +32,8 @@ pub trait Traces: Sized + Send + Sync + 'static {
|
|||||||
/// Returns all traces produced at given block.
|
/// Returns all traces produced at given block.
|
||||||
fn block_traces(&self, _: Params) -> Result<Value, Error>;
|
fn block_traces(&self, _: Params) -> Result<Value, Error>;
|
||||||
|
|
||||||
/// Executes the given call and returns the transaction trace for it.
|
/// Executes the given call and returns a number of possible traces for it.
|
||||||
fn trace_call(&self, _: Params) -> Result<Value, Error>;
|
fn call(&self, _: Params) -> Result<Value, Error>;
|
||||||
|
|
||||||
/// Executes the given call and returns the VM trace for it.
|
|
||||||
fn vm_trace_call(&self, _: Params) -> Result<Value, Error>;
|
|
||||||
|
|
||||||
/// Executes the given call and returns the diff for it.
|
|
||||||
fn state_diff_call(&self, _: Params) -> Result<Value, Error>;
|
|
||||||
|
|
||||||
/// Should be used to convert object to io delegate.
|
/// Should be used to convert object to io delegate.
|
||||||
fn to_delegate(self) -> IoDelegate<Self> {
|
fn to_delegate(self) -> IoDelegate<Self> {
|
||||||
@ -48,10 +42,7 @@ pub trait Traces: Sized + Send + Sync + 'static {
|
|||||||
delegate.add_method("trace_get", Traces::trace);
|
delegate.add_method("trace_get", Traces::trace);
|
||||||
delegate.add_method("trace_transaction", Traces::transaction_traces);
|
delegate.add_method("trace_transaction", Traces::transaction_traces);
|
||||||
delegate.add_method("trace_block", Traces::block_traces);
|
delegate.add_method("trace_block", Traces::block_traces);
|
||||||
|
delegate.add_method("trace_call", Traces::call);
|
||||||
delegate.add_method("trace_traceCall", Traces::trace_call);
|
|
||||||
delegate.add_method("trace_vmTraceCall", Traces::vm_trace_call);
|
|
||||||
delegate.add_method("trace_stateDiffCall", Traces::state_diff_call);
|
|
||||||
|
|
||||||
delegate
|
delegate
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user