2019-08-10 01:54:45 +00:00
|
|
|
import React from 'react'
|
2019-09-19 14:27:01 +00:00
|
|
|
import Window from "./Window";
|
2019-10-22 19:29:05 +00:00
|
|
|
import CID from "cids";
|
|
|
|
import * as multihash from "multihashes";
|
|
|
|
import code from "./chain/code";
|
|
|
|
import Address from "./Address";
|
2019-08-10 01:54:45 +00:00
|
|
|
|
|
|
|
class State extends React.Component {
|
2019-10-22 19:29:05 +00:00
|
|
|
byCode = {
|
|
|
|
[code.init]: InitState,
|
|
|
|
[code.power]: PowerState,
|
|
|
|
[code.market]: MarketState,
|
|
|
|
}
|
|
|
|
|
2019-08-10 01:54:45 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.state = {Balance: -2, State: {}}
|
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
2019-10-22 19:29:05 +00:00
|
|
|
const tipset = this.props.tipset || await this.props.client.call("Filecoin.ChainHead", [])
|
2019-09-10 10:25:46 +00:00
|
|
|
const actstate = await this.props.client.call('Filecoin.StateReadState', [this.props.actor, tipset])
|
2019-10-22 19:29:05 +00:00
|
|
|
|
|
|
|
const c = new CID(this.props.actor.Code['/'])
|
|
|
|
const mh = multihash.decode(c.multihash)
|
|
|
|
let code = mh.digest.toString()
|
|
|
|
|
|
|
|
this.setState({...actstate, code: code})
|
2019-08-10 01:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-10-22 19:29:05 +00:00
|
|
|
let state
|
|
|
|
if(this.byCode[this.state.code]) {
|
|
|
|
const Stelem = this.byCode[this.state.code]
|
|
|
|
state = <Stelem client={this.props.client} mountWindow={this.props.mountWindow} tipset={this.props.tipset}/>
|
|
|
|
} else {
|
|
|
|
state = <div>{Object.keys(this.state.State).map(k => <div key={k}>{k}: <span>{JSON.stringify(this.state.State[k])}</span></div>)}</div>
|
|
|
|
}
|
|
|
|
|
2019-08-10 02:22:49 +00:00
|
|
|
const content = <div className="State">
|
2019-08-10 01:54:45 +00:00
|
|
|
<div>Balance: {this.state.Balance}</div>
|
|
|
|
<div>---</div>
|
2019-10-22 19:29:05 +00:00
|
|
|
{state}
|
2019-08-10 01:54:45 +00:00
|
|
|
</div>
|
2019-10-22 19:29:05 +00:00
|
|
|
return <Window initialSize={{width: 700, height: 400}} onClose={this.props.onClose} title={`Actor ${this.props.addr} ${this.props.tipset && this.props.tipset.Height || ''} ${this.state.code}`}>
|
2019-08-10 01:54:45 +00:00
|
|
|
{content}
|
2019-09-19 14:27:01 +00:00
|
|
|
</Window>
|
2019-08-10 01:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-22 19:29:05 +00:00
|
|
|
class InitState extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.state = {actors: []}
|
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
|
|
|
const tipset = await this.props.client.call("Filecoin.ChainHead", []) // TODO: from props
|
|
|
|
const actors = await this.props.client.call("Filecoin.StateListActors", [tipset])
|
|
|
|
this.setState({actors: actors})
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return this.state.actors.sort((a, b) => (Number(a.substr(1)) > Number(b.substr(1))))
|
|
|
|
.map(addr => <div key={addr}><Address addr={addr} client={this.props.client} mountWindow={this.props.mountWindow}/></div>)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class PowerState extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
this.state = {actors: []}
|
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
|
|
|
const tipset = await this.props.client.call("Filecoin.ChainHead", []) // TODO: from props
|
|
|
|
const actors = await this.props.client.call("Filecoin.StateListMiners", [tipset])
|
|
|
|
this.setState({actors: actors})
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return this.state.actors.sort((a, b) => (Number(a.substr(1)) > Number(b.substr(1))))
|
|
|
|
.map(addr => <div key={addr}><Address miner={true} addr={addr} client={this.props.client} mountWindow={this.props.mountWindow}/></div>)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MarketState extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {participants: {}, deals: []}
|
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
|
|
|
const tipset = await this.props.client.call("Filecoin.ChainHead", []) // TODO: from props
|
|
|
|
const participants = await this.props.client.call("Filecoin.StateMarketParticipants", [tipset])
|
|
|
|
const deals = await this.props.client.call("Filecoin.StateMarketDeals", [tipset])
|
|
|
|
this.setState({participants, deals})
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <div>
|
|
|
|
<div>
|
|
|
|
<div>Participants:</div>
|
|
|
|
{Object.keys(this.state.participants).map(p => <span>{p}</span>)}
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<div>Deals:</div>
|
|
|
|
{this.state.deals.map(d => <span>{d}</span>)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-10 01:54:45 +00:00
|
|
|
export default State
|