import React from 'react'; import Cristal from 'react-cristal' import { BlockLinks } from "./BlockLink"; import StorageNodeInit from "./StorageNodeInit"; import Address from "./Address"; import ChainExplorer from "./ChainExplorer"; import Client from "./Client"; class FullNode extends React.Component { constructor(props) { super(props) this.state = {} this.loadInfo = this.loadInfo.bind(this) this.newSecpAddr = this.newSecpAddr.bind(this) this.newBLSAddr = this.newBLSAddr.bind(this) this.startStorageMiner = this.startStorageMiner.bind(this) this.add1k = this.add1k.bind(this) this.explorer = this.explorer.bind(this) this.client = this.client.bind(this) this.stop = this.stop.bind(this) this.loadInfo() let updates = setInterval(this.loadInfo, 2050) this.props.client.on('close', () => clearInterval(updates)) } async loadInfo() { const id = await this.props.client.call("Filecoin.ID", []) const version = await this.props.client.call("Filecoin.Version", []) const peers = await this.props.client.call("Filecoin.NetPeers", []) const tipset = await this.props.client.call("Filecoin.ChainHead", []) let addrs = await this.props.client.call('Filecoin.WalletList', []) let defaultAddr = "" if (addrs.length > 0) { defaultAddr = await this.props.client.call('Filecoin.WalletDefaultAddress', []) } let paychs = await this.props.client.call('Filecoin.PaychList', []) if(!paychs) paychs = [] const vouchers = await Promise.all(paychs.map(paych => { return this.props.client.call('Filecoin.PaychVoucherList', [paych]) })) let minerList = await this.props.client.call('Filecoin.MinerAddresses', []) let mpoolPending = (await this.props.client.call('Filecoin.MpoolPending', [tipset])).length this.setState(() => ({ id: id, version: version, peers: peers.length, tipset: tipset, mpoolPending: mpoolPending, addrs: addrs, paychs: paychs, vouchers: vouchers, defaultAddr: defaultAddr, minerList: minerList, })) } async newSecpAddr() { const t = "secp256k1" await this.props.client.call("Filecoin.WalletNew", [t]) this.loadInfo() } async newBLSAddr() { const t = "bls" await this.props.client.call("Filecoin.WalletNew", [t]) this.loadInfo() } startStorageMiner() { this.props.spawnStorageNode(this.props.node.Repo, this.props.client) } async add1k(to) { await this.props.give1k(to) } explorer() { this.props.mountWindow((onClose) => ) } client() { this.props.mountWindow((onClose) => ) } async stop() { await this.props.stop() } render() { let runtime =
if (this.state.id) { let chainInfo =
if (this.state.tipset !== undefined) { chainInfo = (
Head: { } H:{this.state.tipset.Height} Mp:{this.state.mpoolPending} [Explore] [Client]
) } let miners = if(this.state.minerList.length > 0) { miners = this.state.minerList.map((a, k) =>
) } let storageMine = [Spawn Storage Miner] let addresses = this.state.addrs.map((addr) => { let line =
if (this.state.defaultAddr === addr) { line = {line} } return
{line}
}) let paychannels = this.state.paychs.map((addr, ak) => { const line =
const vouchers = this.state.vouchers[ak].map(voucher => { let extra = if(voucher.Extra) { extra = Verif: <
> } return
Voucher Nonce:{voucher.Nonce} Lane:{voucher.Lane} Amt:{voucher.Amount} TL:{voucher.TimeLock} MinCl:{voucher.MinCloseHeight} {extra}
}) return
{line} {vouchers}
}) runtime = (
{this.props.node.ID} - v{this.state.version.Version}, {this.state.id.substr(-8)}, {this.state.peers} peers
Repo: LOTUS_PATH={this.props.node.Repo}
{chainInfo}
{storageMine}
Balances: [New [Secp256k1] [BLS]]
{addresses}
{miners}
{paychannels}
) } return (
{runtime}
) } } export default FullNode