Skip to content

Commit

Permalink
Merge pull request #46 from CoopHive/hive-inspect
Browse files Browse the repository at this point in the history
hive inspect
  • Loading branch information
mlegls authored May 31, 2024
2 parents ee775e5 + 6db89ed commit 7008d2e
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 6 deletions.
55 changes: 55 additions & 0 deletions cmd/hive/inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package hive

import (
"encoding/json"
"fmt"

"github.com/CoopHive/coophive/pkg/inspect"
optionsfactory "github.com/CoopHive/coophive/pkg/options"
"github.com/CoopHive/coophive/pkg/web3"
"github.com/spf13/cobra"
)

func newInspectCmd() *cobra.Command {
options := optionsfactory.NewInspectOptions()
runCmd := &cobra.Command{
Use: "inspect",
Short: "View metadata for a previously run job.",
Long: "View metadata for a previously run job.",
Example: "inspect cowsay:v0.0.1 -i Message=moo",
RunE: func(cmd *cobra.Command, args []string) error {

options, err := optionsfactory.ProcessInspectOptions(options, args)
if err != nil {
return err
}
return inspectJob(cmd, options)
},
}
optionsfactory.AddInspectCliFlags(runCmd, &options)
return runCmd
}

func inspectJob(cmd *cobra.Command, options inspect.InspectOptions) error {
web3SDK, err := web3.NewContractSDK(options.Web3)
if err != nil {
return err
}

fmt.Printf("deal id: %s\n", options.DealID)

dealData, err := web3SDK.Contracts.Storage.GetDeal(web3SDK.CallOpts, options.DealID)
if err != nil {
return err
}

jsonBytes, err := json.Marshal(dealData)
if err != nil {
return err
}

jsonString := string(jsonBytes)
fmt.Println(jsonString)

return nil
}
1 change: 1 addition & 0 deletions cmd/hive/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func NewRootCmd() *cobra.Command {
RootCmd.AddCommand(newMediatorCmd())
RootCmd.AddCommand(newJobCreatorCmd())
RootCmd.AddCommand(newSaasApiCmd())
RootCmd.AddCommand(newInspectCmd())
return RootCmd
}

Expand Down
16 changes: 10 additions & 6 deletions cmd/hive/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,16 @@ Generic Decentralized Compute Network https://github.com/CoopHive/coophive
return err
}
spinner.Stop()
fmt.Printf("\n🍂 Generic Decentralized Compute Network job completed, try 👇\n open %s\n cat %s/stdout\n cat %s/stderr\n https://ipfs.io/ipfs/%s\n",
solver.GetDownloadsFilePath(result.JobOffer.DealID),
solver.GetDownloadsFilePath(result.JobOffer.DealID),
solver.GetDownloadsFilePath(result.JobOffer.DealID),
result.Result.DataID,
)

downloadFilePath := solver.GetDownloadsFilePath(result.JobOffer.DealID)
fmt.Printf("\n🍂 Generic Decentralized Compute Network job completed, try 👇\n")
fmt.Printf("\topen %s\n", downloadFilePath)
fmt.Printf("\tcat %s/stdout\n", downloadFilePath)
fmt.Printf("\tcat %s/stderr\n", downloadFilePath)
fmt.Printf("\thttps://ipfs.io/ipfs/%s\n", result.Result.DataID)

fmt.Printf("\nFor more details try: hive inspect %s\n", result.JobOffer.DealID)

return err
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/inspect/inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package inspect

import "github.com/CoopHive/coophive/pkg/web3"

type InspectOptions struct {
Web3 web3.Web3Options
DealID string
}
48 changes: 48 additions & 0 deletions pkg/options/inspect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package options

import (
"github.com/CoopHive/coophive/pkg/inspect"
"github.com/CoopHive/coophive/pkg/system"
"github.com/spf13/cobra"
)

func NewInspectOptions() inspect.InspectOptions {
options := inspect.InspectOptions{
Web3: GetDefaultWeb3Options(),
DealID: "",
}
options.Web3.Service = system.JobCreatorService
return options
}

func ProcessInspectOptions(options inspect.InspectOptions, args []string) (inspect.InspectOptions, error) {
dealId := ""
if len(args) == 1 {
dealId = args[0]
}

if dealId != "" {
options.DealID = dealId
}
newWeb3Options, err := ProcessWeb3Options(options.Web3)
if err != nil {
return options, err
}
options.Web3 = newWeb3Options

return options, CheckInspectOptions(options)
}

func CheckInspectOptions(options inspect.InspectOptions) error {
err := CheckWeb3Options(options.Web3)
if err != nil {
return err
}

// TODO validate dealID
return nil
}

func AddInspectCliFlags(cmd *cobra.Command, options *inspect.InspectOptions) {
AddWeb3CliFlags(cmd, &options.Web3)
}
2 changes: 2 additions & 0 deletions stack
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ function faucet() {
local tokenAddress=$(echo -n "$WEB3_TOKEN_ADDRESS" | sed 's/^0x//')
if [[ -n $LOCAL_GETH ]]; then
export WEB3_PROVIDER=${WEB3_PROVIDER:="http://host.docker.internal:8545"}
echo provider: $WEB3_PROVIDER
echo docker network: $GETH_DOCKER_NETWORK
else
export WEB3_PROVIDER=${WEB3_PROVIDER:="http://geth:8545"}
fi
Expand Down

0 comments on commit 7008d2e

Please sign in to comment.