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

Add a bulk subscribe option to chia-data #33

Merged
merged 1 commit into from
Oct 3, 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
54 changes: 54 additions & 0 deletions cmd/datalayer/bulksub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package datalayer

import (
"encoding/json"
"os"

"github.com/chia-network/go-chia-libs/pkg/rpc"
"github.com/chia-network/go-modules/pkg/slogs"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// bulkSubCmd Subscribes to multiple datastores at once using the output of chia data get_subscriptions
var bulkSubCmd = &cobra.Command{
Use: "bulk-subscribe",
Short: "Subscribes to multiple datastores at once using the output of chia data get_subscriptions",
Example: "chia-tools data bulk-subscribe -f subscriptions.json",
//Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
client, err := rpc.NewClient(rpc.ConnectionModeHTTP, rpc.WithAutoConfig())
if err != nil {
slogs.Logr.Fatal("error creating chia RPC client", "error", err)
}

jsonFile := viper.GetString("bulksub-file")
content, err := os.ReadFile(jsonFile)
if err != nil {
slogs.Logr.Fatal("Unable to read input file", "error", err)
}

subs := &rpc.DatalayerGetSubscriptionsResponse{}
err = json.Unmarshal(content, subs)
if err != nil {
slogs.Logr.Fatal("Could not parse the subscriptions json file", "error", err)
}

for _, id := range subs.StoreIDs {
slogs.Logr.Info("Subscription to store", "id", id)
_, _, err = client.DataLayerService.Subscribe(&rpc.DatalayerSubscribeOptions{
ID: id,
})
if err != nil {
slogs.Logr.Error("Error subscribing to datastore", "id", id, "error", err)
}
}
},
}

func init() {
bulkSubCmd.PersistentFlags().StringP("file", "f", "", "The file containing the json of subscriptions to add")
cobra.CheckErr(viper.BindPFlag("bulksub-file", bulkSubCmd.PersistentFlags().Lookup("file")))

datalayerCmd.AddCommand(bulkSubCmd)
}
1 change: 0 additions & 1 deletion cmd/network/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ var switchCmd = &cobra.Command{
slogs.Logr.Fatal("selected network does not exist in config's network override config", "network", networkName)
}


// Ensure a folder to store the current network's sub-epoch-summaries and height-to-hash files exists
cacheFileDirOldNetwork := path.Join(chiaRoot, "db", currentNetwork)
cacheFileDirNewNetwork := path.Join(chiaRoot, "db", networkName)
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ var (

// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "chia-tools",
Short: "Collection of CLI tools for working with Chia Blockchain",
Use: "chia-tools",
Short: "Collection of CLI tools for working with Chia Blockchain",
Version: fmt.Sprintf("%s (%s)", gitVersion, buildTime),
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/chia-network/chia-tools
go 1.22.4

require (
github.com/chia-network/go-chia-libs v0.15.5
github.com/chia-network/go-chia-libs v0.15.6
github.com/chia-network/go-modules v0.0.7
github.com/spf13/cast v1.7.0
github.com/spf13/cobra v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/chia-network/go-chia-libs v0.15.5 h1:HsBhOnxHuriOLVqJiQQu+8egirQxjA2Qt2Iz6nS7K4A=
github.com/chia-network/go-chia-libs v0.15.5/go.mod h1:npTqaFSjTdMxE7hc0LOmWJmWGqcs+IERarK5fDxXk/I=
github.com/chia-network/go-chia-libs v0.15.6 h1:8XxvR9EQKFSnIZtGzCsSlsy4BpWSIJsEHxut/wZR1WU=
github.com/chia-network/go-chia-libs v0.15.6/go.mod h1:npTqaFSjTdMxE7hc0LOmWJmWGqcs+IERarK5fDxXk/I=
github.com/chia-network/go-modules v0.0.7 h1:l3EV5rGrE2Rvoxyhbxfk4cZy2Pc/l2hNQ54pmB/+NE4=
github.com/chia-network/go-modules v0.0.7/go.mod h1:ZoHvOfnjNj3ydtJxXMxBxM0fBXMWiPlj13IlYgpSj8I=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down