Add trace_{call, rawTransaction, replayTransaction}
This commit is contained in:
@@ -166,3 +166,11 @@ export function inTraceFilter (filterObject) {
|
||||
|
||||
return filterObject;
|
||||
}
|
||||
|
||||
export function inTraceType (whatTrace) {
|
||||
if (isString(whatTrace)) {
|
||||
return [whatTrace];
|
||||
}
|
||||
|
||||
return whatTrace;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import BigNumber from 'bignumber.js';
|
||||
|
||||
import { inAddress, inBlockNumber, inData, inFilter, inHex, inNumber10, inNumber16, inOptions } from './input';
|
||||
import { inAddress, inBlockNumber, inData, inFilter, inHex, inNumber10, inNumber16, inOptions, inTraceType } from './input';
|
||||
import { isAddress } from '../../../test/types';
|
||||
|
||||
describe('api/format/input', () => {
|
||||
@@ -242,4 +242,16 @@ describe('api/format/input', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('inTraceType', () => {
|
||||
it('returns array of types as is', () => {
|
||||
const types = ['vmTrace', 'trace', 'stateDiff'];
|
||||
expect(inTraceType(types)).to.deep.equal(types);
|
||||
});
|
||||
|
||||
it('formats single string type into array', () => {
|
||||
const type = 'vmTrace';
|
||||
expect(inTraceType(type)).to.deep.equal([type]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -254,3 +254,25 @@ export function outTrace (trace) {
|
||||
|
||||
return trace;
|
||||
}
|
||||
|
||||
export function outTraces (traces) {
|
||||
if (traces) {
|
||||
return traces.map(outTrace);
|
||||
}
|
||||
|
||||
return traces;
|
||||
}
|
||||
|
||||
export function outTraceReplay (trace) {
|
||||
if (trace) {
|
||||
Object.keys(trace).forEach((key) => {
|
||||
switch (key) {
|
||||
case 'trace':
|
||||
trace[key] = outTraces(trace[key]);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return trace;
|
||||
}
|
||||
|
||||
@@ -16,19 +16,29 @@
|
||||
|
||||
import { createHttpApi } from '../../../../test/e2e/ethapi';
|
||||
|
||||
describe('ethapi.trace', () => {
|
||||
describe.only('ethapi.trace', () => {
|
||||
const ethapi = createHttpApi();
|
||||
|
||||
describe('block', () => {
|
||||
it('returns the latest block', () => {
|
||||
return ethapi.trace.block().then((block) => {
|
||||
expect(block).to.be.ok;
|
||||
it('returns the latest block traces', () => {
|
||||
return ethapi.trace.block().then((traces) => {
|
||||
expect(traces).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
it('returns a specified block', () => {
|
||||
return ethapi.trace.block('0x65432').then((block) => {
|
||||
expect(block).to.be.ok;
|
||||
it('returns traces for a specified block', () => {
|
||||
return ethapi.trace.block('0x65432').then((traces) => {
|
||||
expect(traces).to.be.ok;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('replayTransaction', () => {
|
||||
it('returns traces for a specific transaction', () => {
|
||||
return ethapi.eth.getBlockByNumber().then((latestBlock) => {
|
||||
return ethapi.trace.replayTransaction(latestBlock.transactions[0]).then((traces) => {
|
||||
expect(traces).to.be.ok;
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,35 +14,53 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import { inBlockNumber, inHex, inNumber16, inTraceFilter } from '../../format/input';
|
||||
import { outTrace } from '../../format/output';
|
||||
import { inBlockNumber, inData, inHex, inNumber16, inOptions, inTraceFilter, inTraceType } from '../../format/input';
|
||||
import { outTraces, outTraceReplay } from '../../format/output';
|
||||
|
||||
export default class Trace {
|
||||
constructor (transport) {
|
||||
this._transport = transport;
|
||||
}
|
||||
|
||||
block (blockNumber = 'latest') {
|
||||
return this._transport
|
||||
.execute('trace_block', inBlockNumber(blockNumber))
|
||||
.then(outTraces);
|
||||
}
|
||||
|
||||
call (options, blockNumber = 'latest', whatTrace = ['trace']) {
|
||||
return this._transport
|
||||
.execute('trace_call', inOptions(options), inBlockNumber(blockNumber), inTraceType(whatTrace))
|
||||
.then(outTraceReplay);
|
||||
}
|
||||
|
||||
filter (filterObj) {
|
||||
return this._transport
|
||||
.execute('trace_filter', inTraceFilter(filterObj))
|
||||
.then(traces => traces.map(trace => outTrace(trace)));
|
||||
.then(outTraces);
|
||||
}
|
||||
|
||||
get (txHash, position) {
|
||||
return this._transport
|
||||
.execute('trace_get', inHex(txHash), inNumber16(position))
|
||||
.then(trace => outTrace(trace));
|
||||
.then(outTraces);
|
||||
}
|
||||
|
||||
rawTransaction (data, whatTrace = ['trace']) {
|
||||
return this._transport
|
||||
.execute('trace_rawTransaction', inData(data), inTraceType(whatTrace))
|
||||
.then(outTraceReplay);
|
||||
}
|
||||
|
||||
replayTransaction (txHash, whatTrace = ['trace']) {
|
||||
return this._transport
|
||||
.execute('trace_replayTransaction', txHash, inTraceType(whatTrace))
|
||||
.then(outTraceReplay);
|
||||
}
|
||||
|
||||
transaction (txHash) {
|
||||
return this._transport
|
||||
.execute('trace_transaction', inHex(txHash))
|
||||
.then(traces => traces.map(trace => outTrace(trace)));
|
||||
}
|
||||
|
||||
block (blockNumber = 'latest') {
|
||||
return this._transport
|
||||
.execute('trace_block', inBlockNumber(blockNumber))
|
||||
.then(traces => traces.map(trace => outTrace(trace)));
|
||||
.then(outTraces);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user