wallet

package
v0.5.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: Apache-2.0, MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ImportCmd = &cli.Command{
	Name:      "import",
	Usage:     "Import a wallet from exported private key",
	ArgsUsage: "[path, or stdin if omitted]",
	Action: func(c *cli.Context) error {
		db, closer, err := database.OpenFromCLI(c)
		if err != nil {
			return errors.WithStack(err)
		}
		defer closer.Close()

		var privateKey string
		if c.Args().Len() > 0 {
			privateKeyBytes, err := os.ReadFile(c.Args().Get(0))
			if err != nil {
				return errors.WithStack(err)
			}
			privateKey = string(privateKeyBytes)
		} else {
			scanner := bufio.NewScanner(os.Stdin)
			fmt.Print("Enter the private key: ")
			if scanner.Scan() {
				privateKey = scanner.Text()
			} else {
				return errors.Wrap(scanner.Err(), "failed to read from stdin")
			}
		}

		lotusClient := util.NewLotusClient(c.String("lotus-api"), c.String("lotus-token"))
		w, err := wallet.Default.ImportHandler(
			c.Context,
			db,
			lotusClient,
			wallet.ImportRequest{
				PrivateKey: privateKey,
			})
		if err != nil {
			return errors.WithStack(err)
		}

		cliutil.Print(c, w)
		return nil
	},
}
View Source
var ListCmd = &cli.Command{
	Name:  "list",
	Usage: "List all imported wallets",
	Action: func(c *cli.Context) error {
		db, closer, err := database.OpenFromCLI(c)
		if err != nil {
			return errors.WithStack(err)
		}
		defer closer.Close()
		wallets, err := wallet.Default.ListHandler(c.Context, db)
		if err != nil {
			return errors.WithStack(err)
		}

		cliutil.Print(c, wallets)
		return nil
	},
}
View Source
var RemoveCmd = &cli.Command{
	Name:      "remove",
	Usage:     "Remove a wallet",
	ArgsUsage: "<address>",
	Before:    cliutil.CheckNArgs,
	Flags: []cli.Flag{
		cliutil.ReallyDotItFlag,
	},
	Action: func(c *cli.Context) error {
		if err := cliutil.HandleReallyDoIt(c); err != nil {
			return errors.WithStack(err)
		}
		db, closer, err := database.OpenFromCLI(c)
		if err != nil {
			return errors.WithStack(err)
		}
		defer closer.Close()
		return wallet.Default.RemoveHandler(c.Context, db, c.Args().Get(0))
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL