This repository has been archived on 2024-04-07. You can view files and clone it, but cannot push or open issues or pull requests.
go-monero/cmd/monero/commands/wallet/auto_refresh.go
2022-10-05 09:40:23 +02:00

60 lines
1.2 KiB
Go

package wallet
import (
"fmt"
"time"
"github.com/spf13/cobra"
"git.gammaspectra.live/P2Pool/go-monero/cmd/monero/options"
"git.gammaspectra.live/P2Pool/go-monero/pkg/rpc/wallet"
)
type autoRefreshCommand struct {
Enable bool
Period time.Duration
}
func (c *autoRefreshCommand) Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "auto-refresh",
Short: "configure wallet-rpc to automatically refresh or not",
RunE: c.RunE,
}
cmd.Flags().BoolVar(&c.Enable, "enable",
true, "enable the ability to auto-refresh")
cmd.Flags().DurationVar(&c.Period, "period",
90*time.Second, "how often to automatically refresh")
return cmd
}
func (c *autoRefreshCommand) RunE(_ *cobra.Command, _ []string) error {
ctx, cancel := options.RootOpts.Context()
defer cancel()
client, err := options.RootOpts.WalletClient()
if err != nil {
return fmt.Errorf("client: %w", err)
}
resp, err := client.AutoRefresh(ctx, c.Enable, int64(c.Period.Seconds()))
if err != nil {
return fmt.Errorf("auto refresh: %w", err)
}
c.pretty(resp)
return nil
}
// nolint:forbidigo
func (c *autoRefreshCommand) pretty(v *wallet.AutoRefreshResult) {
fmt.Println("OK")
}
func init() {
RootCommand.AddCommand((&autoRefreshCommand{}).Cmd())
}