feat: state API for verified client data cap

This commit is contained in:
Dirk McCormick
2020-07-02 12:10:11 -04:00
parent 055a8efe10
commit 2c7aa318c1
5 changed files with 67 additions and 20 deletions
+32
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"github.com/filecoin-project/specs-actors/actors/builtin/verifreg"
"strconv"
cid "github.com/ipfs/go-cid"
@@ -810,3 +811,34 @@ func (a *StateAPI) StateMinerAvailableBalance(ctx context.Context, maddr address
return types.BigAdd(st.GetAvailableBalance(act.Balance), vested), nil
}
// StateVerifiedClientStatus returns the data cap for the given address, or zero if the client is not registered
func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (verifreg.DataCap, error) {
act, err := a.StateGetActor(ctx, builtin.VerifiedRegistryActorAddr, tsk)
if err != nil {
return verifreg.DataCap{}, err
}
cst := cbor.NewCborStore(a.StateManager.ChainStore().Blockstore())
var st verifreg.State
if err := cst.Get(ctx, act.Head, &st); err != nil {
return verifreg.DataCap{}, err
}
vh, err := hamt.LoadNode(ctx, cst, st.VerifiedClients)
if err != nil {
return verifreg.DataCap{}, err
}
var dcap verifreg.DataCap
if err := vh.Find(ctx, string(addr.Bytes()), &dcap); err != nil {
// If there is no entry in the data cap table, just return zero
if err == hamt.ErrNotFound {
return verifreg.DataCap{}, nil
}
return verifreg.DataCap{}, err
}
return dcap, nil
}