Merge pull request #9468 from filecoin-project/gstuart/FIP-0045-cli
feat: cli: Add commands for listing allocations and removing expired allocations
This commit is contained in:
commit
39557de7f4
179
cli/filplus.go
179
cli/filplus.go
@ -5,6 +5,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@ -26,6 +28,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/datacap"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/datacap"
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin/verifreg"
|
"github.com/filecoin-project/lotus/chain/actors/builtin/verifreg"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
|
"github.com/filecoin-project/lotus/lib/tablewriter"
|
||||||
)
|
)
|
||||||
|
|
||||||
var filplusCmd = &cli.Command{
|
var filplusCmd = &cli.Command{
|
||||||
@ -39,6 +42,8 @@ var filplusCmd = &cli.Command{
|
|||||||
filplusCheckClientCmd,
|
filplusCheckClientCmd,
|
||||||
filplusCheckNotaryCmd,
|
filplusCheckNotaryCmd,
|
||||||
filplusSignRemoveDataCapProposal,
|
filplusSignRemoveDataCapProposal,
|
||||||
|
filplusListAllocationsCmd,
|
||||||
|
filplusRemoveExpiredAllocationsCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,6 +229,180 @@ var filplusListClientsCmd = &cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var filplusListAllocationsCmd = &cli.Command{
|
||||||
|
Name: "list-allocations",
|
||||||
|
Usage: "List allocations made by client",
|
||||||
|
ArgsUsage: "clientAddress",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "expired",
|
||||||
|
Usage: "list only expired allocations",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
if cctx.NArg() != 1 {
|
||||||
|
return IncorrectNumArgs(cctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
|
clientAddr, err := address.NewFromString(cctx.Args().Get(0))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
clientIdAddr, err := api.StateLookupID(ctx, clientAddr, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
store := adt.WrapStore(ctx, cbor.NewCborStore(blockstore.NewAPIBlockstore(api)))
|
||||||
|
|
||||||
|
verifregActor, err := api.StateGetActor(ctx, verifreg.Address, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
verifregState, err := verifreg.Load(store, verifregActor)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ts, err := api.ChainHead(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
allocationsMap, err := verifregState.GetAllocations(clientIdAddr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
tw := tablewriter.New(
|
||||||
|
tablewriter.Col("ID"),
|
||||||
|
tablewriter.Col("Provider"),
|
||||||
|
tablewriter.Col("Data"),
|
||||||
|
tablewriter.Col("Size"),
|
||||||
|
tablewriter.Col("TermMin"),
|
||||||
|
tablewriter.Col("TermMax"),
|
||||||
|
tablewriter.Col("Expiration"),
|
||||||
|
)
|
||||||
|
|
||||||
|
for allocationId, allocation := range allocationsMap {
|
||||||
|
if ts.Height() > allocation.Expiration || !cctx.IsSet("expired") {
|
||||||
|
tw.Write(map[string]interface{}{
|
||||||
|
"ID": allocationId,
|
||||||
|
"Provider": allocation.Provider,
|
||||||
|
"Data": allocation.Data,
|
||||||
|
"Size": allocation.Size,
|
||||||
|
"TermMin": allocation.TermMin,
|
||||||
|
"TermMax": allocation.TermMax,
|
||||||
|
"Expiration": allocation.Expiration,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tw.Flush(os.Stdout)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var filplusRemoveExpiredAllocationsCmd = &cli.Command{
|
||||||
|
Name: "remove-expired-allocations",
|
||||||
|
Usage: "remove expired allocations (if no allocations are specified all eligible allocations are removed)",
|
||||||
|
ArgsUsage: "clientAddress Optional[...allocationId]",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "from",
|
||||||
|
Usage: "optionally specify the account to send the message from",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(cctx *cli.Context) error {
|
||||||
|
if cctx.NArg() < 1 {
|
||||||
|
return IncorrectNumArgs(cctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
api, closer, err := GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer closer()
|
||||||
|
ctx := ReqContext(cctx)
|
||||||
|
|
||||||
|
args := cctx.Args().Slice()
|
||||||
|
|
||||||
|
clientAddr, err := address.NewFromString(args[0])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
clientIdAddr, err := api.StateLookupID(ctx, clientAddr, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
clientId, err := address.IDFromAddress(clientIdAddr)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fromAddr := clientIdAddr
|
||||||
|
if from := cctx.String("from"); from != "" {
|
||||||
|
addr, err := address.NewFromString(from)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fromAddr = addr
|
||||||
|
}
|
||||||
|
|
||||||
|
allocationIDs := make([]verifregtypes9.AllocationId, len(args)-1)
|
||||||
|
for i, allocationString := range args[1:] {
|
||||||
|
id, err := strconv.ParseUint(allocationString, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
allocationIDs[i] = verifregtypes9.AllocationId(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
params, err := actors.SerializeParams(&verifregtypes9.RemoveExpiredAllocationsParams{
|
||||||
|
Client: abi.ActorID(clientId),
|
||||||
|
AllocationIds: allocationIDs,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := &types.Message{
|
||||||
|
To: verifreg.Address,
|
||||||
|
From: fromAddr,
|
||||||
|
Method: verifreg.Methods.RemoveExpiredAllocations,
|
||||||
|
Params: params,
|
||||||
|
}
|
||||||
|
|
||||||
|
smsg, err := api.MpoolPushMessage(ctx, msg, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("message sent, now waiting on cid: %s\n", smsg.Cid())
|
||||||
|
|
||||||
|
mwait, err := api.StateWaitMsg(ctx, smsg.Cid(), build.MessageConfidence)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if mwait.Receipt.ExitCode.IsError() {
|
||||||
|
return fmt.Errorf("failed to remove expired allocations: %d", mwait.Receipt.ExitCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var filplusCheckClientCmd = &cli.Command{
|
var filplusCheckClientCmd = &cli.Command{
|
||||||
Name: "check-client-datacap",
|
Name: "check-client-datacap",
|
||||||
Usage: "check verified client remaining bytes",
|
Usage: "check verified client remaining bytes",
|
||||||
|
@ -1208,6 +1208,8 @@ COMMANDS:
|
|||||||
check-client-datacap check verified client remaining bytes
|
check-client-datacap check verified client remaining bytes
|
||||||
check-notary-datacap check a notary's remaining bytes
|
check-notary-datacap check a notary's remaining bytes
|
||||||
sign-remove-data-cap-proposal allows a notary to sign a Remove Data Cap Proposal
|
sign-remove-data-cap-proposal allows a notary to sign a Remove Data Cap Proposal
|
||||||
|
list-allocations List allocations made by client
|
||||||
|
remove-expired-allocations remove expired allocations (if no allocations are specified all eligible allocations are removed)
|
||||||
help, h Shows a list of commands or help for one command
|
help, h Shows a list of commands or help for one command
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
@ -1293,6 +1295,32 @@ OPTIONS:
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### lotus filplus list-allocations
|
||||||
|
```
|
||||||
|
NAME:
|
||||||
|
lotus filplus list-allocations - List allocations made by client
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
lotus filplus list-allocations [command options] clientAddress
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
--expired list only expired allocations (default: false)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### lotus filplus remove-expired-allocations
|
||||||
|
```
|
||||||
|
NAME:
|
||||||
|
lotus filplus remove-expired-allocations - remove expired allocations (if no allocations are specified all eligible allocations are removed)
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
lotus filplus remove-expired-allocations [command options] clientAddress Optional[...allocationId]
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
--from value optionally specify the account to send the message from
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
## lotus paych
|
## lotus paych
|
||||||
```
|
```
|
||||||
NAME:
|
NAME:
|
||||||
|
Loading…
Reference in New Issue
Block a user