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

Fix populate script #135

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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