credit

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package credit provides subcommands to manage the credits of an user.

USAGE:

dps credit command [command options] [arguments...]

COMMANDS:

transfer  Transfer credits to an another account
get       Get the amount of credits owned by you or an user (if first argument is specified).

Index

Constants

This section is empty.

Variables

View Source
var Command = cli.Command{
	Name:  "credit",
	Usage: "Manage credits.",
	Subcommands: []*cli.Command{
		{
			Name:      "transfer",
			Usage:     "Transfer credits to an another account",
			ArgsUsage: "<0x recipient address> <amount>",
			Flags:     flags,
			Action: func(cCtx *cli.Context) error {
				if cCtx.NArg() < 2 {
					return errors.New("missing arguments")
				}
				if wei {
					c, ok := new(big.Int).SetString(cCtx.Args().Get(1), 10)
					if !ok {
						return errors.New("couldn't parse amount")
					}
					creditsWei = c
					credits = ether.FromWei(creditsWei)
				} else {
					c, ok := new(big.Float).SetString(cCtx.Args().Get(1))
					if !ok {
						return errors.New("couldn't parse amount")
					}
					credits = c
					creditsWei = ether.ToWei(credits)
				}
				ctx := cCtx.Context
				recipient := common.HexToAddress(cCtx.Args().First())
				clientset, err := initClient(ctx)
				if err != nil {
					return err
				}

				if !force {
					msg := fmt.Sprintf(
						"Confirm transfer of %s credits (%s wei) to %s?",
						credits.String(),
						creditsWei.String(),
						recipient.Hex(),
					)
					input := confirmation.New(msg, confirmation.No)
					ok, err := input.RunPrompt()
					if err != nil {
						return err
					}
					if !ok {
						fmt.Println("Cancelled.")
						return nil
					}
				}

				if err := clientset.CreditManager().Transfer(ctx, recipient, creditsWei); err != nil {
					return err
				}

				fmt.Println("Done.")
				return nil
			},
		},
		{
			Name:      "get",
			Usage:     "Get the amount of credits owned by you or an user (if first argument is specified).",
			ArgsUsage: "(0x)",
			Flags:     flags,
			Action: func(cCtx *cli.Context) error {
				ctx := cCtx.Context
				clientset, err := initClient(ctx)
				if err != nil {
					return err
				}

				var amount *big.Int
				if cCtx.NArg() >= 1 {
					amount, err = clientset.CreditManager().
						BalanceOf(ctx, common.HexToAddress(cCtx.Args().First()))
					if err != nil {
						return err
					}
				} else {
					amount, err = clientset.CreditManager().Balance(ctx)
					if err != nil {
						return err
					}
				}

				if wei {
					fmt.Println(amount.String())
				} else {
					fmt.Println(ether.FromWei(amount).String())
				}

				return nil
			},
		},
	},
}

Command is the credit subcommand used to manage credits.

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