Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Use trace API for decentralized transaction list #2784

Merged
merged 6 commits into from
Oct 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions js/src/api/format/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,24 @@ export function inOptions (options) {

return options;
}

export function inTraceFilter (filterObject) {
if (filterObject) {
Object.keys(filterObject).forEach((key) => {
switch (key) {
case 'fromAddress':
case 'toAddress':
filterObject[key] = [].concat(filterObject[key])
.map(address => inAddress(address));
break;

case 'toBlock':
case 'fromBlock':
filterObject[key] = inBlockNumber(filterObject[key]);
break;
}
});
}

return filterObject;
}
4 changes: 2 additions & 2 deletions js/src/api/rpc/trace/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// 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 } from '../../format/input';
import { inBlockNumber, inHex, inNumber16, inTraceFilter } from '../../format/input';
import { outTrace } from '../../format/output';

export default class Trace {
Expand All @@ -24,7 +24,7 @@ export default class Trace {

filter (filterObj) {
return this._transport
.execute('trace_filter', filterObj)
.execute('trace_filter', inTraceFilter(filterObj))
.then(traces => traces.map(trace => outTrace(trace)));
}

Expand Down
3 changes: 3 additions & 0 deletions js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import { initStore } from './redux';
import { ContextProvider, muiTheme } from './ui';
import { Accounts, Account, Addresses, Address, Application, Contract, Contracts, Dapp, Dapps, Settings, SettingsBackground, SettingsProxy, SettingsViews, Signer, Status } from './views';

import { setApi } from './redux/providers/apiActions';

import './environment';

import '../assets/fonts/Roboto/font.css';
Expand All @@ -60,6 +62,7 @@ ContractInstances.create(api);

const store = initStore(api);
store.dispatch({ type: 'initAll', api });
store.dispatch(setApi(api));

const routerHistory = useRouterHistory(createHashHistory)({});

Expand Down
3 changes: 2 additions & 1 deletion js/src/redux/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import thunk from 'redux-thunk';

import ErrorsMiddleware from '../ui/Errors/middleware';
import SettingsMiddleware from '../views/Settings/middleware';
Expand All @@ -32,5 +33,5 @@ export default function (api) {
errors.toMiddleware()
];

return middleware.concat(status);
return middleware.concat(status, thunk);
}
22 changes: 22 additions & 0 deletions js/src/redux/providers/apiActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

export function setApi (api) {
return {
type: 'setApi',
api
};
}
26 changes: 26 additions & 0 deletions js/src/redux/providers/apiReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import { handleActions } from 'redux-actions';

const initialState = {};

export default handleActions({
setApi (state, action) {
const { api } = action;
return api;
}
}, initialState);
128 changes: 128 additions & 0 deletions js/src/redux/providers/blockchainActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import Contracts from '../../contracts';

export function setBlock (blockNumber, block) {
return {
type: 'setBlock',
blockNumber, block
};
}

export function setTransaction (txHash, info) {
return {
type: 'setTransaction',
txHash, info
};
}

export function setBytecode (address, bytecode) {
return {
type: 'setBytecode',
address, bytecode
};
}

export function setMethod (signature, method) {
return {
type: 'setMethod',
signature, method
};
}

export function fetchBlock (blockNumber) {
return (dispatch, getState) => {
const { blocks } = getState().blockchain;

if (blocks[blockNumber.toString()]) {
return;
}

const { api } = getState();

api.eth
.getBlockByNumber(blockNumber)
.then(block => {
dispatch(setBlock(blockNumber, block));
})
.catch(e => {
console.error('blockchain::fetchBlock', e);
});
};
}

export function fetchTransaction (txHash) {
return (dispatch, getState) => {
const { transactions } = getState().blockchain;

if (transactions[txHash]) {
return;
}

const { api } = getState();

api.eth
.getTransactionByHash(txHash)
.then(info => {
dispatch(setTransaction(txHash, info));
})
.catch(e => {
console.error('blockchain::fetchTransaction', e);
});
};
}

export function fetchBytecode (address) {
return (dispatch, getState) => {
const { bytecodes } = getState().blockchain;

if (bytecodes[address]) {
return;
}

const { api } = getState();

api.eth
.getCode(address)
.then(code => {
dispatch(setBytecode(address, code));
})
.catch(e => {
console.error('blockchain::fetchBytecode', e);
});
};
}

export function fetchMethod (signature) {
return (dispatch, getState) => {
const { methods } = getState().blockchain;

if (methods[signature]) {
return;
}

Contracts
.get()
.signatureReg.lookup(signature)
.then(method => {
dispatch(setMethod(signature, method));
})
.catch(e => {
console.error('blockchain::fetchMethod', e);
});
};
}
66 changes: 66 additions & 0 deletions js/src/redux/providers/blockchainReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import { handleActions } from 'redux-actions';

const initialState = {
blocks: {},
transactions: {},
bytecodes: {},
methods: {}
};

export default handleActions({
setBlock (state, action) {
const { blockNumber, block } = action;

const blocks = Object.assign({}, state.blocks, {
[blockNumber.toString()]: block
});

return Object.assign({}, state, { blocks });
},

setTransaction (state, action) {
const { txHash, info } = action;

const transactions = Object.assign({}, state.transactions, {
[txHash]: info
});

return Object.assign({}, state, { transactions });
},

setBytecode (state, action) {
const { address, bytecode } = action;

const bytecodes = Object.assign({}, state.bytecodes, {
[address]: bytecode
});

return Object.assign({}, state, { bytecodes });
},

setMethod (state, action) {
const { signature, method } = action;

const methods = Object.assign({}, state.methods, {
[signature]: method
});

return Object.assign({}, state, { methods });
}
}, initialState);
2 changes: 2 additions & 0 deletions js/src/redux/providers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ export Personal from './personal';
export Signer from './signer';
export Status from './status';

export apiReducer from './apiReducer';
export balancesReducer from './balancesReducer';
export imagesReducer from './imagesReducer';
export personalReducer from './personalReducer';
export signerReducer from './signerReducer';
export statusReducer from './statusReducer';
export blockchainReducer from './blockchainReducer';
18 changes: 15 additions & 3 deletions js/src/redux/providers/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ export default class Status {
.catch(() => dispatch(false));
}

_pollTraceMode = () => {
return this._api.trace.block()
.then(blockTraces => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently miners mine 0 tx's in a block on purpose, not sure this is correct...

// Assumes not in Trace Mode if no transactions
// in latest block...
return blockTraces.length > 0;
})
.catch(() => false);
}

_pollStatus = () => {
const { secureToken, isConnected, isConnecting, needsToken } = this._api;
const nextTimeout = (timeout = 1000) => {
Expand All @@ -80,9 +90,10 @@ export default class Status {
this._api.ethcore.netPort(),
this._api.ethcore.nodeName(),
this._api.ethcore.rpcSettings(),
this._api.eth.syncing()
this._api.eth.syncing(),
this._pollTraceMode()
])
.then(([clientVersion, coinbase, defaultExtraData, extraData, gasFloorTarget, hashrate, minGasPrice, netChain, netPeers, netPort, nodeName, rpcSettings, syncing]) => {
.then(([clientVersion, coinbase, defaultExtraData, extraData, gasFloorTarget, hashrate, minGasPrice, netChain, netPeers, netPort, nodeName, rpcSettings, syncing, traceMode]) => {
const isTest = netChain === 'morden' || netChain === 'testnet';

this._store.dispatch(statusCollection({
Expand All @@ -99,7 +110,8 @@ export default class Status {
nodeName,
rpcSettings,
syncing,
isTest
isTest,
traceMode
}));
nextTimeout();
})
Expand Down
3 changes: 2 additions & 1 deletion js/src/redux/providers/statusReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ const initialState = {
syncing: false,
isApiConnected: true,
isPingConnected: true,
isTest: true
isTest: false,
traceMode: undefined
};

export default handleActions({
Expand Down
Loading