Add accessors for allocations and claims maps

This commit is contained in:
Geoff Stuart
2022-10-07 16:41:59 -04:00
parent 6e99a6b9f7
commit e2d5d12e7f
27 changed files with 634 additions and 2 deletions
+76 -1
View File
@@ -813,7 +813,7 @@ func (a *StateAPI) StateGetAllocation(ctx context.Context, clientAddr address.Ad
allocation, found, err := st.GetAllocation(idAddr, allocationId)
if err != nil {
return nil, err
return nil, xerrors.Errorf("getting allocation: %w", err)
}
if !found {
return nil, nil
@@ -822,6 +822,81 @@ func (a *StateAPI) StateGetAllocation(ctx context.Context, clientAddr address.Ad
return allocation, nil
}
func (a *StateAPI) StateGetAllocations(ctx context.Context, clientAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) {
idAddr, err := a.StateLookupID(ctx, clientAddr, tsk)
if err != nil {
return nil, err
}
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}
st, err := a.StateManager.GetVerifregState(ctx, ts)
if err != nil {
return nil, xerrors.Errorf("loading verifreg state: %w", err)
}
allocations, err := st.GetAllocations(idAddr)
if err != nil {
return nil, xerrors.Errorf("getting allocations: %w", err)
}
return allocations, nil
}
func (a *StateAPI) StateGetClaim(ctx context.Context, providerAddr address.Address, claimId verifregtypes.ClaimId, tsk types.TipSetKey) (*verifregtypes.Claim, error) {
idAddr, err := a.StateLookupID(ctx, providerAddr, tsk)
if err != nil {
return nil, err
}
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}
st, err := a.StateManager.GetVerifregState(ctx, ts)
if err != nil {
return nil, err
}
claim, found, err := st.GetClaim(idAddr, claimId)
if err != nil {
return nil, xerrors.Errorf("getting claim: %w", err)
}
if !found {
return nil, nil
}
return claim, nil
}
func (a *StateAPI) StateGetClaims(ctx context.Context, providerAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) {
idAddr, err := a.StateLookupID(ctx, providerAddr, tsk)
if err != nil {
return nil, err
}
ts, err := a.Chain.GetTipSetFromKey(ctx, tsk)
if err != nil {
return nil, xerrors.Errorf("loading tipset %s: %w", tsk, err)
}
st, err := a.StateManager.GetVerifregState(ctx, ts)
if err != nil {
return nil, xerrors.Errorf("loading verifreg state: %w", err)
}
claims, err := st.GetClaims(idAddr)
if err != nil {
return nil, xerrors.Errorf("getting claims: %w", err)
}
return claims, nil
}
func (a *StateAPI) StateComputeDataCID(ctx context.Context, maddr address.Address, sectorType abi.RegisteredSealProof, deals []abi.DealID, tsk types.TipSetKey) (cid.Cid, error) {
nv, err := a.StateNetworkVersion(ctx, tsk)
if err != nil {