Use enode RPC in UI (#3108)

* add enode rpc

* spaces -> tabs

* Added Enode to JSAPI // Use it to display in Status (#3106)

* Added enode to JSON RPC Interfaces #3108
This commit is contained in:
Nicolas Gotchac 2016-11-03 12:04:25 +01:00 committed by Gav Wood
parent d101cb5247
commit d99f1b517c
6 changed files with 62 additions and 2 deletions

View File

@ -58,6 +58,11 @@ export default class Ethcore {
.execute('ethcore_dropNonReservedPeers'); .execute('ethcore_dropNonReservedPeers');
} }
enode () {
return this._transport
.execute('ethcore_enode');
}
extraData () { extraData () {
return this._transport return this._transport
.execute('ethcore_extraData'); .execute('ethcore_extraData');

View File

@ -85,6 +85,15 @@ export default {
} }
}, },
enode: {
desc: 'Returns the node enode URI',
params: [],
returns: {
type: String,
desc: 'Enode URI'
}
},
extraData: { extraData: {
desc: 'Returns currently set extra data', desc: 'Returns currently set extra data',
params: [], params: [],

View File

@ -29,6 +29,20 @@ export default class Status {
this._pollPing(); this._pollPing();
this._pollStatus(); this._pollStatus();
this._pollLogs(); this._pollLogs();
this._fetchEnode();
}
_fetchEnode () {
this._api
.ethcore.enode()
.then((enode) => {
this._store.dispatch(statusCollection({ enode }));
})
.catch(() => {
window.setTimeout(() => {
this._fetchEnode();
}, 1000);
});
} }
_subscribeBlockNumber () { _subscribeBlockNumber () {
@ -68,11 +82,17 @@ export default class Status {
_pollStatus = () => { _pollStatus = () => {
const { secureToken, isConnected, isConnecting, needsToken } = this._api; const { secureToken, isConnected, isConnecting, needsToken } = this._api;
const nextTimeout = (timeout = 1000) => { const nextTimeout = (timeout = 1000) => {
setTimeout(this._pollStatus, timeout); setTimeout(this._pollStatus, timeout);
}; };
if (isConnected !== this._store.getState().nodeStatus.isConnected) {
this._fetchEnode();
}
this._store.dispatch(statusCollection({ isConnected, isConnecting, needsToken, secureToken })); this._store.dispatch(statusCollection({ isConnected, isConnecting, needsToken, secureToken }));
if (!isConnected) { if (!isConnected) {
nextTimeout(250); nextTimeout(250);
return; return;

View File

@ -25,6 +25,7 @@ const initialState = {
clientVersion: '', clientVersion: '',
coinbase: '', coinbase: '',
defaultExtraData: '', defaultExtraData: '',
enode: '',
extraData: '', extraData: '',
gasFloorTarget: new BigNumber(0), gasFloorTarget: new BigNumber(0),
hashrate: new BigNumber(0), hashrate: new BigNumber(0),

View File

@ -15,16 +15,24 @@
/* along with Parity. If not, see <http://www.gnu.org/licenses/>. /* along with Parity. If not, see <http://www.gnu.org/licenses/>.
*/ */
.status { .status {
clear: both;
padding: 1.5em; padding: 1.5em;
text-align: right; text-align: right;
color: #ddd; color: #ddd;
display: flex;
flex-direction: column;
align-items: flex-end;
} }
.title { .title {
margin: 0 0.5em 0 2em; margin: 0 0.5em 0 2em;
} }
.enode {
width: 45em;
word-wrap: break-word;
margin: 0.5em 0 0.25em;
}
.block { .block {
} }

View File

@ -26,6 +26,7 @@ class Status extends Component {
static propTypes = { static propTypes = {
blockNumber: PropTypes.object.isRequired, blockNumber: PropTypes.object.isRequired,
clientVersion: PropTypes.string, clientVersion: PropTypes.string,
enode: PropTypes.string,
netPeers: PropTypes.object, netPeers: PropTypes.object,
netChain: PropTypes.string, netChain: PropTypes.string,
isTest: PropTypes.bool isTest: PropTypes.bool
@ -44,6 +45,7 @@ class Status extends Component {
<div className={ styles.version }> <div className={ styles.version }>
{ clientVersion } { clientVersion }
</div> </div>
{ this.renderEnode() }
<div className={ styles.netinfo }> <div className={ styles.netinfo }>
<div> <div>
<BlockStatus /> <BlockStatus />
@ -58,14 +60,29 @@ class Status extends Component {
</div> </div>
); );
} }
renderEnode () {
const { enode } = this.props;
if (!enode) {
return null;
}
return (
<div className={ styles.enode }>
{ enode }
</div>
);
}
} }
function mapStateToProps (state) { function mapStateToProps (state) {
const { blockNumber, clientVersion, netPeers, netChain, isTest } = state.nodeStatus; const { blockNumber, clientVersion, enode, netPeers, netChain, isTest } = state.nodeStatus;
return { return {
blockNumber, blockNumber,
clientVersion, clientVersion,
enode,
netPeers, netPeers,
netChain, netChain,
isTest isTest