pond: chain explorer

This commit is contained in:
Łukasz Magiera 2019-08-16 04:34:11 +02:00
parent 3327781e60
commit 04925a27aa
3 changed files with 46 additions and 14 deletions

View File

@ -29,33 +29,47 @@ class Address extends React.Component {
async refresh() { async refresh() {
let balance = 0 let balance = 0
let actor = {} let actor = {}
let actorInfo
try { try {
balance = await this.props.client.call('Filecoin.WalletBalance', [this.props.addr]) balance = await this.props.client.call('Filecoin.WalletBalance', [this.props.addr])
actor = await this.props.client.call('Filecoin.ChainGetActor', [this.props.addr, this.props.ts || null]) actor = await this.props.client.call('Filecoin.ChainGetActor', [this.props.addr, this.props.ts || null])
actorInfo = await this.actorInfo(actor)
} catch (err) { } catch (err) {
console.log(err)
balance = -1 balance = -1
} }
this.setState({balance, actor}) this.setState({balance, actor, actorInfo})
} }
openState() { openState() {
this.props.mountWindow((onClose) => <State addr={this.props.addr} actor={this.state.actor} client={this.props.client} onClose={onClose}/>) this.props.mountWindow((onClose) => <State addr={this.props.addr} actor={this.state.actor} client={this.props.client} onClose={onClose}/>)
} }
async actorInfo(actor) {
const c = new CID(actor.Code['/'])
const mh = multihash.decode(c.multihash) // TODO: check identity
let info = <span>({mh.digest.toString()})</span>
switch(mh.digest.toString()) {
case 'paych':
const actstate = await this.props.client.call('Filecoin.ChainReadState', [actor, this.props.ts || null])
info = <span>({mh.digest.toString()} to <Address nobalance={true} client={this.props.client} addr={actstate.State.To} mountWindow={this.props.mountWindow}/>)</span>
}
return info
}
render() { render() {
let add1k = <span/> let add1k = <span/>
if(this.props.add1k) { if(this.props.add1k) {
add1k = <a href="#" onClick={() => this.props.add1k(this.props.addr)}>[+1k]</a> add1k = <span>&nbsp;<a href="#" onClick={() => this.props.add1k(this.props.addr)}>[+1k]</a></span>
} }
let addr = truncAddr(this.props.addr) let addr = truncAddr(this.props.addr)
let actInfo = <span>(?)</span> let actInfo = <span>(?)</span>
if(this.state.balance >= 0) { if(this.state.balance >= 0) {
const c = new CID(this.state.actor.Code['/']) actInfo = this.state.actorInfo
const mh = multihash.decode(c.multihash) // TODO: check identity
actInfo = <span>({mh.digest.toString()})</span>
addr = <a href="#" onClick={this.openState}>{addr}</a> addr = <a href="#" onClick={this.openState}>{addr}</a>
} }
@ -64,7 +78,7 @@ class Address extends React.Component {
balance = <span></span> balance = <span></span>
} }
return <span>{addr}{balance}&nbsp;{actInfo}&nbsp;{add1k}</span> return <span>{addr}{balance}&nbsp;{actInfo}{add1k}</span>
} }
} }

View File

@ -57,4 +57,20 @@
.Consensus { .Consensus {
font-family: monospace; font-family: monospace;
} }
.ChainExplorer {
font-family: monospace;
}
.ChainExplorer-at {
background: #77ff77;
}
.ChainExplorer-after {
background: #cc9c44
}
.ChainExplorer-before {
background: #cccc00
}

View File

@ -4,10 +4,7 @@ import Cristal from 'react-cristal'
import { BlockLinks } from "./BlockLink"; import { BlockLinks } from "./BlockLink";
import StorageNodeInit from "./StorageNodeInit"; import StorageNodeInit from "./StorageNodeInit";
import Address from "./Address"; import Address from "./Address";
import ChainExplorer from "./ChainExplorer";
async function awaitListReducer(prev, c) {
return [...await prev, await c]
}
class FullNode extends React.Component { class FullNode extends React.Component {
constructor(props) { constructor(props) {
@ -22,6 +19,7 @@ class FullNode extends React.Component {
this.newScepAddr = this.newScepAddr.bind(this) this.newScepAddr = this.newScepAddr.bind(this)
this.startStorageMiner = this.startStorageMiner.bind(this) this.startStorageMiner = this.startStorageMiner.bind(this)
this.add1k = this.add1k.bind(this) this.add1k = this.add1k.bind(this)
this.explorer = this.explorer.bind(this)
this.loadInfo() this.loadInfo()
setInterval(this.loadInfo, 2050) setInterval(this.loadInfo, 2050)
@ -88,6 +86,10 @@ class FullNode extends React.Component {
await this.props.give1k(to) await this.props.give1k(to)
} }
explorer() {
this.props.mountWindow((onClose) => <ChainExplorer onClose={onClose} ts={this.state.tipset} client={this.props.client} mountWindow={this.props.mountWindow}/>)
}
render() { render() {
let runtime = <div></div> let runtime = <div></div>
@ -98,7 +100,7 @@ class FullNode extends React.Component {
<div> <div>
Head: { Head: {
<BlockLinks cids={this.state.tipset.Cids} conn={this.props.client} mountWindow={this.props.mountWindow} /> <BlockLinks cids={this.state.tipset.Cids} conn={this.props.client} mountWindow={this.props.mountWindow} />
} H:{this.state.tipset.Height} } H:{this.state.tipset.Height} <a href="#" onClick={this.explorer}>[Explore]</a>
</div> </div>
) )
} }
@ -122,7 +124,7 @@ class FullNode extends React.Component {
const vouchers = this.state.vouchers[ak].map(voucher => { const vouchers = this.state.vouchers[ak].map(voucher => {
let extra = <span></span> let extra = <span></span>
if(voucher.Extra) { if(voucher.Extra) {
extra = <span>Verif: &lt;<b><Address nobalance={true} client={this.props.client} addr={voucher.Extra.Actor} mountWindow={this.props.mountWindow}/>M{voucher.Extra.Method}</b>&gt;</span> extra = <span>Verif: &lt;<b><Address nobalance={true} client={this.props.client} addr={voucher.Extra.Actor} mountWindow={this.props.mountWindow}/>&nbsp;M{voucher.Extra.Method}</b>&gt;</span>
} }
return <div key={voucher.Nonce} className="FullNode-voucher"> return <div key={voucher.Nonce} className="FullNode-voucher">