Merge branch 'master' into jg-container-title

This commit is contained in:
Jaco Greeff 2016-11-29 13:54:30 +01:00
commit 907606ab69
34 changed files with 556 additions and 379 deletions

View File

@ -17,6 +17,7 @@
use endpoint::EndpointInfo; use endpoint::EndpointInfo;
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)] #[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct App { pub struct App {
pub id: String, pub id: String,
pub name: String, pub name: String,
@ -54,6 +55,7 @@ impl Into<EndpointInfo> for App {
} }
#[derive(Debug, PartialEq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct ApiError { pub struct ApiError {
pub code: String, pub code: String,
pub title: String, pub title: String,

View File

@ -3,6 +3,7 @@ WORKDIR /build
# install tools and dependencies # install tools and dependencies
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y \ apt-get install -y \
build-essential \
g++ \ g++ \
curl \ curl \
git \ git \

View File

@ -4,6 +4,7 @@ WORKDIR /build
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y \ apt-get install -y \
g++ \ g++ \
build-essential \
curl \ curl \
git \ git \
file \ file \

View File

@ -128,7 +128,7 @@ export default class DeployContract extends Component {
title={ title } title={ title }
waiting={ waiting } waiting={ waiting }
visible visible
scroll> >
{ this.renderStep() } { this.renderStep() }
</Modal> </Modal>
); );

View File

@ -62,7 +62,6 @@ export default class LoadContract extends Component {
title={ title } title={ title }
actions={ this.renderDialogActions() } actions={ this.renderDialogActions() }
visible visible
scroll
> >
{ this.renderBody() } { this.renderBody() }
</Modal> </Modal>

View File

@ -61,7 +61,7 @@ export default class SMSVerification extends Component {
<Modal <Modal
actions={ this.renderDialogActions(phase, error, isStepValid) } actions={ this.renderDialogActions(phase, error, isStepValid) }
title='verify your account via SMS' title='verify your account via SMS'
visible scroll visible
current={ phase } current={ phase }
steps={ ['Prepare', 'Enter Data', 'Request', 'Enter Code', 'Confirm', 'Done!'] } steps={ ['Prepare', 'Enter Data', 'Request', 'Enter Code', 'Confirm', 'Done!'] }
waiting={ error ? [] : [ 0, 2, 4 ] } waiting={ error ? [] : [ 0, 2, 4 ] }

View File

@ -104,7 +104,6 @@ class Transfer extends Component {
steps={ steps } steps={ steps }
waiting={ extras ? [2] : [1] } waiting={ extras ? [2] : [1] }
visible visible
scroll
> >
{ this.renderWarning() } { this.renderWarning() }
{ this.renderPage() } { this.renderPage() }

View File

@ -17,6 +17,8 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { Card } from 'material-ui/Card'; import { Card } from 'material-ui/Card';
import Title from './Title';
import styles from './container.css'; import styles from './container.css';
export default class Container extends Component { export default class Container extends Component {
@ -25,7 +27,10 @@ export default class Container extends Component {
className: PropTypes.string, className: PropTypes.string,
compact: PropTypes.bool, compact: PropTypes.bool,
light: PropTypes.bool, light: PropTypes.bool,
style: PropTypes.object style: PropTypes.object,
title: PropTypes.oneOfType([
PropTypes.string, PropTypes.node
])
} }
render () { render () {
@ -35,9 +40,22 @@ export default class Container extends Component {
return ( return (
<div className={ classes } style={ style }> <div className={ classes } style={ style }>
<Card className={ compact ? styles.compact : styles.padded }> <Card className={ compact ? styles.compact : styles.padded }>
{ this.renderTitle() }
{ children } { children }
</Card> </Card>
</div> </div>
); );
} }
renderTitle () {
const { title } = this.props;
if (!title) {
return null;
}
return (
<Title title={ title } />
);
}
} }

View File

@ -41,7 +41,6 @@ class Modal extends Component {
compact: PropTypes.bool, compact: PropTypes.bool,
current: PropTypes.number, current: PropTypes.number,
waiting: PropTypes.array, waiting: PropTypes.array,
scroll: PropTypes.bool,
steps: PropTypes.array, steps: PropTypes.array,
title: PropTypes.oneOfType([ title: PropTypes.oneOfType([
PropTypes.node, PropTypes.string PropTypes.node, PropTypes.string
@ -52,7 +51,7 @@ class Modal extends Component {
render () { render () {
const { muiTheme } = this.context; const { muiTheme } = this.context;
const { actions, busy, className, current, children, compact, scroll, steps, waiting, title, visible, settings } = this.props; const { actions, busy, className, current, children, compact, steps, waiting, title, visible, settings } = this.props;
const contentStyle = muiTheme.parity.getBackgroundStyle(null, settings.backgroundSeed); const contentStyle = muiTheme.parity.getBackgroundStyle(null, settings.backgroundSeed);
const header = ( const header = (
<Title <Title
@ -70,7 +69,7 @@ class Modal extends Component {
actions={ actions } actions={ actions }
actionsContainerStyle={ ACTIONS_STYLE } actionsContainerStyle={ ACTIONS_STYLE }
autoDetectWindowHeight={ false } autoDetectWindowHeight={ false }
autoScrollBodyContent={ !!scroll } autoScrollBodyContent
actionsContainerClassName={ styles.actions } actionsContainerClassName={ styles.actions }
bodyClassName={ styles.body } bodyClassName={ styles.body }
contentClassName={ styles.content } contentClassName={ styles.content }

View File

@ -14,4 +14,4 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
export default from './transaction'; export default from './txList';

131
js/src/ui/TxList/store.js Normal file
View File

@ -0,0 +1,131 @@
// 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 { action, observable, transaction } from 'mobx';
import { uniq } from 'lodash';
export default class Store {
@observable blocks = {};
@observable sortedHashes = [];
@observable transactions = {};
constructor (api) {
this._api = api;
this._subscriptionId = 0;
this._pendingHashes = [];
this.subscribe();
}
@action addBlocks = (blocks) => {
this.blocks = Object.assign({}, this.blocks, blocks);
}
@action addTransactions = (transactions) => {
transaction(() => {
this.transactions = Object.assign({}, this.transactions, transactions);
this.sortedHashes = Object
.keys(this.transactions)
.sort((ahash, bhash) => {
const bnA = this.transactions[ahash].blockNumber;
const bnB = this.transactions[bhash].blockNumber;
if (bnB.eq(0)) {
return bnB.eq(bnA) ? 0 : 1;
}
return bnB.comparedTo(bnA);
});
this._pendingHashes = this.sortedHashes.filter((hash) => this.transactions[hash].blockNumber.eq(0));
});
}
@action clearPending () {
this._pendingHashes = [];
}
subscribe () {
this._api
.subscribe('eth_blockNumber', (error, blockNumber) => {
if (error) {
return;
}
if (this._pendingHashes.length) {
this.loadTransactions(this._pendingHashes);
this.clearPending();
}
})
.then((subscriptionId) => {
this._subscriptionId = subscriptionId;
});
}
unsubscribe () {
if (!this._subscriptionId) {
return;
}
this._api.unsubscribe(this._subscriptionId);
this._subscriptionId = 0;
}
loadTransactions (_txhashes) {
const txhashes = _txhashes.filter((hash) => !this.transactions[hash] || this._pendingHashes.includes(hash));
if (!txhashes || !txhashes.length) {
return;
}
Promise
.all(txhashes.map((txhash) => this._api.eth.getTransactionByHash(txhash)))
.then((transactions) => {
this.addTransactions(
transactions.reduce((transactions, tx, index) => {
transactions[txhashes[index]] = tx;
return transactions;
}, {})
);
this.loadBlocks(transactions.map((tx) => tx.blockNumber ? tx.blockNumber.toNumber() : 0));
})
.catch((error) => {
console.warn('loadTransactions', error);
});
}
loadBlocks (_blockNumbers) {
const blockNumbers = uniq(_blockNumbers).filter((bn) => !this.blocks[bn]);
if (!blockNumbers || !blockNumbers.length) {
return;
}
Promise
.all(blockNumbers.map((blockNumber) => this._api.eth.getBlockByNumber(blockNumber)))
.then((blocks) => {
this.addBlocks(
blocks.reduce((blocks, block, index) => {
blocks[blockNumbers[index]] = block;
return blocks;
}, {})
);
})
.catch((error) => {
console.warn('loadBlocks', error);
});
}
}

View File

@ -0,0 +1,81 @@
/* 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/>.
*/
.transactions {
width: 100%;
border-collapse: collapse;
tr {
line-height: 32px;
vertical-align: top;
&:nth-child(even) {
background: rgba(255, 255, 255, 0.04);
}
}
th {
color: #aaa;
text-align: center;
}
td {
vertical-align: top;
padding: 0.75em 0.75em;
&.method {
width: 40%;
}
&.timestamp {
padding-top: 1.5em;
text-align: right;
line-height: 1.5em;
opacity: 0.5;
}
&.transaction {
padding-top: 1.5em;
text-align: center;
& div {
line-height: 1.25em;
min-height: 1.25em;
}
}
}
.icon {
margin: 0;
}
.link {
vertical-align: top;
}
.right {
text-align: right;
}
.center {
text-align: center;
}
.left {
text-align: left;
}
}

178
js/src/ui/TxList/txList.js Normal file
View File

@ -0,0 +1,178 @@
// 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 moment from 'moment';
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { observer } from 'mobx-react';
import { txLink, addressLink } from '../../3rdparty/etherscan/links';
import IdentityIcon from '../IdentityIcon';
import IdentityName from '../IdentityName';
import MethodDecoding from '../MethodDecoding';
import Store from './store';
import styles from './txList.css';
@observer
class TxList extends Component {
static contextTypes = {
api: PropTypes.object.isRequired
}
static propTypes = {
address: PropTypes.string.isRequired,
hashes: PropTypes.oneOfType([
PropTypes.array,
PropTypes.object
]).isRequired,
isTest: PropTypes.bool.isRequired
}
store = new Store(this.context.api);
componentWillMount () {
this.store.loadTransactions(this.props.hashes);
}
componentWillUnmount () {
this.store.unsubscribe();
}
componentWillReceiveProps (newProps) {
this.store.loadTransactions(newProps.hashes);
}
render () {
return (
<table className={ styles.transactions }>
<tbody>
{ this.renderRows() }
</tbody>
</table>
);
}
renderRows () {
const { address, isTest } = this.props;
return this.store.sortedHashes.map((txhash) => {
const tx = this.store.transactions[txhash];
return (
<tr key={ tx.hash }>
{ this.renderBlockNumber(tx.blockNumber) }
{ this.renderAddress(tx.from) }
<td className={ styles.transaction }>
{ this.renderEtherValue(tx.value) }
<div></div>
<div>
<a
className={ styles.link }
href={ txLink(tx.hash, isTest) }
target='_blank'>
{ `${tx.hash.substr(2, 6)}...${tx.hash.slice(-6)}` }
</a>
</div>
</td>
{ this.renderAddress(tx.to) }
<td className={ styles.method }>
<MethodDecoding
historic
address={ address }
transaction={ tx } />
</td>
</tr>
);
});
}
renderAddress (address) {
const { isTest } = this.props;
let esLink = null;
if (address) {
esLink = (
<a
href={ addressLink(address, isTest) }
target='_blank'
className={ styles.link }>
<IdentityName address={ address } shorten />
</a>
);
}
return (
<td className={ styles.address }>
<div className={ styles.center }>
<IdentityIcon
center
className={ styles.icon }
address={ address } />
</div>
<div className={ styles.center }>
{ esLink || 'DEPLOY' }
</div>
</td>
);
}
renderEtherValue (_value) {
const { api } = this.context;
const value = api.util.fromWei(_value);
if (value.eq(0)) {
return <div className={ styles.value }>{ ' ' }</div>;
}
return (
<div className={ styles.value }>
{ value.toFormat(5) }<small>ETH</small>
</div>
);
}
renderBlockNumber (_blockNumber) {
const blockNumber = _blockNumber.toNumber();
const block = this.store.blocks[blockNumber];
return (
<td className={ styles.timestamp }>
<div>{ blockNumber && block ? moment(block.timestamp).fromNow() : null }</div>
<div>{ blockNumber ? _blockNumber.toFormat() : 'Pending' }</div>
</td>
);
}
}
function mapStateToProps (state) {
const { isTest } = state.nodeStatus;
return {
isTest
};
}
function mapDispatchToProps (dispatch) {
return bindActionCreators({}, dispatch);
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(TxList);

View File

@ -42,6 +42,7 @@ import SignerIcon from './SignerIcon';
import Tags from './Tags'; import Tags from './Tags';
import Tooltips, { Tooltip } from './Tooltips'; import Tooltips, { Tooltip } from './Tooltips';
import TxHash from './TxHash'; import TxHash from './TxHash';
import TxList from './TxList';
export { export {
Actionbar, Actionbar,
@ -85,5 +86,6 @@ export {
Tags, Tags,
Tooltip, Tooltip,
Tooltips, Tooltips,
TxHash TxHash,
TxList
}; };

View File

@ -1,184 +0,0 @@
// 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 BigNumber from 'bignumber.js';
import React, { Component, PropTypes } from 'react';
import moment from 'moment';
import { IdentityIcon, IdentityName, MethodDecoding } from '../../../../ui';
import ShortenedHash from '../../../../ui/ShortenedHash';
import { txLink, addressLink } from '../../../../3rdparty/etherscan/links';
import styles from '../transactions.css';
export default class Transaction extends Component {
static contextTypes = {
api: PropTypes.object.isRequired
}
static propTypes = {
address: PropTypes.string.isRequired,
isTest: PropTypes.bool.isRequired,
transaction: PropTypes.object.isRequired
}
state = {
isContract: false,
isReceived: false,
transaction: null,
block: null
}
componentDidMount () {
this.lookup();
}
render () {
const { block } = this.state;
const { transaction } = this.props;
return (
<tr>
<td className={ styles.timestamp }>
<div>{ this.formatBlockTimestamp(block) }</div>
<div>{ this.formatNumber(transaction.blockNumber) }</div>
</td>
{ this.renderAddress(transaction.from) }
{ this.renderTransaction() }
{ this.renderAddress(transaction.to) }
<td className={ styles.method }>
{ this.renderMethod() }
</td>
</tr>
);
}
renderMethod () {
const { address } = this.props;
const { transaction } = this.state;
if (!transaction) {
return null;
}
return (
<MethodDecoding
historic
address={ address }
transaction={ transaction } />
);
}
renderTransaction () {
const { isTest } = this.props;
const { transaction } = this.props;
return (
<td className={ styles.transaction }>
{ this.renderEtherValue() }
<div></div>
<div>
<a
className={ styles.link }
href={ txLink(transaction.hash, isTest) }
target='_blank'
>
<ShortenedHash data={ transaction.hash } />
</a>
</div>
</td>
);
}
renderAddress (address) {
const { isTest } = this.props;
const eslink = address ? (
<a
href={ addressLink(address, isTest) }
target='_blank'
className={ styles.link }>
<IdentityName address={ address } shorten />
</a>
) : 'DEPLOY';
return (
<td className={ styles.address }>
<div className={ styles.center }>
<IdentityIcon
center
className={ styles.icon }
address={ address } />
</div>
<div className={ styles.center }>
{ eslink }
</div>
</td>
);
}
renderEtherValue () {
const { api } = this.context;
const { transaction } = this.state;
if (!transaction) {
return null;
}
const value = api.util.fromWei(transaction.value);
if (value.eq(0)) {
return <div className={ styles.value }>{ ' ' }</div>;
}
return (
<div className={ styles.value }>
{ value.toFormat(5) }<small>ETH</small>
</div>
);
}
formatNumber (number) {
return new BigNumber(number).toFormat();
}
formatBlockTimestamp (block) {
if (!block) {
return null;
}
return moment(block.timestamp).fromNow();
}
lookup () {
const { api } = this.context;
const { transaction, address } = this.props;
this.setState({ isReceived: address === transaction.to });
Promise
.all([
api.eth.getBlockByNumber(transaction.blockNumber),
api.eth.getTransactionByHash(transaction.hash)
])
.then(([block, transaction]) => {
this.setState({ block, transaction });
})
.catch((error) => {
console.warn('lookup', error);
});
}
}

View File

@ -14,49 +14,10 @@
/* You should have received a copy of the GNU General Public License /* You should have received a copy of the GNU General Public License
/* along with Parity. If not, see <http://www.gnu.org/licenses/>. /* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/ */
.right {
text-align: right;
}
.center {
text-align: center;
}
.left {
text-align: left;
}
.transactions { .transactions {
} }
.transactions table {
width: 100%;
border-collapse: collapse;
}
.transactions tr {
line-height: 32px;
vertical-align: top;
}
.transactions tr:nth-child(even) {
background: rgba(255, 255, 255, 0.04);
}
.transactions th {
color: #aaa;
text-align: center;
}
.transactions td {
vertical-align: top;
padding: 0.75em 0.75em;
}
.transactions .link {
vertical-align: top;
}
.infonone { .infonone {
opacity: 0.25; opacity: 0.25;
} }
@ -67,35 +28,3 @@
font-size: 0.75em; font-size: 0.75em;
color: #aaa; color: #aaa;
} }
.address {
text-align: center;
}
.transaction {
text-align: center;
}
.transactions td.transaction {
padding-top: 1.5em;
}
.transaction div {
line-height: 1.25em;
min-height: 1.25em;
}
.icon {
margin: 0;
}
.method {
width: 40%;
}
.transactions td.timestamp {
padding-top: 1.5em;
text-align: right;
line-height: 1.5em;
opacity: 0.5;
}

View File

@ -17,12 +17,9 @@
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import LinearProgress from 'material-ui/LinearProgress';
import etherscan from '../../../3rdparty/etherscan'; import etherscan from '../../../3rdparty/etherscan';
import { Container, ContainerTitle } from '../../../ui'; import { Container, TxList } from '../../../ui';
import Transaction from './Transaction';
import styles from './transactions.css'; import styles from './transactions.css';
@ -33,16 +30,12 @@ class Transactions extends Component {
static propTypes = { static propTypes = {
address: PropTypes.string.isRequired, address: PropTypes.string.isRequired,
accounts: PropTypes.object,
contacts: PropTypes.object,
contracts: PropTypes.object,
tokens: PropTypes.object,
isTest: PropTypes.bool, isTest: PropTypes.bool,
traceMode: PropTypes.bool traceMode: PropTypes.bool
} }
state = { state = {
transactions: [], hashes: [],
loading: true, loading: true,
callInfo: {} callInfo: {}
} }
@ -67,38 +60,16 @@ class Transactions extends Component {
} }
render () { render () {
return ( const { address } = this.props;
<Container> const { hashes } = this.state;
<ContainerTitle title='transactions' />
{ this.renderTransactions() }
</Container>
);
}
renderTransactions () {
const { loading, transactions } = this.state;
if (loading) {
return (
<LinearProgress mode='indeterminate' />
);
} else if (!transactions.length) {
return (
<div className={ styles.infonone }>
No transactions were found for this account
</div>
);
}
return ( return (
<div className={ styles.transactions }> <Container title='transactions'>
<table> <TxList
<tbody> address={ address }
{ this.renderRows() } hashes={ hashes } />
</tbody>
</table>
{ this.renderEtherscanFooter() } { this.renderEtherscanFooter() }
</div> </Container>
); );
} }
@ -116,30 +87,6 @@ class Transactions extends Component {
); );
} }
renderRows () {
const { address, accounts, contacts, contracts, tokens, isTest } = this.props;
const { transactions } = this.state;
return (transactions || [])
.sort((tA, tB) => {
return tB.blockNumber.comparedTo(tA.blockNumber);
})
.slice(0, 25)
.map((transaction, index) => {
return (
<Transaction
key={ index }
transaction={ transaction }
address={ address }
accounts={ accounts }
contacts={ contacts }
contracts={ contracts }
tokens={ tokens }
isTest={ isTest } />
);
});
}
getTransactions = (props) => { getTransactions = (props) => {
const { isTest, address, traceMode } = props; const { isTest, address, traceMode } = props;
@ -151,9 +98,9 @@ class Transactions extends Component {
return this return this
.fetchTransactions(isTest, address, traceMode) .fetchTransactions(isTest, address, traceMode)
.then(transactions => { .then((transactions) => {
this.setState({ this.setState({
transactions, hashes: transactions.map((transaction) => transaction.hash),
loading: false loading: false
}); });
}); });
@ -204,16 +151,10 @@ class Transactions extends Component {
function mapStateToProps (state) { function mapStateToProps (state) {
const { isTest, traceMode } = state.nodeStatus; const { isTest, traceMode } = state.nodeStatus;
const { accounts, contacts, contracts } = state.personal;
const { tokens } = state.balances;
return { return {
isTest, isTest,
traceMode, traceMode
accounts,
contacts,
contracts,
tokens
}; };
} }

View File

@ -165,7 +165,6 @@ class Contract extends Component {
actions={ [ cancelBtn ] } actions={ [ cancelBtn ] }
title={ 'contract details' } title={ 'contract details' }
visible visible
scroll
> >
<div className={ styles.details }> <div className={ styles.details }>
{ this.renderSource(contract) } { this.renderSource(contract) }

View File

@ -50,7 +50,7 @@ export default class AddDapps extends Component {
/> />
] } ] }
visible visible
scroll> >
<div className={ styles.warning } /> <div className={ styles.warning } />
{ this.renderList(store.sortedLocal, 'Applications locally available', 'All applications installed locally on the machine by the user for access by the Parity client.') } { this.renderList(store.sortedLocal, 'Applications locally available', 'All applications installed locally on the machine by the user for access by the Parity client.') }
{ this.renderList(store.sortedBuiltin, 'Applications bundled with Parity', 'Experimental applications developed by the Parity team to show off dapp capabilities, integration, experimental features and to control certain network-wide client behaviour.') } { this.renderList(store.sortedBuiltin, 'Applications bundled with Parity', 'Experimental applications developed by the Parity team to show off dapp capabilities, integration, experimental features and to control certain network-wide client behaviour.') }

View File

@ -18,15 +18,17 @@ import BigNumber from 'bignumber.js';
import React, { Component, PropTypes } from 'react'; import React, { Component, PropTypes } from 'react';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { observer } from 'mobx-react';
import Store from '../../store'; import Store from '../../store';
import * as RequestsActions from '../../../../redux/providers/signerActions'; import * as RequestsActions from '../../../../redux/providers/signerActions';
import { Container, ContainerTitle } from '../../../../ui'; import { Container, Page, TxList } from '../../../../ui';
import { RequestPending, RequestFinished } from '../../components'; import { RequestPending, RequestFinished } from '../../components';
import styles from './RequestsPage.css'; import styles from './RequestsPage.css';
@observer
class RequestsPage extends Component { class RequestsPage extends Component {
static contextTypes = { static contextTypes = {
api: PropTypes.object.isRequired api: PropTypes.object.isRequired
@ -44,20 +46,19 @@ class RequestsPage extends Component {
isTest: PropTypes.bool.isRequired isTest: PropTypes.bool.isRequired
}; };
store = new Store(this.context.api); store = new Store(this.context.api, true);
componentWillUnmount () {
this.store.unsubscribe();
}
render () { render () {
const { pending, finished } = this.props.signer;
if (!pending.length && !finished.length) {
return this.renderNoRequestsMsg();
}
return ( return (
<div> <Page>
{ this.renderPendingRequests() } <div>{ this.renderPendingRequests() }</div>
{ this.renderFinishedRequests() } <div>{ this.renderLocalQueue() }</div>
</div> <div>{ this.renderFinishedRequests() }</div>
</Page>
); );
} }
@ -65,18 +66,39 @@ class RequestsPage extends Component {
return new BigNumber(b.id).cmp(a.id); return new BigNumber(b.id).cmp(a.id);
} }
renderLocalQueue () {
const { localHashes } = this.store;
if (!localHashes.length) {
return null;
}
return (
<Container title='Local Transactions'>
<TxList
address=''
hashes={ localHashes } />
</Container>
);
}
renderPendingRequests () { renderPendingRequests () {
const { pending } = this.props.signer; const { pending } = this.props.signer;
if (!pending.length) { if (!pending.length) {
return; return (
<Container>
<div className={ styles.noRequestsMsg }>
There are no requests requiring your confirmation.
</div>
</Container>
);
} }
const items = pending.sort(this._sortRequests).map(this.renderPending); const items = pending.sort(this._sortRequests).map(this.renderPending);
return ( return (
<Container> <Container title='Pending Requests'>
<ContainerTitle title='Pending Requests' />
<div className={ styles.items }> <div className={ styles.items }>
{ items } { items }
</div> </div>
@ -94,8 +116,7 @@ class RequestsPage extends Component {
const items = finished.sort(this._sortRequests).map(this.renderFinished); const items = finished.sort(this._sortRequests).map(this.renderFinished);
return ( return (
<Container> <Container title='Finished Requests'>
<ContainerTitle title='Finished Requests' />
<div className={ styles.items }> <div className={ styles.items }>
{ items } { items }
</div> </div>
@ -143,16 +164,6 @@ class RequestsPage extends Component {
/> />
); );
} }
renderNoRequestsMsg () {
return (
<Container>
<div className={ styles.noRequestsMsg }>
There are no requests requiring your confirmation.
</div>
</Container>
);
}
} }
function mapStateToProps (state) { function mapStateToProps (state) {

View File

@ -16,7 +16,7 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Actionbar, Page } from '../../ui'; import { Actionbar } from '../../ui';
import RequestsPage from './containers/RequestsPage'; import RequestsPage from './containers/RequestsPage';
import styles from './signer.css'; import styles from './signer.css';
@ -27,9 +27,7 @@ export default class Signer extends Component {
<div className={ styles.signer }> <div className={ styles.signer }>
<Actionbar <Actionbar
title='Trusted Signer' /> title='Trusted Signer' />
<Page> <RequestsPage />
<RequestsPage />
</Page>
</div> </div>
); );
} }

View File

@ -14,13 +14,26 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
import { isEqual } from 'lodash';
import { action, observable } from 'mobx'; import { action, observable } from 'mobx';
export default class Store { export default class Store {
@observable balances = {}; @observable balances = {};
@observable localHashes = [];
constructor (api) { constructor (api, withLocalTransactions = false) {
this._api = api; this._api = api;
this._timeoutId = 0;
if (withLocalTransactions) {
this.fetchLocalTransactions();
}
}
@action unsubscribe () {
if (this._timeoutId) {
clearTimeout(this._timeoutId);
}
} }
@action setBalance = (address, balance) => { @action setBalance = (address, balance) => {
@ -31,6 +44,12 @@ export default class Store {
this.balances = Object.assign({}, this.balances, balances); this.balances = Object.assign({}, this.balances, balances);
} }
@action setLocalHashes = (localHashes) => {
if (!isEqual(localHashes, this.localHashes)) {
this.localHashes = localHashes;
}
}
fetchBalance (address) { fetchBalance (address) {
this._api.eth this._api.eth
.getBalance(address) .getBalance(address)
@ -63,4 +82,18 @@ export default class Store {
console.warn('Store:fetchBalances', error); console.warn('Store:fetchBalances', error);
}); });
} }
fetchLocalTransactions = () => {
const nextTimeout = () => {
this._timeoutId = setTimeout(this.fetchLocalTransactions, 1500);
};
this._api.parity
.localTransactions()
.then((localTransactions) => {
this.setLocalHashes(Object.keys(localTransactions));
})
.then(nextTimeout)
.catch(nextTimeout);
}
} }

View File

@ -0,0 +1,3 @@
[signer]
passwd = []

View File

@ -649,11 +649,12 @@ mod tests {
fn should_parse_config_and_return_errors() { fn should_parse_config_and_return_errors() {
let config1 = Args::parse_config(include_str!("./config.invalid1.toml")); let config1 = Args::parse_config(include_str!("./config.invalid1.toml"));
let config2 = Args::parse_config(include_str!("./config.invalid2.toml")); let config2 = Args::parse_config(include_str!("./config.invalid2.toml"));
let config3 = Args::parse_config(include_str!("./config.invalid3.toml"));
match (config1, config2) { match (config1, config2, config3) {
(Err(ArgsError::Parsing(_)), Err(ArgsError::Decode(_))) => {}, (Err(ArgsError::Parsing(_)), Err(ArgsError::Decode(_)), Err(ArgsError::UnknownFields(_))) => {},
(a, b) => { (a, b, c) => {
assert!(false, "Got invalid error types: {:?}, {:?}", a, b); assert!(false, "Got invalid error types: {:?}, {:?}, {:?}", a, b, c);
} }
} }
} }

View File

@ -58,6 +58,7 @@ macro_rules! usage {
Parsing(Vec<toml::ParserError>), Parsing(Vec<toml::ParserError>),
Decode(toml::DecodeError), Decode(toml::DecodeError),
Config(String, io::Error), Config(String, io::Error),
UnknownFields(String),
} }
impl ArgsError { impl ArgsError {
@ -80,6 +81,11 @@ macro_rules! usage {
println_stderr!("There was an error reading your config file at: {}", path); println_stderr!("There was an error reading your config file at: {}", path);
println_stderr!("{}", e); println_stderr!("{}", e);
process::exit(2) process::exit(2)
},
ArgsError::UnknownFields(fields) => {
println_stderr!("You have some extra fields in your config file:");
println_stderr!("{}", fields);
process::exit(2)
} }
} }
} }
@ -173,10 +179,13 @@ macro_rules! usage {
let mut value_parser = toml::Parser::new(&config); let mut value_parser = toml::Parser::new(&config);
match value_parser.parse() { match value_parser.parse() {
Some(value) => { Some(value) => {
let result = rustc_serialize::Decodable::decode(&mut toml::Decoder::new(toml::Value::Table(value))); let mut decoder = toml::Decoder::new(toml::Value::Table(value));
match result { let result = rustc_serialize::Decodable::decode(&mut decoder);
Ok(config) => Ok(config),
Err(e) => Err(e.into()), match (result, decoder.toml) {
(Err(e), _) => Err(e.into()),
(_, Some(toml)) => Err(ArgsError::UnknownFields(toml::encode_str(&toml))),
(Ok(config), None) => Ok(config),
} }
}, },
None => Err(ArgsError::Parsing(value_parser.errors)), None => Err(ArgsError::Parsing(value_parser.errors)),

View File

@ -19,6 +19,7 @@ use v1::types::{Bytes, H160, U256};
/// Call request /// Call request
#[derive(Debug, Default, PartialEq, Deserialize)] #[derive(Debug, Default, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct CallRequest { pub struct CallRequest {
/// From /// From
pub from: Option<H160>, pub from: Option<H160>,

View File

@ -137,6 +137,7 @@ impl From<helpers::ConfirmationPayload> for ConfirmationPayload {
/// Possible modifications to the confirmed transaction sent by `Trusted Signer` /// Possible modifications to the confirmed transaction sent by `Trusted Signer`
#[derive(Debug, PartialEq, Deserialize)] #[derive(Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct TransactionModification { pub struct TransactionModification {
/// Modified gas price /// Modified gas price
#[serde(rename="gasPrice")] #[serde(rename="gasPrice")]

View File

@ -21,6 +21,7 @@ use util::stats;
/// Values of RPC settings. /// Values of RPC settings.
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Histogram { pub struct Histogram {
/// Gas prices for bucket edges. /// Gas prices for bucket edges.
#[serde(rename="bucketBounds")] #[serde(rename="bucketBounds")]

View File

@ -18,6 +18,7 @@
/// Values of RPC settings. /// Values of RPC settings.
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct RpcSettings { pub struct RpcSettings {
/// Whether RPC is enabled. /// Whether RPC is enabled.
pub enabled: bool, pub enabled: bool,
@ -25,4 +26,4 @@ pub struct RpcSettings {
pub interface: String, pub interface: String,
/// The port being listened on. /// The port being listened on.
pub port: u64, pub port: u64,
} }

View File

@ -22,6 +22,7 @@ use v1::types::{BlockNumber, H160};
/// Trace filter /// Trace filter
#[derive(Debug, PartialEq, Deserialize)] #[derive(Debug, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct TraceFilter { pub struct TraceFilter {
/// From block /// From block
#[serde(rename="fromBlock")] #[serde(rename="fromBlock")]

View File

@ -21,6 +21,7 @@ use v1::helpers;
/// Transaction request coming from RPC /// Transaction request coming from RPC
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)] #[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct TransactionRequest { pub struct TransactionRequest {
/// Sender /// Sender
pub from: H160, pub from: H160,

View File

@ -258,6 +258,12 @@ impl BlockDownloader {
self.blocks.reset_to(hashes); self.blocks.reset_to(hashes);
self.state = State::Blocks; self.state = State::Blocks;
return Ok(DownloadAction::Reset); return Ok(DownloadAction::Reset);
} else {
let best = io.chain().chain_info().best_block_number;
if best > self.last_imported_block && best - self.last_imported_block > MAX_REORG_BLOCKS {
trace!(target: "sync", "No common block, disabling peer");
return Err(BlockDownloaderImportError::Invalid);
}
} }
}, },
State::Blocks => { State::Blocks => {

View File

@ -250,3 +250,14 @@ fn high_td_attach() {
assert_eq!(net.peer(0).chain.chain_info().best_block_number, 5); assert_eq!(net.peer(0).chain.chain_info().best_block_number, 5);
} }
#[test]
fn disconnect_on_unrelated_chain() {
::env_logger::init().ok();
let mut net = TestNet::new(2);
net.peer_mut(0).chain.add_blocks(200, EachBlockWith::Uncle);
net.peer_mut(1).chain.add_blocks(100, EachBlockWith::Nothing);
net.sync();
assert_eq!(net.disconnect_events, vec![(0, 0)]);
}

View File

@ -123,6 +123,7 @@ pub struct TestPeer {
pub struct TestNet { pub struct TestNet {
pub peers: Vec<TestPeer>, pub peers: Vec<TestPeer>,
pub started: bool, pub started: bool,
pub disconnect_events: Vec<(PeerId, PeerId)>, //disconnected (initiated by, to)
} }
impl TestNet { impl TestNet {
@ -140,6 +141,7 @@ impl TestNet {
let mut net = TestNet { let mut net = TestNet {
peers: Vec::new(), peers: Vec::new(),
started: false, started: false,
disconnect_events: Vec::new(),
}; };
for _ in 0..n { for _ in 0..n {
let chain = TestBlockChainClient::new(); let chain = TestBlockChainClient::new();
@ -190,6 +192,7 @@ impl TestNet {
// notify this that disconnecting peers are disconnecting // notify this that disconnecting peers are disconnecting
let mut io = TestIo::new(&mut p.chain, &p.snapshot_service, &mut p.queue, Some(*d)); let mut io = TestIo::new(&mut p.chain, &p.snapshot_service, &mut p.queue, Some(*d));
p.sync.write().on_peer_aborting(&mut io, *d); p.sync.write().on_peer_aborting(&mut io, *d);
self.disconnect_events.push((peer, *d));
} }
to_disconnect to_disconnect
}; };