From 2a3d79f055a0483f5740b9b136daf0c2c193139a Mon Sep 17 00:00:00 2001 From: Jeromy Date: Fri, 29 May 2020 14:47:17 -0700 Subject: [PATCH] add commands to check individual balances for verifiers and clients --- cmd/lotus-shed/verifreg.go | 100 +++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/cmd/lotus-shed/verifreg.go b/cmd/lotus-shed/verifreg.go index f1e665078..41de8c879 100644 --- a/cmd/lotus-shed/verifreg.go +++ b/cmd/lotus-shed/verifreg.go @@ -29,6 +29,8 @@ var verifRegCmd = &cli.Command{ verifRegVerifyClientCmd, verifRegListVerifiersCmd, verifRegListClientsCmd, + verifRegCheckClientCmd, + verifRegCheckVerifierCmd, }, } @@ -275,3 +277,101 @@ var verifRegListClientsCmd = &cli.Command{ return nil }, } + +var verifRegCheckClientCmd = &cli.Command{ + Name: "check-client", + Usage: "check verified client remaining bytes", + Action: func(cctx *cli.Context) error { + if !cctx.Args().Present() { + return fmt.Errorf("must specify client address to check") + } + + caddr, err := address.NewFromString(cctx.Args().First()) + if err != nil { + return err + } + + api, closer, err := lcli.GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := lcli.ReqContext(cctx) + + act, err := api.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, types.EmptyTSK) + if err != nil { + return err + } + + apibs := apibstore.NewAPIBlockstore(api) + cst := cbor.NewCborStore(apibs) + + var st verifreg.State + if err := cst.Get(ctx, act.Head, &st); err != nil { + return err + } + + vh, err := hamt.LoadNode(ctx, cst, st.VerifiedClients) + if err != nil { + return err + } + + var dcap verifreg.DataCap + if err := vh.Find(ctx, string(caddr.Bytes()), &dcap); err != nil { + return err + } + + fmt.Println(dcap) + + return nil + }, +} + +var verifRegCheckVerifierCmd = &cli.Command{ + Name: "check-verifier", + Usage: "check verifiers remaining bytes", + Action: func(cctx *cli.Context) error { + if !cctx.Args().Present() { + return fmt.Errorf("must specify verifier address to check") + } + + vaddr, err := address.NewFromString(cctx.Args().First()) + if err != nil { + return err + } + + api, closer, err := lcli.GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := lcli.ReqContext(cctx) + + act, err := api.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, types.EmptyTSK) + if err != nil { + return err + } + + apibs := apibstore.NewAPIBlockstore(api) + cst := cbor.NewCborStore(apibs) + + var st verifreg.State + if err := cst.Get(ctx, act.Head, &st); err != nil { + return err + } + + vh, err := hamt.LoadNode(ctx, cst, st.Verifiers) + if err != nil { + return err + } + + var dcap verifreg.DataCap + if err := vh.Find(ctx, string(vaddr.Bytes()), &dcap); err != nil { + return err + } + + fmt.Println(dcap) + + return nil + }, +}