Merge branch 'master' into asr/spec-v1
This commit is contained in:
+58
-5
@@ -12,13 +12,12 @@ import (
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
|
||||
tm "github.com/buger/goterm"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/fatih/color"
|
||||
datatransfer "github.com/filecoin-project/go-data-transfer"
|
||||
"github.com/filecoin-project/go-fil-markets/retrievalmarket"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-cidutil/cidenc"
|
||||
"github.com/libp2p/go-libp2p-core/peer"
|
||||
@@ -476,6 +475,7 @@ func interactiveDeal(cctx *cli.Context) error {
|
||||
var ask storagemarket.StorageAsk
|
||||
var epochPrice big.Int
|
||||
var epochs abi.ChainEpoch
|
||||
var verified bool
|
||||
|
||||
var a address.Address
|
||||
if from := cctx.String("from"); from != "" {
|
||||
@@ -572,6 +572,53 @@ func interactiveDeal(cctx *cli.Context) error {
|
||||
ask = *a
|
||||
|
||||
// TODO: run more validation
|
||||
state = "verified"
|
||||
case "verified":
|
||||
ts, err := api.ChainHead(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dcap, err := api.StateVerifiedClientStatus(ctx, a, ts.Key())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if dcap == nil {
|
||||
state = "confirm"
|
||||
continue
|
||||
}
|
||||
|
||||
color.Blue(".. checking verified deal eligibility\n")
|
||||
ds, err := api.ClientDealSize(ctx, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if dcap.Uint64() < uint64(ds.PieceSize) {
|
||||
color.Yellow(".. not enough DataCap available for a verified deal\n")
|
||||
state = "confirm"
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Print("\nMake this a verified deal? (yes/no): ")
|
||||
|
||||
var yn string
|
||||
_, err = fmt.Scan(&yn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch yn {
|
||||
case "yes":
|
||||
verified = true
|
||||
case "no":
|
||||
verified = false
|
||||
default:
|
||||
fmt.Println("Type in full 'yes' or 'no'")
|
||||
continue
|
||||
}
|
||||
|
||||
state = "confirm"
|
||||
case "confirm":
|
||||
fromBal, err := api.WalletBalance(ctx, a)
|
||||
@@ -590,10 +637,15 @@ func interactiveDeal(cctx *cli.Context) error {
|
||||
epochs = abi.ChainEpoch(dur / (time.Duration(build.BlockDelaySecs) * time.Second))
|
||||
// TODO: do some more or epochs math (round to miner PP, deal start buffer)
|
||||
|
||||
pricePerGib := ask.Price
|
||||
if verified {
|
||||
pricePerGib = ask.VerifiedPrice
|
||||
}
|
||||
|
||||
gib := types.NewInt(1 << 30)
|
||||
|
||||
// TODO: price is based on PaddedPieceSize, right?
|
||||
epochPrice = types.BigDiv(types.BigMul(ask.Price, types.NewInt(uint64(ds.PieceSize))), gib)
|
||||
epochPrice = types.BigDiv(types.BigMul(pricePerGib, types.NewInt(uint64(ds.PieceSize))), gib)
|
||||
totalPrice := types.BigMul(epochPrice, types.NewInt(uint64(epochs)))
|
||||
|
||||
fmt.Printf("-----\n")
|
||||
@@ -603,6 +655,7 @@ func interactiveDeal(cctx *cli.Context) error {
|
||||
fmt.Printf("Piece size: %s (Payload size: %s)\n", units.BytesSize(float64(ds.PieceSize)), units.BytesSize(float64(ds.PayloadSize)))
|
||||
fmt.Printf("Duration: %s\n", dur)
|
||||
fmt.Printf("Total price: ~%s (%s per epoch)\n", types.FIL(totalPrice), types.FIL(epochPrice))
|
||||
fmt.Printf("Verified: %v\n", verified)
|
||||
|
||||
state = "accept"
|
||||
case "accept":
|
||||
@@ -637,7 +690,7 @@ func interactiveDeal(cctx *cli.Context) error {
|
||||
MinBlocksDuration: uint64(epochs),
|
||||
DealStartEpoch: abi.ChainEpoch(cctx.Int64("start-epoch")),
|
||||
FastRetrieval: cctx.Bool("fast-retrieval"),
|
||||
VerifiedDeal: false, // TODO: Allow setting
|
||||
VerifiedDeal: verified,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -1423,7 +1476,7 @@ func toChannelOutput(useColor bool, otherPartyColumn string, channel lapi.DataTr
|
||||
otherPartyColumn: otherParty,
|
||||
"Root Cid": rootCid,
|
||||
"Initiated?": initiated,
|
||||
"Transferred": channel.Transferred,
|
||||
"Transferred": units.BytesSize(float64(channel.Transferred)),
|
||||
"Voucher": voucher,
|
||||
"Message": channel.Message,
|
||||
}
|
||||
|
||||
+47
-18
@@ -7,6 +7,7 @@ import (
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
cid "github.com/ipfs/go-cid"
|
||||
"github.com/urfave/cli/v2"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
@@ -43,6 +44,10 @@ var mpoolPending = &cli.Command{
|
||||
Name: "local",
|
||||
Usage: "print pending messages for addresses in local wallet only",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "cids",
|
||||
Usage: "only print cids of messages in output",
|
||||
},
|
||||
},
|
||||
Action: func(cctx *cli.Context) error {
|
||||
api, closer, err := GetFullNodeAPI(cctx)
|
||||
@@ -79,11 +84,15 @@ var mpoolPending = &cli.Command{
|
||||
}
|
||||
}
|
||||
|
||||
out, err := json.MarshalIndent(msg, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
if cctx.Bool("cids") {
|
||||
fmt.Println(msg.Cid())
|
||||
} else {
|
||||
out, err := json.MarshalIndent(msg, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -308,21 +317,8 @@ var mpoolReplaceCmd = &cli.Command{
|
||||
Usage: "Spend up to X FIL for this message (applicable for auto mode)",
|
||||
},
|
||||
},
|
||||
ArgsUsage: "[from] [nonce]",
|
||||
ArgsUsage: "<from nonce> | <message-cid>",
|
||||
Action: func(cctx *cli.Context) error {
|
||||
if cctx.Args().Len() < 2 {
|
||||
return cli.ShowCommandHelp(cctx, cctx.Command.Name)
|
||||
}
|
||||
|
||||
from, err := address.NewFromString(cctx.Args().Get(0))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nonce, err := strconv.ParseUint(cctx.Args().Get(1), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
api, closer, err := GetFullNodeAPI(cctx)
|
||||
if err != nil {
|
||||
@@ -332,6 +328,39 @@ var mpoolReplaceCmd = &cli.Command{
|
||||
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
var from address.Address
|
||||
var nonce uint64
|
||||
switch cctx.Args().Len() {
|
||||
case 1:
|
||||
mcid, err := cid.Decode(cctx.Args().First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
msg, err := api.ChainGetMessage(ctx, mcid)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not find referenced message: %w", err)
|
||||
}
|
||||
|
||||
from = msg.From
|
||||
nonce = msg.Nonce
|
||||
case 2:
|
||||
f, err := address.NewFromString(cctx.Args().Get(0))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
n, err := strconv.ParseUint(cctx.Args().Get(1), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
from = f
|
||||
nonce = n
|
||||
default:
|
||||
return cli.ShowCommandHelp(cctx, cctx.Command.Name)
|
||||
}
|
||||
|
||||
ts, err := api.ChainHead(ctx)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("getting chain head: %w", err)
|
||||
|
||||
+3
-2
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hako/durafmt"
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/go-state-types/abi"
|
||||
@@ -36,11 +37,11 @@ func parseTipSet(ctx context.Context, api api.FullNode, vals []string) (*types.T
|
||||
func EpochTime(curr, e abi.ChainEpoch) string {
|
||||
switch {
|
||||
case curr > e:
|
||||
return fmt.Sprintf("%d (%s ago)", e, time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(curr-e)))
|
||||
return fmt.Sprintf("%d (%s ago)", e, durafmt.Parse(time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(curr-e))).LimitFirstN(2))
|
||||
case curr == e:
|
||||
return fmt.Sprintf("%d (now)", e)
|
||||
case curr < e:
|
||||
return fmt.Sprintf("%d (in %s)", e, time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(e-curr)))
|
||||
return fmt.Sprintf("%d (in %s)", e, durafmt.Parse(time.Second*time.Duration(int64(build.BlockDelaySecs)*int64(e-curr))).LimitFirstN(2))
|
||||
}
|
||||
|
||||
panic("math broke")
|
||||
|
||||
Reference in New Issue
Block a user