Published
Edited
Aug 11, 2020
Insert cell
Insert cell
Insert cell
Insert cell
await client.version()
Insert cell
Insert cell
chainHead = await client.chainHead()
Insert cell
Insert cell
currentHeight = chainHead.Height
Insert cell
Insert cell
headTipSet = chainHead.Cids
Insert cell
Insert cell
Insert cell
selectedHeight
Insert cell
Insert cell
Insert cell
tipSet = (await client.chainGetTipSetByHeight(selectedHeight, headTipSet)).Cids
Insert cell
Insert cell
totalPower = (await client.stateMinerPower('<empty>', tipSet)).TotalPower
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
async function* minerPowerStream() {
for (const { miner, annotation, longitude, latitude } of routableMiners) {
const minerPower = (await client.stateMinerPower(miner, tipSet)).MinerPower
yield {
miner,
annotation,
longitude,
latitude,
rawBytePower: Number(minerPower.RawBytePower),
qualityAdjPower: Number(minerPower.QualityAdjPower),
}
}
}
Insert cell
minerPowerStream()
Insert cell
Insert cell
minerPower = {
let records = []
for await (const record of minerPowerStream()) {
records.push(record)
records.sort(({qualityAdjPower: a}, {qualityAdjPower: b}) => b - a)
yield records
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mapboxgl = require('mapbox-gl')
Insert cell
chinaViewState = ({
latitude: 28.908332885027765,
longitude: 113.50569520637455,
zoom: 3.326570932673526,
bearing: 6.120265859126128,
pitch: 52.01540376375816,
minZoom: 1,
maxZoom: 20
})
Insert cell
deckgl = {
return new deck.DeckGL({
container,
map: mapboxgl,
mapboxAccessToken: '',
// This token is for demo-purpose only and rotated regularly. Get your token at https://www.mapbox.com
mapboxApiAccessToken: 'pk.eyJ1IjoidWJlcmRhdGEiLCJhIjoiY2pudzRtaWloMDAzcTN2bzN1aXdxZHB5bSJ9.2bkj3IiRC8wj3jLThvDGdA',
mapStyle: 'mapbox://styles/mapbox/dark-v10', // https://docs.mapbox.com/api/maps/#styles
initialViewState: chinaViewState,
controller: true,
layers: [ hexagonLayer ]
});
}
Insert cell
async function *dataStream() {
let power = 0
let count = 0
let records = []
for await (const record of minerPowerStream()) {
if (record.qualityAdjPower > 0) {
power += record.qualityAdjPower
count++
records.push(record)
}
}
yield { height: selectedHeight, count, power: bytes(power, { mode: 'binary' }), records }
}
Insert cell
data = dataStream()
Insert cell
hexagonLayer = new deck.HexagonLayer({
id: 'miners',
extruded: true,
data: data.records,
radius: 50000,
getPosition: d => [d.longitude, d.latitude],
getElevationWeight: d => d.qualityAdjPower,
elevationAggregation: 'SUM',
elevationScale: 400,
opacity: 0.4
})
Insert cell
Insert cell
Insert cell
Insert cell
LotusRPC = (await import('@filecoin-shipyard/lotus-client-rpc')).LotusRPC
Insert cell
BrowserProvider = (await import('@filecoin-shipyard/lotus-client-provider-browser')).BrowserProvider
Insert cell
schema = (await import('@filecoin-shipyard/lotus-client-schema')).testnet.fullNode
Insert cell
Insert cell
Object.keys(schema.methods)
Insert cell
Insert cell
endpointUrl = "wss://lotus.testground.ipfs.team/calibration_api/0/node/rpc/v0"
Insert cell
client = {
const provider = new BrowserProvider(endpointUrl)
return new LotusRPC(provider, { schema })
}
Insert cell
bytes = (await import('@jimpick/bytes-iec@3.1.0-2')).default
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more