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

Use enode RPC in UI #3108

Merged
merged 6 commits into from
Nov 3, 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
5 changes: 5 additions & 0 deletions js/src/api/rpc/ethcore/ethcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export default class Ethcore {
.execute('ethcore_dropNonReservedPeers');
}

enode () {
return this._transport
.execute('ethcore_enode');
}

extraData () {
return this._transport
.execute('ethcore_extraData');
Expand Down
9 changes: 9 additions & 0 deletions js/src/jsonrpc/interfaces/ethcore.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ export default {
}
},

enode: {
desc: 'Returns the node enode URI',
params: [],
returns: {
type: String,
desc: 'Enode URI'
}
},

extraData: {
desc: 'Returns currently set extra data',
params: [],
Expand Down
20 changes: 20 additions & 0 deletions js/src/redux/providers/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ export default class Status {
this._pollPing();
this._pollStatus();
this._pollLogs();
this._fetchEnode();
}

_fetchEnode () {
this._api
.ethcore.enode()
.then((enode) => {
this._store.dispatch(statusCollection({ enode }));
})
.catch(() => {
window.setTimeout(() => {
this._fetchEnode();
}, 1000);
});
}

_subscribeBlockNumber () {
Expand Down Expand Up @@ -68,11 +82,17 @@ export default class Status {

_pollStatus = () => {
const { secureToken, isConnected, isConnecting, needsToken } = this._api;

const nextTimeout = (timeout = 1000) => {
setTimeout(this._pollStatus, timeout);
};

if (isConnected !== this._store.getState().nodeStatus.isConnected) {
Copy link
Contributor

@derhuerst derhuerst Nov 3, 2016

Choose a reason for hiding this comment

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

const wasConnected = this._store.getState().nodeStatus.isConnected;
if (isConnected !== wasConnected) 

this._fetchEnode();
}

this._store.dispatch(statusCollection({ isConnected, isConnecting, needsToken, secureToken }));

if (!isConnected) {
nextTimeout(250);
return;
Expand Down
1 change: 1 addition & 0 deletions js/src/redux/providers/statusReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const initialState = {
clientVersion: '',
coinbase: '',
defaultExtraData: '',
enode: '',
extraData: '',
gasFloorTarget: new BigNumber(0),
hashrate: new BigNumber(0),
Expand Down
10 changes: 9 additions & 1 deletion js/src/views/Application/Status/status.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@
/* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/
.status {
clear: both;
padding: 1.5em;
text-align: right;
color: #ddd;
display: flex;
flex-direction: column;
align-items: flex-end;
}

.title {
margin: 0 0.5em 0 2em;
}

.enode {
width: 45em;
word-wrap: break-word;
margin: 0.5em 0 0.25em;
}

.block {
}

Expand Down
19 changes: 18 additions & 1 deletion js/src/views/Application/Status/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Status extends Component {
static propTypes = {
blockNumber: PropTypes.object.isRequired,
clientVersion: PropTypes.string,
enode: PropTypes.string,
netPeers: PropTypes.object,
netChain: PropTypes.string,
isTest: PropTypes.bool
Expand All @@ -44,6 +45,7 @@ class Status extends Component {
<div className={ styles.version }>
{ clientVersion }
</div>
{ this.renderEnode() }
<div className={ styles.netinfo }>
<div>
<BlockStatus />
Expand All @@ -58,14 +60,29 @@ class Status extends Component {
</div>
);
}

renderEnode () {
const { enode } = this.props;

if (!enode) {
return null;
}

return (
<div className={ styles.enode }>
{ enode }
</div>
);
}
}

function mapStateToProps (state) {
const { blockNumber, clientVersion, netPeers, netChain, isTest } = state.nodeStatus;
const { blockNumber, clientVersion, enode, netPeers, netChain, isTest } = state.nodeStatus;

return {
blockNumber,
clientVersion,
enode,
netPeers,
netChain,
isTest
Expand Down