Merge pull request #1363 from filecoin-project/feat/cwatch-update

Update chainwatch
This commit is contained in:
Łukasz Magiera 2020-03-09 07:16:40 +01:00 committed by GitHub
commit c10142816e
3 changed files with 64 additions and 12 deletions

View File

@ -17,8 +17,8 @@
{{$addr := .}} {{$addr := .}}
<div> <div>
<a href="key.html?w={{$addr}}">{{$addr}}</a> <a href="key.html?w={{$addr}}">{{$addr}}</a>
<span><b>{{qstr "select count(distinct cid) from messages where \"from\"=?" $addr}}</b> outmsgs;</span> <span><b>{{qstr "select count(distinct cid) from messages where \"from\"=$1" $addr}}</b> outmsgs;</span>
<span><b>{{qstr "select count(distinct cid) from messages where \"to\"=?" $addr}}</b> inmsgs</span> <span><b>{{qstr "select count(distinct cid) from messages where \"to\"=$1" $addr}}</b> inmsgs</span>
</div> </div>
{{end}} {{end}}
</div> </div>

View File

@ -2,7 +2,6 @@ package main
import ( import (
"database/sql" "database/sql"
"fmt"
"sync" "sync"
"time" "time"
@ -211,7 +210,7 @@ create table if not exists receipts
create index if not exists receipts_msg_state_index create index if not exists receipts_msg_state_index
on receipts (msg, state); on receipts (msg, state);
/*
create table if not exists miner_heads create table if not exists miner_heads
( (
head text not null, head text not null,
@ -303,7 +302,7 @@ create index if not exists deal_activations_activation_epoch_index
create unique index if not exists deal_activations_deal_uindex create unique index if not exists deal_activations_deal_uindex
on deal_activations (deal); on deal_activations (deal);
*/
create table if not exists blocks_challenges create table if not exists blocks_challenges
( (
block text not null block text not null
@ -445,7 +444,7 @@ func (st *storage) storeActors(actors map[address.Address]map[types.Actor]actorI
} }
func (st *storage) storeMiners(miners map[minerKey]*minerInfo) error { func (st *storage) storeMiners(miners map[minerKey]*minerInfo) error {
tx, err := st.db.Begin() /*tx, err := st.db.Begin()
if err != nil { if err != nil {
return err return err
} }
@ -490,7 +489,8 @@ create temp table mh (like miner_heads excluding constraints) on commit drop;
return xerrors.Errorf("actor put: %w", err) 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 { func (st *storage) storeHeaders(bhs map[cid.Cid]*types.BlockHeader, sync bool) error {
@ -842,7 +842,7 @@ func (st *storage) storeMpoolInclusions(msgs []api.MpoolUpdate) error {
} }
func (st *storage) storeDeals(deals map[string]api.MarketDeal) error { func (st *storage) storeDeals(deals map[string]api.MarketDeal) error {
tx, err := st.db.Begin() /*tx, err := st.db.Begin()
if err != nil { if err != nil {
return err return err
} }
@ -935,7 +935,7 @@ func (st *storage) storeDeals(deals map[string]api.MarketDeal) error {
if err := tx.Commit(); err != nil { if err := tx.Commit(); err != nil {
return err return err
} }
*/
return nil return nil
} }

View File

@ -9,6 +9,9 @@ import (
"strconv" "strconv"
rice "github.com/GeertJohan/go.rice" 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" "github.com/ipfs/go-cid"
"golang.org/x/xerrors" "golang.org/x/xerrors"
@ -243,6 +246,45 @@ func (h *handler) qstrs(q string, n int, p ...interface{}) ([]string, error) {
return c, nil 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 == "<nil>" {
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) { func (h *handler) messages(filter string, args ...interface{}) (out []types.Message, err error) {
if len(filter) > 0 { if len(filter) > 0 {
filter = " where " + filter filter = " where " + filter
@ -255,7 +297,7 @@ func (h *handler) messages(filter string, args ...interface{}) (out []types.Mess
return nil, err return nil, err
} }
for rws.Next() { for rws.Next() {
var r types.Message var r Message
var cs string var cs string
if err := rws.Scan( if err := rws.Scan(
@ -276,11 +318,21 @@ func (h *handler) messages(filter string, args ...interface{}) (out []types.Mess
if err != nil { if err != nil {
return nil, err 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") log.Warn("msg cid doesn't match")
} }
out = append(out, r) out = append(out, tr)
} }
return return