From 7c92fd39163566516e29f83365711fff6813c4b8 Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Fri, 2 Jun 2023 17:17:12 +0800 Subject: [PATCH] opt: add flag --miner for batch deal command --- cmd/market-client/storage.go | 36 +++++++++++-------- ...71\351\207\217\345\217\221\345\215\225.md" | 7 ++-- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/cmd/market-client/storage.go b/cmd/market-client/storage.go index 105ddede..6fdc708b 100644 --- a/cmd/market-client/storage.go +++ b/cmd/market-client/storage.go @@ -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 } @@ -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 }, @@ -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) @@ -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 } @@ -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 '. 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", @@ -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) @@ -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 } diff --git "a/docs/zh/\346\211\271\351\207\217\345\217\221\345\215\225.md" "b/docs/zh/\346\211\271\351\207\217\345\217\221\345\215\225.md" index 951991c2..76b56bbf 100644 --- "a/docs/zh/\346\211\271\351\207\217\345\217\221\345\215\225.md" +++ "b/docs/zh/\346\211\271\351\207\217\345\217\221\345\215\225.md" @@ -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 就是本次预期发布的订单总数 @@ -46,10 +47,10 @@ bafybeigq66gjr6c6junro7t4fwcpkhl7vpowi3soadksjvleusq6nlzu6a,test-total-19-part-4 1. 发布普通离线订单 ``` -./market-client storage deals batch --from
--manifest --end-index 10 --start-index 5 t019150,t018682 0 518400 +./market-client storage deals batch --from
--manifest --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 @@ -62,7 +63,7 @@ create deal success, proposal cid: bafyreigtemnxftqg65gtwsw3rwfvqaqzbb47d4r75ipk > 请加上 --verified-deal flag ``` -./market-client storage deals batch --from
--manifest --end-index 15 --start-index 10 --verified-deal t019150,t018682 0 518400 +./market-client storage deals batch --from
--manifest --end-index 15 --start-index 10 --verified-deal --miner=t019150 --miner=t018682 0 518400 ``` ### 查询订单