Skip to content

Commit

Permalink
opt: add flag --miner for batch deal command
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Jun 2, 2023
1 parent f409ae1 commit 7c92fd3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
36 changes: 22 additions & 14 deletions cmd/market-client/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ The minimum value is 518400 (6 months).`,
}

// [data, miner, price, dur]
p, err := dealParamsFromContext(cctx, api, fapi)
p, err := dealParamsFromContext(cctx, api, fapi, false)
if err != nil {
return err
}
Expand Down Expand Up @@ -530,7 +530,7 @@ The minimum value is 518400 (6 months).`,
return err
}

afmt.Println(encoder.Encode(*proposal))
afmt.Println("proposal cid: ", encoder.Encode(*proposal))

return nil
},
Expand Down Expand Up @@ -1508,16 +1508,21 @@ type params struct {
dcap uint64
}

func dealParamsFromContext(cctx *cli.Context, api clientapi.IMarketClient, fapi v1api.FullNode) (*params, error) {
func dealParamsFromContext(cctx *cli.Context, api clientapi.IMarketClient, fapi v1api.FullNode, isBatch bool) (*params, error) {
var start int
var addrs []string
var miners []address.Address
if cctx.Args().Len() == 4 {
start = 1
if !isBatch {
// [data, miner, price, dur]
start = 2
addrs = []string{cctx.Args().Get(1)}
} else {
// [price, dur]
addrs = cctx.StringSlice("miner")
}

addrs := strings.Split(cctx.Args().Get(start), ",")
if len(addrs) == 0 {
return nil, fmt.Errorf("invalid miner %s", cctx.Args().Get(start))
return nil, fmt.Errorf("must pass miner")
}
for _, addrStr := range addrs {
miner, err := address.NewFromString(addrStr)
Expand All @@ -1527,11 +1532,11 @@ func dealParamsFromContext(cctx *cli.Context, api clientapi.IMarketClient, fapi
miners = append(miners, miner)
}

price, err := types.ParseFIL(cctx.Args().Get(start + 1))
price, err := types.ParseFIL(cctx.Args().Get(start))
if err != nil {
return nil, err
}
dur, err := strconv.ParseInt(cctx.Args().Get(start+2), 10, 32)
dur, err := strconv.ParseInt(cctx.Args().Get(start+1), 10, 32)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1609,14 +1614,17 @@ var storageDelesBatchCmd = &cli.Command{
Name: "batch",
Usage: "Batch storage deals with miners",
Description: `Make deals with miners.
miners is the address of the miners you wish to make a deal with, eg. t010001,t010003,t010004.
price is measured in FIL/Epoch. Miners usually don't accept a bid
lower than their advertised ask (which is in FIL/GiB/Epoch). You can check a miners listed price
with './market-client storage asks query <miner address>'.
duration is how long the miner should store the data for, in blocks.
The minimum value is 518400 (6 months).`,
ArgsUsage: "[miners price duration]",
ArgsUsage: "[price duration]",
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "miner",
Usage: "The address of the miner you wish to make a deal with, eg. --miner t010001 --miner t010002",
},
&cli.StringFlag{
Name: "manifest",
Usage: "Path to the manifest file",
Expand Down Expand Up @@ -1660,8 +1668,8 @@ The minimum value is 518400 (6 months).`,
&cli2.CidBaseFlag,
},
Action: func(cctx *cli.Context) error {
if cctx.NArg() != 3 {
return fmt.Errorf("must pass three arguments")
if cctx.NArg() != 2 {
return fmt.Errorf("must pass two arguments")
}

fapi, fcloser, err := cli2.NewFullNode(cctx)
Expand All @@ -1677,7 +1685,7 @@ The minimum value is 518400 (6 months).`,
defer closer()

ctx := cli2.ReqContext(cctx)
p, err := dealParamsFromContext(cctx, api, fapi)
p, err := dealParamsFromContext(cctx, api, fapi, true)
if err != nil {
return err
}
Expand Down
7 changes: 4 additions & 3 deletions docs/zh/批量发单.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

部分 Option:

* --miner 接收订单的矿工,可以是多个 `--miner=t010001` `--miner=t010002`,多个会平均分配订单。
* --manifest `go-graphsplit` 生成的 `manifest.csv` 文件,包含 `payload cid``piece cid``piece size` 等信息
* --start-index 从 `manifest.csv` 第 N 条订单开始
* --end-index 在 `manifest.csv` 第 N 条订单结束,start-index - end-index 就是本次预期发布的订单总数
Expand Down Expand Up @@ -46,10 +47,10 @@ bafybeigq66gjr6c6junro7t4fwcpkhl7vpowi3soadksjvleusq6nlzu6a,test-total-19-part-4

1. 发布普通离线订单
```
./market-client storage deals batch --from <address> --manifest <path-to-manifest.csv> --end-index 10 --start-index 5 t019150,t018682 0 518400
./market-client storage deals batch --from <address> --manifest <path-to-manifest.csv> --end-index 10 --start-index 5 --miner=t019150 --miner=t018682 0 518400
# 结果
has 5 deals need to publish, t018682: 3 , t019150: 2
has 5 deals need to publish, t018682: 3, t019150: 2
create deal success, proposal cid: bafyreihwvsr3vfsdbrxagtdjzsemngtc3r3xra2gaunbs6pjb63lyodl6a
create deal success, proposal cid: bafyreid2oakcs2di6lq5mv3e4h5sybkezl3zn7lhvf656zeqentcsqetem
create deal success, proposal cid: bafyreidmzdh7zee7inm65cdxmuwyxyv7uwtoo2hiphsjfseyymoir2z4nm
Expand All @@ -62,7 +63,7 @@ create deal success, proposal cid: bafyreigtemnxftqg65gtwsw3rwfvqaqzbb47d4r75ipk
> 请加上 --verified-deal flag
```
./market-client storage deals batch --from <address> --manifest <path-to-manifest.csv> --end-index 15 --start-index 10 --verified-deal t019150,t018682 0 518400
./market-client storage deals batch --from <address> --manifest <path-to-manifest.csv> --end-index 15 --start-index 10 --verified-deal --miner=t019150 --miner=t018682 0 518400
```

### 查询订单
Expand Down

0 comments on commit 7c92fd3

Please sign in to comment.