2019-07-24 17:10:44 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { Client } from 'rpc-websockets'
|
2019-07-24 18:42:02 +00:00
|
|
|
import Cristal from 'react-cristal'
|
2019-07-25 17:06:10 +00:00
|
|
|
import { BlockLinks } from "./BlockLink";
|
2019-07-30 23:18:21 +00:00
|
|
|
import StorageNodeInit from "./StorageNodeInit";
|
2019-07-24 17:10:44 +00:00
|
|
|
|
2019-07-25 14:57:30 +00:00
|
|
|
async function awaitListReducer(prev, c) {
|
|
|
|
return [...await prev, await c]
|
|
|
|
}
|
|
|
|
|
2019-07-25 15:13:45 +00:00
|
|
|
function truncAddr(addr) {
|
|
|
|
if (addr.length > 41) {
|
|
|
|
return <abbr title={addr}>{addr.substr(0, 38) + '...'}</abbr>
|
|
|
|
}
|
|
|
|
return addr
|
|
|
|
}
|
|
|
|
|
2019-07-24 17:10:44 +00:00
|
|
|
class FullNode extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.state = {
|
2019-07-24 22:30:17 +00:00
|
|
|
mining: false,
|
2019-07-24 17:10:44 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 22:30:17 +00:00
|
|
|
this.loadInfo = this.loadInfo.bind(this)
|
|
|
|
this.startMining = this.startMining.bind(this)
|
2019-07-30 23:18:21 +00:00
|
|
|
this.newScepAddr = this.newScepAddr.bind(this)
|
|
|
|
this.startStorageMiner = this.startStorageMiner.bind(this)
|
2019-08-09 15:59:12 +00:00
|
|
|
this.add1k = this.add1k.bind(this)
|
2019-07-24 17:10:44 +00:00
|
|
|
|
2019-08-09 15:59:12 +00:00
|
|
|
this.loadInfo()
|
|
|
|
setInterval(this.loadInfo, 2050)
|
2019-07-24 17:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async loadInfo() {
|
2019-08-09 15:59:12 +00:00
|
|
|
const id = await this.props.client.call("Filecoin.ID", [])
|
|
|
|
|
|
|
|
const version = await this.props.client.call("Filecoin.Version", [])
|
2019-07-24 17:10:44 +00:00
|
|
|
|
2019-08-09 15:59:12 +00:00
|
|
|
const peers = await this.props.client.call("Filecoin.NetPeers", [])
|
2019-07-24 22:14:09 +00:00
|
|
|
|
2019-08-09 15:59:12 +00:00
|
|
|
const tipset = await this.props.client.call("Filecoin.ChainHead", [])
|
2019-07-25 14:57:30 +00:00
|
|
|
|
2019-08-09 15:59:12 +00:00
|
|
|
const addrss = await this.props.client.call('Filecoin.WalletList', [])
|
2019-07-25 23:26:40 +00:00
|
|
|
let defaultAddr = ""
|
|
|
|
if (addrss.length > 0) {
|
2019-08-09 15:59:12 +00:00
|
|
|
defaultAddr = await this.props.client.call('Filecoin.WalletDefaultAddress', [])
|
2019-07-25 23:26:40 +00:00
|
|
|
}
|
2019-07-25 14:57:30 +00:00
|
|
|
|
|
|
|
const balances = await addrss.map(async addr => {
|
2019-07-25 15:13:45 +00:00
|
|
|
let balance = 0
|
|
|
|
try {
|
2019-08-09 15:59:12 +00:00
|
|
|
balance = await this.props.client.call('Filecoin.WalletBalance', [addr])
|
2019-07-25 15:13:45 +00:00
|
|
|
} catch {
|
|
|
|
balance = -1
|
|
|
|
}
|
2019-07-25 14:57:30 +00:00
|
|
|
return [addr, balance]
|
|
|
|
}).reduce(awaitListReducer, Promise.resolve([]))
|
|
|
|
|
2019-08-09 16:11:46 +00:00
|
|
|
this.setState(() => ({
|
|
|
|
id: id,
|
|
|
|
version: version,
|
|
|
|
peers: peers.length,
|
|
|
|
tipset: tipset,
|
|
|
|
|
|
|
|
balances: balances,
|
|
|
|
defaultAddr: defaultAddr}))
|
2019-07-24 17:10:44 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 22:30:17 +00:00
|
|
|
async startMining() {
|
|
|
|
// TODO: Use actual miner address
|
|
|
|
// see cli/miner.go
|
2019-07-30 23:18:21 +00:00
|
|
|
this.setState({mining: true})
|
2019-07-26 16:14:01 +00:00
|
|
|
let addr = "t0523423423" // in case we have no wallets
|
|
|
|
if (this.state.defaultAddr) {
|
|
|
|
addr = this.state.defaultAddr
|
|
|
|
}
|
|
|
|
|
2019-07-24 22:30:17 +00:00
|
|
|
this.setState({mining: true})
|
2019-08-09 15:59:12 +00:00
|
|
|
await this.props.client.call("Filecoin.MinerStart", [addr])
|
2019-07-24 22:30:17 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 23:18:21 +00:00
|
|
|
async newScepAddr() {
|
|
|
|
const t = "secp256k1"
|
2019-08-09 15:59:12 +00:00
|
|
|
await this.props.client.call("Filecoin.WalletNew", [t])
|
2019-07-30 23:18:21 +00:00
|
|
|
this.loadInfo()
|
|
|
|
}
|
|
|
|
|
|
|
|
async startStorageMiner() {
|
2019-08-09 15:59:12 +00:00
|
|
|
this.props.mountWindow((onClose) => <StorageNodeInit fullRepo={this.props.node.Repo} fullConn={this.props.client} pondClient={this.props.pondClient} onClose={onClose} mountWindow={this.props.mountWindow}/>)
|
|
|
|
}
|
|
|
|
|
|
|
|
async add1k(to) {
|
|
|
|
await this.props.give1k(to)
|
2019-07-30 23:18:21 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 17:10:44 +00:00
|
|
|
render() {
|
|
|
|
let runtime = <div></div>
|
2019-08-09 16:11:46 +00:00
|
|
|
|
|
|
|
if (this.state.id) {
|
2019-07-24 22:14:09 +00:00
|
|
|
let chainInfo = <div></div>
|
|
|
|
if (this.state.tipset !== undefined) {
|
|
|
|
chainInfo = (
|
2019-07-25 16:13:46 +00:00
|
|
|
<div>
|
|
|
|
Head: {
|
2019-08-09 17:32:46 +00:00
|
|
|
<BlockLinks cids={this.state.tipset.Cids} conn={this.props.client} mountWindow={this.props.mountWindow} />
|
2019-07-25 16:13:46 +00:00
|
|
|
} H:{this.state.tipset.Height}
|
|
|
|
</div>
|
2019-07-24 22:14:09 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-07-25 16:13:46 +00:00
|
|
|
let mine = <a href="#" disabled={this.state.mining} onClick={this.startMining}>[Mine]</a>
|
2019-07-24 23:46:48 +00:00
|
|
|
if (this.state.mining) {
|
2019-07-25 16:13:46 +00:00
|
|
|
mine = "[Mining]"
|
2019-07-24 23:46:48 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 23:18:21 +00:00
|
|
|
let storageMine = <a href="#" onClick={this.startStorageMiner}>[Spawn Storage Miner]</a>
|
|
|
|
|
2019-07-25 15:13:45 +00:00
|
|
|
let balances = this.state.balances.map(([addr, balance]) => {
|
2019-08-09 15:59:12 +00:00
|
|
|
let add1k = <a href="#" onClick={() => this.add1k(addr)}>[+1k]</a>
|
|
|
|
|
|
|
|
let line = <span>{truncAddr(addr)}: {balance} (ActTyp) {add1k}</span>
|
2019-07-25 15:13:45 +00:00
|
|
|
if (this.state.defaultAddr === addr) {
|
|
|
|
line = <b>{line}</b>
|
|
|
|
}
|
2019-08-09 16:11:46 +00:00
|
|
|
return <div key={addr}>{line}</div>
|
2019-07-25 15:13:45 +00:00
|
|
|
})
|
2019-07-25 14:57:30 +00:00
|
|
|
|
2019-07-24 17:10:44 +00:00
|
|
|
runtime = (
|
|
|
|
<div>
|
2019-08-09 16:11:46 +00:00
|
|
|
<div>{this.props.node.ID} - v{this.state.version.Version}, <abbr title={this.state.id}>{this.state.id.substr(-8)}</abbr>, {this.state.peers} peers</div>
|
2019-07-24 22:14:09 +00:00
|
|
|
<div>Repo: LOTUS_PATH={this.props.node.Repo}</div>
|
|
|
|
{chainInfo}
|
2019-07-25 14:57:30 +00:00
|
|
|
<div>
|
2019-07-30 23:18:21 +00:00
|
|
|
{mine} {storageMine}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div>Balances: [New <a href="#" onClick={this.newScepAddr}>[Secp256k1]</a>]</div>
|
2019-07-25 14:57:30 +00:00
|
|
|
<div>{balances}</div>
|
|
|
|
</div>
|
2019-07-24 22:14:09 +00:00
|
|
|
|
2019-07-24 17:10:44 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2019-07-24 18:42:02 +00:00
|
|
|
<Cristal
|
|
|
|
title={"Node " + this.props.node.ID}
|
|
|
|
initialPosition={{x: this.props.node.ID*30, y: this.props.node.ID * 30}} >
|
2019-07-25 14:57:30 +00:00
|
|
|
<div className="CristalScroll">
|
|
|
|
<div className="FullNode">
|
|
|
|
{runtime}
|
|
|
|
</div>
|
2019-07-24 18:42:02 +00:00
|
|
|
</div>
|
|
|
|
</Cristal>
|
2019-07-24 17:10:44 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default FullNode
|