From 8e4ce107083e1526f57bfbe2776ed561fa67285d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sun, 17 Mar 2024 22:36:08 +0100 Subject: [PATCH] curio web: Show basic balances in Actor Summary --- curiosrc/web/hapi/simpleinfo.go | 2 ++ curiosrc/web/hapi/watch_actor.go | 34 ++++++++++++++++++++++ curiosrc/web/hapi/web/actor_summary.gohtml | 3 ++ curiosrc/web/static/index.html | 3 ++ 4 files changed, 42 insertions(+) diff --git a/curiosrc/web/hapi/simpleinfo.go b/curiosrc/web/hapi/simpleinfo.go index 319db88e0..e78c1dffb 100644 --- a/curiosrc/web/hapi/simpleinfo.go +++ b/curiosrc/web/hapi/simpleinfo.go @@ -33,6 +33,8 @@ type actorInfo struct { QualityAdjustedPower string RawBytePower string + ActorBalance, ActorAvailable, WorkerBalance string + Deadlines []actorDeadline } diff --git a/curiosrc/web/hapi/watch_actor.go b/curiosrc/web/hapi/watch_actor.go index e785a415b..f7fb73d3f 100644 --- a/curiosrc/web/hapi/watch_actor.go +++ b/curiosrc/web/hapi/watch_actor.go @@ -10,6 +10,9 @@ import ( "github.com/filecoin-project/go-address" + "github.com/filecoin-project/lotus/blockstore" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" + "github.com/filecoin-project/lotus/chain/store" "github.com/filecoin-project/lotus/chain/types" ) @@ -39,6 +42,8 @@ func (a *app) updateActor(ctx context.Context) error { api := a.workingApi a.rpcInfoLk.Unlock() + stor := store.ActorStore(ctx, blockstore.NewReadCachedBlockstore(blockstore.NewAPIBlockstore(a.workingApi), ChainBlockCache)) + if api == nil { log.Warnw("no working api yet") return nil @@ -76,6 +81,16 @@ func (a *app) updateActor(ctx context.Context) error { return xerrors.Errorf("getting deadlines: %w", err) } + mact, err := api.StateGetActor(ctx, addr, types.EmptyTSK) + if err != nil { + return xerrors.Errorf("getting actor: %w", err) + } + + mas, err := miner.Load(stor, mact) + if err != nil { + return err + } + outDls := []actorDeadline{} for dlidx := range dls { @@ -127,12 +142,31 @@ func (a *app) updateActor(ctx context.Context) error { outDls[pd.Index].Current = true + avail, err := mas.AvailableBalance(mact.Balance) + if err != nil { + return xerrors.Errorf("getting available balance: %w", err) + } + + mi, err := mas.Info() + if err != nil { + return xerrors.Errorf("getting miner info: %w", err) + } + + wbal, err := api.WalletBalance(ctx, mi.Worker) + if err != nil { + return xerrors.Errorf("getting worker balance: %w", err) + } + actorInfos = append(actorInfos, actorInfo{ Address: addr.String(), CLayers: cnames, QualityAdjustedPower: types.DeciStr(p.MinerPower.QualityAdjPower), RawBytePower: types.DeciStr(p.MinerPower.RawBytePower), Deadlines: outDls, + + ActorBalance: types.FIL(mact.Balance).Short(), + ActorAvailable: types.FIL(avail).Short(), + WorkerBalance: types.FIL(wbal).Short(), }) } diff --git a/curiosrc/web/hapi/web/actor_summary.gohtml b/curiosrc/web/hapi/web/actor_summary.gohtml index 31992fb23..92f1139ce 100644 --- a/curiosrc/web/hapi/web/actor_summary.gohtml +++ b/curiosrc/web/hapi/web/actor_summary.gohtml @@ -15,6 +15,9 @@ {{end}} + {{.ActorBalance}} + {{.ActorAvailable}} + {{.WorkerBalance}} {{end}} {{end}} \ No newline at end of file diff --git a/curiosrc/web/static/index.html b/curiosrc/web/static/index.html index f2f1c087c..eaabe0173 100644 --- a/curiosrc/web/static/index.html +++ b/curiosrc/web/static/index.html @@ -97,6 +97,9 @@ Config Layers QaP Deadlines + Balance + Available + Worker