Skip to content

Commit

Permalink
reduce diff
Browse files Browse the repository at this point in the history
  • Loading branch information
samliok committed Nov 7, 2024
1 parent 78bfd53 commit 8141f8b
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/morpheusvm/vm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ import (
"context"
"encoding/json"
"strings"
"time"

"github.com/ava-labs/hypersdk/api/jsonrpc"
"github.com/ava-labs/hypersdk/chain"
"github.com/ava-labs/hypersdk/codec"
"github.com/ava-labs/hypersdk/examples/morpheusvm/consts"
"github.com/ava-labs/hypersdk/genesis"
"github.com/ava-labs/hypersdk/requester"
"github.com/ava-labs/hypersdk/utils"
)

const balanceCheckInterval = 500 * time.Millisecond

type JSONRPCClient struct {
requester *requester.EndpointRequester
g *genesis.DefaultGenesis
Expand Down Expand Up @@ -60,6 +65,28 @@ func (cli *JSONRPCClient) Balance(ctx context.Context, addr codec.Address) (uint
return resp.Amount, err
}

func (cli *JSONRPCClient) WaitForBalance(
ctx context.Context,
addr codec.Address,
min uint64,
) error {
return jsonrpc.Wait(ctx, balanceCheckInterval, func(ctx context.Context) (bool, error) {
balance, err := cli.Balance(ctx, addr)
if err != nil {
return false, err
}
shouldExit := balance >= min
if !shouldExit {
utils.Outf(
"{{yellow}}waiting for %s balance: %s{{/}}\n",
utils.FormatBalance(min),
addr,
)
}
return shouldExit, nil
})
}

func (cli *JSONRPCClient) Parser(ctx context.Context) (chain.Parser, error) {
g, err := cli.Genesis(ctx)
if err != nil {
Expand Down

0 comments on commit 8141f8b

Please sign in to comment.