import React from 'react'; import {BlockLinks} from "./BlockLink"; import Address from "./Address"; import Window from "./Window"; class Block extends React.Component { constructor(props) { super(props) this.state = {} this.loadHeader() } async loadHeader() { const header = await this.props.conn.call('Filecoin.ChainGetBlock', [this.props.cid]) let messages = await this.props.conn.call('Filecoin.ChainGetParentMessages', [this.props.cid]) let receipts = await this.props.conn.call('Filecoin.ChainGetParentReceipts', [this.props.cid]) if (!messages) { messages = [] } messages = messages.map((msg, k) => ({...msg.Message, cid: msg.Cid, receipt: receipts[k]})) messages = await Promise.all(messages.map(async (msg, i) => { if (msg.receipt.ExitCode !== 0) { let reply = await this.props.conn.call('Filecoin.StateReplay', [{Cids: [this.props.cid], Blocks: [header], Height: header.Height}, msg.Cid]) if(!reply.Error) { reply.Error = "reply: no error" } msg.Error = reply.Error } return msg })) this.setState({header: header, messages: messages}) } render() { let content =
Loading Block Info
if (this.state.header) { let head = this.state.header const messages = this.state.messages.map((m, k) => (
 => 
 N{m.Nonce}  {m.receipt.GasUsed}Gas {m.receipt.ExitCode !== 0 ?  EXIT:{m.receipt.ExitCode} : }
{m.receipt.ExitCode !== 0 ?
     Error: {m.Error}
: }
)) content = (
Height: {head.Height}
Parents:
Weight: {head.ParentWeight}
Miner: {
}
Messages: {head.Messages['/']} {/*TODO: link to message explorer */}
Parent Receipts: {head.ParentMessageReceipts['/']}
Parent State Root: {head.ParentStateRoot['/']}  
 
 
 
 
----
{messages}
) } return ( {content} ) } } export default Block