Skip to content

Commit

Permalink
Fix populate script (#135)
Browse files Browse the repository at this point in the history
* Add `--token` and `--path` options to `send bounty` cmd

* Fix populate script
  • Loading branch information
guidanoli authored Aug 12, 2024
1 parent f6e8939 commit dd52633
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 158 deletions.
45 changes: 33 additions & 12 deletions cli/cmd/bounty.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/spf13/cobra"
)

Expand All @@ -18,32 +19,45 @@ var bountyCmd = &cobra.Command{
}

var (
bountyName string
bountyImgLink string
bountyDescription string
bountyDuration int64
bountyCodePath string
bountyName string
bountyImgLink string
bountyDescription string
bountyDuration int64
bountyCodePathInMachine string
bountyCodePathInHost string
bountyToken string
)

func bountyRun(cmd *cobra.Command, args []string) {
code, err := bountyLoadCode()
if err != nil {
log.Fatal(err)
var codeZipBinary *string
if bountyCodePathInHost != "" {
code, err := bountyLoadCode()
if err != nil {
log.Fatal(err)
}
codeZipBinary = &code
}
var codeZipPath *string
if bountyCodePathInMachine != "" {
codeZipPath = &bountyCodePathInMachine
}
durationSecs := time.Duration(bountyDuration) * time.Second
deadline := time.Now().UTC().Add(durationSecs).Unix()
token := common.HexToAddress(bountyToken)
payload := &shared.CreateAppBounty{
Name: bountyName,
ImgLink: bountyImgLink,
Description: bountyDescription,
Deadline: deadline,
CodeZipBinary: &code,
CodeZipBinary: codeZipBinary,
CodeZipPath: codeZipPath,
Token: token,
}
sendInput(shared.CreateAppBountyInputKind, payload)
}

func bountyLoadCode() (string, error) {
f, err := os.Open(bountyCodePath)
f, err := os.Open(bountyCodePathInHost)
if err != nil {
log.Fatalf("failed to open code zip: %v", err)
}
Expand Down Expand Up @@ -78,6 +92,13 @@ func init() {
&bountyDuration, "duration", 24*60*60, "duration of the bounty in secods")

bountyCmd.Flags().StringVarP(
&bountyCodePath, "code", "c", "", "Path to the code zip")
bountyCmd.MarkFlagRequired("code")
&bountyCodePathInHost, "code", "c", "", "Path to the code zip (in the host filesystem)")
bountyCmd.Flags().StringVarP(
&bountyCodePathInMachine, "path", "p", "", "Path to the code zip (in the machine filesystem)")
bountyCmd.MarkFlagsOneRequired("code", "path")
bountyCmd.MarkFlagsMutuallyExclusive("code", "path")

bountyCmd.Flags().StringVarP(
&bountyToken, "token", "t", "", "Token address")
bountyCmd.MarkFlagRequired("token")
}
Loading

0 comments on commit dd52633

Please sign in to comment.