From a46296d34016611e89e733b7f4bee90f71e66a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Mon, 9 Mar 2020 06:43:32 +0100 Subject: [PATCH] Update chainwatch --- cmd/lotus-chainwatch/site/keys.html | 4 +- cmd/lotus-chainwatch/storage.go | 14 +++---- cmd/lotus-chainwatch/templates.go | 58 +++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/cmd/lotus-chainwatch/site/keys.html b/cmd/lotus-chainwatch/site/keys.html index 01ba3d241..1ad72fafe 100644 --- a/cmd/lotus-chainwatch/site/keys.html +++ b/cmd/lotus-chainwatch/site/keys.html @@ -17,8 +17,8 @@ {{$addr := .}}
{{$addr}} - {{qstr "select count(distinct cid) from messages where \"from\"=?" $addr}} outmsgs; - {{qstr "select count(distinct cid) from messages where \"to\"=?" $addr}} inmsgs + {{qstr "select count(distinct cid) from messages where \"from\"=$1" $addr}} outmsgs; + {{qstr "select count(distinct cid) from messages where \"to\"=$1" $addr}} inmsgs
{{end}} diff --git a/cmd/lotus-chainwatch/storage.go b/cmd/lotus-chainwatch/storage.go index 374066ced..527befaa3 100644 --- a/cmd/lotus-chainwatch/storage.go +++ b/cmd/lotus-chainwatch/storage.go @@ -2,7 +2,6 @@ package main import ( "database/sql" - "fmt" "sync" "time" @@ -211,7 +210,7 @@ create table if not exists receipts create index if not exists receipts_msg_state_index on receipts (msg, state); - +/* create table if not exists miner_heads ( head text not null, @@ -300,7 +299,7 @@ create index if not exists deal_activations_activation_epoch_index create unique index if not exists deal_activations_deal_uindex on deal_activations (deal); - +*/ create table if not exists blocks_challenges ( block text not null @@ -442,7 +441,7 @@ func (st *storage) storeActors(actors map[address.Address]map[types.Actor]actorI } func (st *storage) storeMiners(miners map[minerKey]*minerInfo) error { - tx, err := st.db.Begin() + /*tx, err := st.db.Begin() if err != nil { return err } @@ -487,7 +486,8 @@ create temp table mh (like miner_heads excluding constraints) on commit drop; return xerrors.Errorf("actor put: %w", err) } - return tx.Commit() + return tx.Commit()*/ + return nil } func (st *storage) storeHeaders(bhs map[cid.Cid]*types.BlockHeader, sync bool) error { @@ -839,7 +839,7 @@ func (st *storage) storeMpoolInclusions(msgs []api.MpoolUpdate) error { } func (st *storage) storeDeals(deals map[string]api.MarketDeal) error { - tx, err := st.db.Begin() + /*tx, err := st.db.Begin() if err != nil { return err } @@ -932,7 +932,7 @@ func (st *storage) storeDeals(deals map[string]api.MarketDeal) error { if err := tx.Commit(); err != nil { return err } - +*/ return nil } diff --git a/cmd/lotus-chainwatch/templates.go b/cmd/lotus-chainwatch/templates.go index 32b9d398c..d1ad6984d 100644 --- a/cmd/lotus-chainwatch/templates.go +++ b/cmd/lotus-chainwatch/templates.go @@ -9,6 +9,9 @@ import ( "strconv" rice "github.com/GeertJohan/go.rice" + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/specs-actors/actors/abi" + "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/ipfs/go-cid" "golang.org/x/xerrors" @@ -243,6 +246,45 @@ func (h *handler) qstrs(q string, n int, p ...interface{}) ([]string, error) { return c, nil } +type sbig types.BigInt + +func (bi *sbig) Scan(value interface{}) error { + switch value := value.(type) { + case string: + i, ok := big.NewInt(0).SetString(value, 10) + if !ok { + if value == "" { + return nil + } + return xerrors.Errorf("failed to parse bigint string: '%s'", value) + } + + bi.Int = i + + return nil + case int64: + bi.Int = big.NewInt(value).Int + return nil + default: + return xerrors.Errorf("non-string types unsupported: %T", value) + } +} + +type Message struct { + To address.Address + From address.Address + + Nonce uint64 + + Value sbig + + GasPrice sbig + GasLimit sbig + + Method abi.MethodNum + Params []byte +} + func (h *handler) messages(filter string, args ...interface{}) (out []types.Message, err error) { if len(filter) > 0 { filter = " where " + filter @@ -255,7 +297,7 @@ func (h *handler) messages(filter string, args ...interface{}) (out []types.Mess return nil, err } for rws.Next() { - var r types.Message + var r Message var cs string if err := rws.Scan( @@ -276,11 +318,21 @@ func (h *handler) messages(filter string, args ...interface{}) (out []types.Mess if err != nil { return nil, err } - if c != r.Cid() { + tr := types.Message{ + To: r.To, + From: r.From, + Nonce: r.Nonce, + Value: types.BigInt(r.Value), + GasPrice: types.BigInt(r.GasPrice), + GasLimit: types.BigInt(r.GasLimit), + Method: r.Method, + Params: r.Params, + } + if c != tr.Cid() { log.Warn("msg cid doesn't match") } - out = append(out, r) + out = append(out, tr) } return