Skip to content

Commit

Permalink
basevm actions passing
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Jul 22, 2023
1 parent 653c33f commit 33dafbe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion examples/basevm/cmd/base-cli/cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd
import (
"context"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/hypersdk/examples/basevm/actions"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -39,7 +40,7 @@ var transferCmd = &cobra.Command{
}

// Select amount
amount, err := handler.Root().PromptAmount("amount", balance, nil)
amount, err := handler.Root().PromptAmount("amount", ids.Empty, balance, nil)
if err != nil {
return err
}
Expand Down
25 changes: 25 additions & 0 deletions examples/basevm/cmd/base-cli/cmd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
brpc "github.com/ava-labs/hypersdk/examples/basevm/rpc"
"github.com/ava-labs/hypersdk/examples/basevm/utils"
"github.com/ava-labs/hypersdk/rpc"
hutils "github.com/ava-labs/hypersdk/utils"
)

var _ cli.Controller = (*Controller)(nil)
Expand Down Expand Up @@ -55,6 +56,30 @@ func (h *Handler) DefaultActor() (
), nil
}

func (h *Handler) GetBalance(
ctx context.Context,
cli *brpc.JSONRPCClient,
publicKey crypto.PublicKey,
) (uint64, error) {
addr := utils.Address(publicKey)
balance, err := cli.Balance(ctx, addr)
if err != nil {
return 0, err
}
if balance == 0 {
hutils.Outf("{{red}}balance:{{/}} 0 %s\n", consts.Symbol)
hutils.Outf("{{red}}please send funds to %s{{/}}\n", addr)
hutils.Outf("{{red}}exiting...{{/}}\n")
return 0, nil
}
hutils.Outf(
"{{yellow}}balance:{{/}} %s %s\n",
hutils.FormatBalance(balance),
consts.Symbol,
)
return balance, nil
}

type Controller struct {
databasePath string
}
Expand Down

0 comments on commit 33dafbe

Please sign in to comment.