Skip to content

Commit

Permalink
feat: add API methods to get allocations and claims
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Oct 14, 2022
1 parent 076b4a5 commit 6ecb0d6
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 27 deletions.
80 changes: 79 additions & 1 deletion app/submodule/chain/miner_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func (msa *minerStateAPI) StateGetAllocation(ctx context.Context, clientAddr add

allocation, found, err := st.GetAllocation(idAddr, allocationID)
if err != nil {
return nil, err
return nil, fmt.Errorf("getting allocation: %w", err)
}
if !found {
return nil, nil
Expand All @@ -429,6 +429,84 @@ func (msa *minerStateAPI) StateGetAllocation(ctx context.Context, clientAddr add
return allocation, nil
}

// StateGetAllocations returns the all the allocations for a given client.
func (msa *minerStateAPI) StateGetAllocations(ctx context.Context, clientAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) {
idAddr, err := msa.ChainSubmodule.API().StateLookupID(ctx, clientAddr, tsk)
if err != nil {
return nil, err
}

_, view, err := msa.Stmgr.ParentStateViewTsk(ctx, tsk)
if err != nil {
return nil, fmt.Errorf("Stmgr.ParentStateViewTsk failed:%v", err)
}

st, err := view.LoadVerifregActor(ctx)
if err != nil {
return nil, fmt.Errorf("failed to load miner actor state: %v", err)
}

allocations, err := st.GetAllocations(idAddr)
if err != nil {
return nil, fmt.Errorf("getting allocations: %w", err)
}

return allocations, nil
}

// StateGetClaim returns the claim for a given address and claim ID.
func (msa *minerStateAPI) StateGetClaim(ctx context.Context, providerAddr address.Address, claimID verifregtypes.ClaimId, tsk types.TipSetKey) (*verifregtypes.Claim, error) {
idAddr, err := msa.ChainSubmodule.API().StateLookupID(ctx, providerAddr, tsk)
if err != nil {
return nil, err
}

_, view, err := msa.Stmgr.ParentStateViewTsk(ctx, tsk)
if err != nil {
return nil, fmt.Errorf("Stmgr.ParentStateViewTsk failed:%v", err)
}

st, err := view.LoadVerifregActor(ctx)
if err != nil {
return nil, fmt.Errorf("failed to load miner actor state: %v", err)
}

claim, found, err := st.GetClaim(idAddr, claimID)
if err != nil {
return nil, fmt.Errorf("getting claim: %w", err)
}
if !found {
return nil, nil
}

return claim, nil
}

// StateGetClaims returns the all the claims for a given provider.
func (msa *minerStateAPI) StateGetClaims(ctx context.Context, providerAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) {
idAddr, err := msa.ChainSubmodule.API().StateLookupID(ctx, providerAddr, tsk)
if err != nil {
return nil, err
}

_, view, err := msa.Stmgr.ParentStateViewTsk(ctx, tsk)
if err != nil {
return nil, fmt.Errorf("Stmgr.ParentStateViewTsk failed:%v", err)
}

st, err := view.LoadVerifregActor(ctx)
if err != nil {
return nil, fmt.Errorf("failed to load miner actor state: %v", err)
}

claims, err := st.GetClaims(idAddr)
if err != nil {
return nil, fmt.Errorf("getting claims: %w", err)
}

return claims, nil
}

// StateComputeDataCID computes DataCID from a set of on-chain deals
func (msa *minerStateAPI) StateComputeDataCID(ctx context.Context, maddr address.Address, sectorType abi.RegisteredSealProof, deals []abi.DealID, tsk types.TipSetKey) (cid.Cid, error) {
nv, err := msa.API().StateNetworkVersion(ctx, tsk)
Expand Down
11 changes: 8 additions & 3 deletions venus-devtool/api-gen/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,14 @@ func init() {
panic(err)
}
addExample(constants.TestNetworkVersion)
allocationId := verifreg.AllocationId(0)
addExample(allocationId)
addExample(&allocationId)
allocationID := verifreg.AllocationId(0)
addExample(allocationID)
addExample(&allocationID)
addExample(map[verifreg.AllocationId]verifreg.Allocation{})
claimID := verifreg.ClaimId(0)
addExample(claimID)
addExample(&claimID)
addExample(map[verifreg.ClaimId]verifreg.Claim{})
textSelExample := textselector.Expression("Links/21/Hash/Links/42/Hash")
clientEvent := retrievalmarket.ClientEventDealAccepted
addExample(bitfield.NewFromSet([]uint64{5}))
Expand Down
40 changes: 23 additions & 17 deletions venus-shared/api/chain/v0/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,31 @@ type IMinerState interface {
StateMinerPartitions(ctx context.Context, maddr address.Address, dlIdx uint64, tsk types.TipSetKey) ([]types.Partition, error) //perm:read
StateMinerDeadlines(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]types.Deadline, error) //perm:read
StateMinerSectors(ctx context.Context, maddr address.Address, sectorNos *bitfield.BitField, tsk types.TipSetKey) ([]*miner.SectorOnChainInfo, error) //perm:read
StateMarketStorageDeal(ctx context.Context, dealID abi.DealID, tsk types.TipSetKey) (*types.MarketDeal, error) //perm:read //perm:read
StateMarketStorageDeal(ctx context.Context, dealID abi.DealID, tsk types.TipSetKey) (*types.MarketDeal, error) //perm:read
// StateGetAllocationForPendingDeal returns the allocation for a given deal ID of a pending deal.
StateGetAllocationForPendingDeal(ctx context.Context, dealID abi.DealID, tsk types.TipSetKey) (*verifregtypes.Allocation, error) //perm:read
// StateGetAllocation returns the allocation for a given address and allocation ID.
StateGetAllocation(ctx context.Context, clientAddr address.Address, allocationID verifregtypes.AllocationId, tsk types.TipSetKey) (*verifregtypes.Allocation, error) //perm:read
StateMinerPreCommitDepositForPower(ctx context.Context, maddr address.Address, pci miner.SectorPreCommitInfo, tsk types.TipSetKey) (big.Int, error) //perm:read
StateMinerInitialPledgeCollateral(ctx context.Context, maddr address.Address, pci miner.SectorPreCommitInfo, tsk types.TipSetKey) (big.Int, error) //perm:read
StateVMCirculatingSupplyInternal(ctx context.Context, tsk types.TipSetKey) (types.CirculatingSupply, error) //perm:read
StateCirculatingSupply(ctx context.Context, tsk types.TipSetKey) (abi.TokenAmount, error) //perm:read
StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]*types.MarketDeal, error) //perm:read
StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*miner.SectorOnChainInfo, error) //perm:read
StateLookupID(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error) //perm:read
StateListMiners(ctx context.Context, tsk types.TipSetKey) ([]address.Address, error) //perm:read
StateListActors(ctx context.Context, tsk types.TipSetKey) ([]address.Address, error) //perm:read
StateMinerPower(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*types.MinerPower, error) //perm:read
StateMinerAvailableBalance(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (big.Int, error) //perm:read
StateSectorExpiration(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*lminer.SectorExpiration, error) //perm:read
StateMinerSectorCount(ctx context.Context, addr address.Address, tsk types.TipSetKey) (types.MinerSectors, error) //perm:read
StateMarketBalance(ctx context.Context, addr address.Address, tsk types.TipSetKey) (types.MarketBalance, error) //perm:read
StateDealProviderCollateralBounds(ctx context.Context, size abi.PaddedPieceSize, verified bool, tsk types.TipSetKey) (types.DealCollateralBounds, error) //perm:read
StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) //perm:read
// StateGetAllocations returns the all the allocations for a given client.
StateGetAllocations(ctx context.Context, clientAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.AllocationId]verifregtypes.Allocation, error) //perm:read
// StateGetClaim returns the claim for a given address and claim ID.
StateGetClaim(ctx context.Context, providerAddr address.Address, claimID verifregtypes.ClaimId, tsk types.TipSetKey) (*verifregtypes.Claim, error) //perm:read
// StateGetClaims returns the all the claims for a given provider.
StateGetClaims(ctx context.Context, providerAddr address.Address, tsk types.TipSetKey) (map[verifregtypes.ClaimId]verifregtypes.Claim, error) //perm:read
StateMinerPreCommitDepositForPower(ctx context.Context, maddr address.Address, pci miner.SectorPreCommitInfo, tsk types.TipSetKey) (big.Int, error) //perm:read
StateMinerInitialPledgeCollateral(ctx context.Context, maddr address.Address, pci miner.SectorPreCommitInfo, tsk types.TipSetKey) (big.Int, error) //perm:read
StateVMCirculatingSupplyInternal(ctx context.Context, tsk types.TipSetKey) (types.CirculatingSupply, error) //perm:read
StateCirculatingSupply(ctx context.Context, tsk types.TipSetKey) (abi.TokenAmount, error) //perm:read
StateMarketDeals(ctx context.Context, tsk types.TipSetKey) (map[string]*types.MarketDeal, error) //perm:read
StateMinerActiveSectors(ctx context.Context, maddr address.Address, tsk types.TipSetKey) ([]*miner.SectorOnChainInfo, error) //perm:read
StateLookupID(ctx context.Context, addr address.Address, tsk types.TipSetKey) (address.Address, error) //perm:read
StateListMiners(ctx context.Context, tsk types.TipSetKey) ([]address.Address, error) //perm:read
StateListActors(ctx context.Context, tsk types.TipSetKey) ([]address.Address, error) //perm:read
StateMinerPower(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*types.MinerPower, error) //perm:read
StateMinerAvailableBalance(ctx context.Context, maddr address.Address, tsk types.TipSetKey) (big.Int, error) //perm:read
StateSectorExpiration(ctx context.Context, maddr address.Address, sectorNumber abi.SectorNumber, tsk types.TipSetKey) (*lminer.SectorExpiration, error) //perm:read
StateMinerSectorCount(ctx context.Context, addr address.Address, tsk types.TipSetKey) (types.MinerSectors, error) //perm:read
StateMarketBalance(ctx context.Context, addr address.Address, tsk types.TipSetKey) (types.MarketBalance, error) //perm:read
StateDealProviderCollateralBounds(ctx context.Context, size abi.PaddedPieceSize, verified bool, tsk types.TipSetKey) (types.DealCollateralBounds, error) //perm:read
StateVerifiedClientStatus(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.StoragePower, error) //perm:read
}
87 changes: 87 additions & 0 deletions venus-shared/api/chain/v0/method.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@
* [StateDealProviderCollateralBounds](#StateDealProviderCollateralBounds)
* [StateGetAllocation](#StateGetAllocation)
* [StateGetAllocationForPendingDeal](#StateGetAllocationForPendingDeal)
* [StateGetAllocations](#StateGetAllocations)
* [StateGetClaim](#StateGetClaim)
* [StateGetClaims](#StateGetClaims)
* [StateListActors](#StateListActors)
* [StateListMiners](#StateListMiners)
* [StateLookupID](#StateLookupID)
Expand Down Expand Up @@ -2847,6 +2850,90 @@ Response:
}
```

### StateGetAllocations
StateGetAllocations returns the all the allocations for a given client.


Perms: read

Inputs:
```json
[
"f01234",
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```

Response: `{}`

### StateGetClaim
StateGetClaim returns the claim for a given address and claim ID.


Perms: read

Inputs:
```json
[
"f01234",
0,
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```

Response:
```json
{
"Provider": 1000,
"Client": 1000,
"Data": {
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
"Size": 1032,
"TermMin": 10101,
"TermMax": 10101,
"TermStart": 10101,
"Sector": 9
}
```

### StateGetClaims
StateGetClaims returns the all the claims for a given provider.


Perms: read

Inputs:
```json
[
"f01234",
[
{
"/": "bafy2bzacea3wsdh6y3a36tb3skempjoxqpuyompjbmfeyf34fi3uy6uue42v4"
},
{
"/": "bafy2bzacebp3shtrn43k7g3unredz7fxn4gj533d3o43tqn2p2ipxxhrvchve"
}
]
]
```

Response: `{}`

### StateListActors


Expand Down
45 changes: 45 additions & 0 deletions venus-shared/api/chain/v0/mock/mock_fullnode.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions venus-shared/api/chain/v0/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6ecb0d6

Please sign in to comment.