pond: Fix chain explorer

This commit is contained in:
Łukasz Magiera 2019-10-09 07:12:35 +02:00
parent 172c1895f2
commit 535becf5e7
2 changed files with 31 additions and 4 deletions

View File

@ -12,7 +12,7 @@ export class BlockLinks extends React.Component {
block = this.props.blocks[k] block = this.props.blocks[k]
} }
return <BlockLink key={c} block={block} conn={this.props.conn} cid={c} mountWindow={this.props.mountWindow}/> return <BlockLink key={c + '-' + k} block={block} conn={this.props.conn} cid={c} mountWindow={this.props.mountWindow}/>
}) })
} }
} }

View File

@ -5,6 +5,8 @@ import Window from "./Window";
const rows = 32 const rows = 32
class ChainExplorer extends React.Component { class ChainExplorer extends React.Component {
fetching = []
constructor(props) { constructor(props) {
super(props) super(props)
@ -57,11 +59,30 @@ class ChainExplorer extends React.Component {
await this.fetchVisible() await this.fetchVisible()
} }
async fetch(h, cache, msgcache) { async fetch(h, base, cache, msgcache) {
console.log(h, base, cache)
if (this.fetching[h]) {
return
}
this.fetching[h] = true
if (h < 0) { if (h < 0) {
return return
} }
const cids = cache[h + 1].Blocks.map(b => b.Parents).reduce((acc, val) => acc.concat(val), []) if(!base.Blocks) {
console.log("base for H is nll blk", h, base)
return
}
let cids = base.Blocks.map(b => b.Parents)
.reduce((acc, val) => {
let out = {...acc}
val.forEach(c => out[c['/']] = 8)
return out
}, {})
cids = Object.keys(cids).map(k => ({'/': k}))
console.log("parents", cids)
const blocks = await Promise.all(cids.map(cid => this.props.client.call('Filecoin.ChainGetBlock', [cid]))) const blocks = await Promise.all(cids.map(cid => this.props.client.call('Filecoin.ChainGetBlock', [cid])))
cache[h] = { cache[h] = {
@ -71,6 +92,8 @@ class ChainExplorer extends React.Component {
} }
await this.updateMessages(cids, msgcache) await this.updateMessages(cids, msgcache)
return cache[h]
} }
async fetchVisible() { async fetchVisible() {
@ -93,7 +116,11 @@ class ChainExplorer extends React.Component {
let cache = {...this.state.cache} let cache = {...this.state.cache}
let msgcache = {...this.state.messages} let msgcache = {...this.state.messages}
await tofetch.reduce(async (prev, next) => [...await prev, await this.fetch(next, cache, msgcache)], Promise.resolve([])) await tofetch.reduce(async (prev, next) => {
let prevts = await prev
let newts = await this.fetch(next, prevts, cache, msgcache)
return newts ? newts : prevts
}, Promise.resolve(cache[top]))
this.setState({cache: cache, messages: msgcache}) this.setState({cache: cache, messages: msgcache})
} }