Published
Edited
Mar 20, 2021
2 forks
Importers
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getAddrMessageList = async (address, pageSize) => {
let result = []
let curr = 100
let page = 0
while (curr === 100) {
const url = `https://filfox.info/api/v1/address/${address}/messages?pageSize=${pageSize}&page=${page}`
const messages = (await (await fetch(url)).json()).messages
result = result.concat(messages)
curr = messages.length
page = page + 1
}
return result
}
Insert cell
getMessage = async (message) => {
const url = `https://filfox.info/api/v1/message/${message}`
return (await (await fetch(url)).json())
}
Insert cell
getActors = async (actors) => {
return Promise.all(actors.map(d => getActor(d)))
}
Insert cell
getActor = async (actor) => {
const url = `https://filfox.info/api/v1/address/${actor}`
return (await (await fetch(url)).json())
}
Insert cell
getMessagesFromActor = async (actor) => {
const cids = (await getAddrMessageList(actor, 100)).map(d => d.cid)
const messages = cids.map(d => getMessage(d))
return Promise.all(messages)
}
Insert cell
getMessages = async (monitor) => {
return Object.values((await Promise.all(
monitor.map(d => getMessagesFromActor(d, 100))
)).flat().reduce((acc, curr) => {
if (!acc[curr.cid]) {
acc[curr.cid] = curr
}
return acc
}, {}))
}
Insert cell
Insert cell
accounts = Array.from(new Set(ids.split(',').map(d => d.trim())))
Insert cell
actors = getActors(accounts)
Insert cell
messages = getMessages(accounts)
Insert cell
transfers = messages.map(message => message.transfers ? message.transfers.map(transfer => ({transfer, message})) : [{message}]).flat()
Insert cell
transfersOnly = transfers
.filter(d => d.transfer && d.transfer.type === 'transfer')
.map(d => ({
...d.transfer,
flow: {from: d.transfer.from, to: d.transfer.to, through: d.transfer.from != d.message.from && d.message.from},
timestamp: d.message.timestamp,
cid: d.message.cid,
value: d.transfer.value/1e18,
method: d.message.method
}))
Insert cell
function getFilecoinExpectedHeight (at) {
const filGenesis = new Date('2020-08-24 22:00:00Z').getTime()
return Math.floor((at - filGenesis) / 1000 / 30)
}
Insert cell
expectedEpoch = getFilecoinExpectedHeight(Date.now())
Insert cell
Insert cell
balances_table = (balances) => Table(
balances,
{
layout: 'auto',
rows: 30,
sort: 'balances',
columns: ['id', 'actor', 'balance'],
format: {
id: x => html`${addr(x, '')}`,
balance: x => d3.format(',.2f')(+x/1e18)
}
}
)
Insert cell
message_table = (messages) => Table(
messages,
{
layout: 'auto',
rows: 30,
sort: 'timestamp',
columns: ['cid', 'flow', 'method', 'value', 'timestamp'],
format: {
timestamp: x => d3.timeFormat('%Y/%m/%d %X')(new Date(x*1000)),
cid: x => html`<a href="https://filfox.info/en/message/${x}">${x.substr(0,4)}...${x.substr(-6)}</a>`,
flow: ({from, to, through}) => {

return html`
${addr(from)}
&rarr;
${addr(to)}
${through && `(signed by ${addr(through, 'sign')})` || ''}
`
},
}
}
)
Insert cell
addr = (address, sign) => {
const short = address.length < 10 ? address : address.substr(-6)
return `<a href="https://filfox.info/en/address/${address}">${short} ${addresses[sign ? sign : address] || addresses['default']}</a>`
}
Insert cell
addresses = ({default: '👤', sign: '✍️', multisig:'🔒' })
Insert cell
Insert cell
import {Table} from "@observablehq/table"
Insert cell
d3 = require('d3@5', 'd3-time-format', 'd3-array@2')
Insert cell
import {text} from "@jashkenas/inputs"
Insert cell
import {serialize} from "@palewire/saving-csv"
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