Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve: add the cmd set-ask and handle the empty deal #190

Merged
merged 6 commits into from
Jan 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve: update printUsage
  • Loading branch information
sonic committed Jan 6, 2023
commit ae20b6dd2ba1adb8c38b77bee6c523de5ea6508d
44 changes: 37 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package main

import (
"context"
"flag"
"fmt"
"github.com/filswan/go-swan-lib/client/boost"
"os"
"os/signal"
"strconv"
"strings"
"swan-provider/common"
"swan-provider/common/constants"
"swan-provider/config"
Expand Down Expand Up @@ -105,11 +105,40 @@ func LoadEnv() {
}

func setAsk() {
price := flag.String("price", "0", "Set the price of the ask for unverified deals (specified as FIL / GiB / Epoch) to `PRICE`.")
verifiedPrice := flag.String("verified-price", "0", "Set the price of the ask for verified deals (specified as FIL / GiB / Epoch) to `PRICE`")
minSize := flag.String("min-piece-size", "256B", "Set minimum piece size (w/bit-padding, in bytes) in ask to `SIZE`")
maxSize := flag.String("max-piece-size", "0", "Set maximum piece size (w/bit-padding, in bytes) in ask to `SIZE`")
flag.Parse()
params := os.Args[2:]
var price, verifiedPrice, minSize, maxSize string
for _, param := range params {
if strings.Contains(param, "verified-price") {
index := strings.Index(param, "=")
verifiedPrice = param[index+1:]
} else if strings.Contains(param, "min-piece-size") {
index := strings.Index(param, "=")
minSize = param[index+1:]
} else if strings.Contains(param, "max-piece-size") {
index := strings.Index(param, "=")
maxSize = param[index+1:]
} else if strings.Contains(param, "price") {
index := strings.Index(param, "=")
price = param[index+1:]
}
}

if price == "" {
logs.GetLogger().Errorf("price is required")
return
}
if verifiedPrice == "" {
logs.GetLogger().Errorf("verified-price is required")
return
}
if minSize == "" {
logs.GetLogger().Errorf("min-piece-size is required")
return
}
if maxSize == "" {
logs.GetLogger().Errorf("max-piece-size is required")
return
}

market := config.GetConfig().Market
boostToken, err := service.GetBoostToken(market.Repo)
Expand All @@ -123,7 +152,8 @@ func setAsk() {
return
}
defer closer()
if err = boostClient.MarketSetAsk(context.TODO(), *price, *verifiedPrice, *minSize, *maxSize); err != nil {

if err = boostClient.MarketSetAsk(context.TODO(), price, verifiedPrice, minSize, maxSize); err != nil {
logs.GetLogger().Error(err)
}
}