add commands to check individual balances for verifiers and clients

This commit is contained in:
Jeromy 2020-05-29 14:47:17 -07:00
parent 1c01799a4b
commit 2a3d79f055

View File

@ -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
},
}