Skip to content

Commit

Permalink
[tokenvm] GUI (ava-labs#411)
Browse files Browse the repository at this point in the history
* add token-browser

* first run content

* add design/router

* create routes shell

* stub keys/chains

* basic working gui

* it works

* update go mod

* making progress

* example works

* use uint64

* add conditional failed formatting

* add basic logos

* add basic chart example

* add plots lib

* add basic graphs

* fix flashing animation

* fetch address and balance

* cleanup navbar

* add token balance tracking

* use table for navbar

* use drawer for mint

* use await for fetching balance

* cleanup more async logic

* add trade to bar

* update wording on file

* add support for symbol/supply

* remove modifyAsset

* update rpc

* update cli action

* put faucet after explorer

* add more args to asset

* [tokenvm] Add symbol+decimals (ava-labs#458)

* revamp cli args

* progress

* use original symbol and decimals for warp tokens

* fix key

* fix actions

* cache asset calls

* update tx parsing

* fix token-cli actions

* token-cli compiles

* morepheus-cli compiles

* integration compiles

* fix cache stale

* integration tests pass

* fix lint

* fix e2e

* more lint fixes

* add license files

* reduce max symbol size

* remove unnecessary casts

* move to token-wallet

* update name

* add txs to balance drawer

* use decimals with tokens

* token minting works

* add basic tx parsing

* add basic tx history

* add mint button

* mint works

* mint tx parsing

* clear form earlier

* auto-populate self-address on mint

* add message for processing

* token type formatting

* add basic mine page

* Add PoW Faucet (ava-labs#461)

* add basic challenge implementation

* add client implementation

* add basic challenge implementation

* implement send from within controller

* perform some cleanup

* add faucet implementation

* add token-cli implementation

* faucet command working

* add better viz

* add dynamic difficulty

* make sure to reset lastRotation

* work on standalone token faucet

* add stock server

* slim down server

* remove aliases

* more progress

* implement handler

* more cleanup

* move server to root

* basic facuet compiling

* migrate to logger

* faucet works e2e

* use proper packages

* remove faucet from vm

* remove faucet from script

* add missing headers

* use atomic in challenge

* use 0.1

* add missing headers

* fix linter

* remove todo

* store private key as bytes

* basic gui faucet

* overlapping notifications

* notifications working across app

* remove side layout on mint

* basic functionality without address book

* Address Book (ava-labs#465)

* working on address book

* add basic side spacing

* add minimal address book addition

* fix clear screen issue

* address book parsing works

* add me to address book

* address book for mint

* limit width of views

* fix footer view

* Token Trading (ava-labs#467)

* basic impl

* add basic icon for in/out

* fix order book spacing

* asset switching works

* add basic handling of addition

* support add asset check

* add basic order viewing

* fill order works

* add explanation blocks

* define createOrder function

* creating orders works

* trading works

* add tx tracking for all trades

* make parsing more efficient

* change action history name

* remove verbose logs

* don't faucet if fee too high

* [GUI] Use Persistent Storage + Fix App Icon (ava-labs#469)

* use homedir

* update logo

* use different appicon import

* save dawin plist

* fix floating navbar

* cleanup context usage

* cleanup app.go

* add min height

* backend passing

* cleaning up app

* fix store asset check

* prevent duplicate add assets

* add address persistence

* store solutiosn

* move everything to db

* fix off-by-1 address

* all working

* use prettier formatting

* fix lint

* remove unused font

* open to all hosts

* typo

* update http host

* fix hosts flag

* debugging binary build

* update build script

* Add api proxy (ava-labs#471)

* add proxy script

* fix log

* use long-lived port

* revert navbar changes for now

* commit root index

* Disable actions + warning when no funds (ava-labs#476)

* fix path selection

* add FundsCheck to pages

* use window for has balance check

* disable buttons if no balance

* treat index as explorer

* add placeholder text for funds check

* formatting

* [tokenvm] Transfer.Memo (ava-labs#478)

* memo passing integration tests

* add memo to UI

* UI updated for memo

* Micropayment example (ava-labs#479)

* set version to 0.0.0

* nit

* cleanup faucet page

* update wording on mint

* add popover for explorer

* add explanation for Trade

* finish populating popovers

* linter
  • Loading branch information
patrick-ogrady authored Sep 20, 2023
1 parent 330e9be commit 838307c
Show file tree
Hide file tree
Showing 121 changed files with 12,057 additions and 631 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dist/
tmp-storage-testing
.token-cli*
.morpheus-cli*
*.html
*.coverage.html
data/
osxcross/

Expand Down
8 changes: 8 additions & 0 deletions chain/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ func (b *StatefulBlock) Size() int {
return b.size
}

func (b *StatefulBlock) ID() (ids.ID, error) {
blk, err := b.Marshal()
if err != nil {
return ids.ID{}, err
}
return utils.ToID(blk), nil
}

// warpJob is used to signal to a listner that a *warp.Message has been
// verified.
type warpJob struct {
Expand Down
1 change: 1 addition & 0 deletions cli/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type Controller interface {
DatabasePath() string
Symbol() string
Decimals() uint8
Address(ed25519.PublicKey) string
ParseAddress(string) (ed25519.PublicKey, error)
}
6 changes: 3 additions & 3 deletions cli/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (h *Handler) SetKey(lookupBalance func(int, string, string, uint32, ids.ID)
utils.Outf("{{red}}no stored keys{{/}}\n")
return nil
}
chainID, uris, err := h.GetDefaultChain()
chainID, uris, err := h.GetDefaultChain(true)
if err != nil {
return err
}
Expand Down Expand Up @@ -90,11 +90,11 @@ func (h *Handler) SetKey(lookupBalance func(int, string, string, uint32, ids.ID)
}

func (h *Handler) Balance(checkAllChains bool, promptAsset bool, printBalance func(ed25519.PublicKey, string, uint32, ids.ID, ids.ID) error) error {
priv, err := h.GetDefaultKey()
priv, err := h.GetDefaultKey(true)
if err != nil {
return err
}
chainID, uris, err := h.GetDefaultChain()
chainID, uris, err := h.GetDefaultChain(true)
if err != nil {
return err
}
Expand Down
37 changes: 7 additions & 30 deletions cli/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (h *Handler) PromptAsset(label string, allowNative bool) (ids.ID, error) {

func (*Handler) PromptAmount(
label string,
assetID ids.ID,
decimals uint8,
balance uint64,
f func(input uint64) error,
) (uint64, error) {
Expand All @@ -104,13 +104,7 @@ func (*Handler) PromptAmount(
if len(input) == 0 {
return ErrInputEmpty
}
var amount uint64
var err error
if assetID == ids.Empty {
amount, err = utils.ParseBalance(input)
} else {
amount, err = strconv.ParseUint(input, 10, 64)
}
amount, err := utils.ParseBalance(input, decimals)
if err != nil {
return err
}
Expand All @@ -128,17 +122,12 @@ func (*Handler) PromptAmount(
return 0, err
}
rawAmount = strings.TrimSpace(rawAmount)
var amount uint64
if assetID == ids.Empty {
amount, err = utils.ParseBalance(rawAmount)
} else {
amount, err = strconv.ParseUint(rawAmount, 10, 64)
}
return amount, err
return utils.ParseBalance(rawAmount, decimals)
}

func (*Handler) PromptInt(
label string,
max int,
) (int, error) {
promptText := promptui.Prompt{
Label: label,
Expand All @@ -153,6 +142,9 @@ func (*Handler) PromptInt(
if amount <= 0 {
return fmt.Errorf("%d must be > 0", amount)
}
if amount > max {
return fmt.Errorf("%d must be <= %d", amount, max)
}
return nil
},
}
Expand Down Expand Up @@ -326,21 +318,6 @@ func (h *Handler) PromptChain(label string, excluded set.Set[ids.ID]) (ids.ID, [
return chainID, chains[chainID], nil
}

func (*Handler) ValueString(assetID ids.ID, value uint64) string {
if assetID == ids.Empty {
return utils.FormatBalance(value)
}
// Custom assets are denoted in raw units
return strconv.FormatUint(value, 10)
}

func (h *Handler) AssetString(assetID ids.ID) string {
if assetID == ids.Empty {
return h.c.Symbol()
}
return assetID.String()
}

func (*Handler) PrintStatus(txID ids.ID, success bool) {
status := "⚠️"
if success {
Expand Down
14 changes: 7 additions & 7 deletions cli/spam.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ func (h *Handler) Spam(
}

// Distribute funds
numAccounts, err := h.PromptInt("number of accounts")
numAccounts, err := h.PromptInt("number of accounts", consts.MaxInt)
if err != nil {
return err
}
numTxsPerAccount, err := h.PromptInt("number of transactions per account per second")
numTxsPerAccount, err := h.PromptInt("number of transactions per account per second", consts.MaxInt)
if err != nil {
return err
}
numClients, err := h.PromptInt("number of clients per node")
numClients, err := h.PromptInt("number of clients per node", consts.MaxInt)
if err != nil {
return err
}
Expand All @@ -139,8 +139,8 @@ func (h *Handler) Spam(
distAmount := (balance - witholding) / uint64(numAccounts)
utils.Outf(
"{{yellow}}distributing funds to each account:{{/}} %s %s\n",
h.ValueString(ids.Empty, distAmount),
h.AssetString(ids.Empty),
utils.FormatBalance(distAmount, h.c.Decimals()),
h.c.Symbol(),
)
accounts := make([]ed25519.PrivateKey, numAccounts)
dcli, err := rpc.NewWebSocketClient(uris[0], rpc.DefaultHandshakeTimeout, pubsub.MaxPendingMessages, pubsub.MaxReadMessageSize) // we write the max read
Expand Down Expand Up @@ -431,8 +431,8 @@ func (h *Handler) Spam(
}
utils.Outf(
"{{yellow}}returned funds:{{/}} %s %s\n",
h.ValueString(ids.Empty, returnedBalance),
h.AssetString(ids.Empty),
utils.FormatBalance(returnedBalance, h.c.Decimals()),
h.c.Symbol(),
)
return nil
}
Expand Down
12 changes: 8 additions & 4 deletions cli/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (h *Handler) StoreDefaultChain(chainID ids.ID) error {
return h.StoreDefault(defaultChainKey, chainID[:])
}

func (h *Handler) GetDefaultChain() (ids.ID, []string, error) {
func (h *Handler) GetDefaultChain(log bool) (ids.ID, []string, error) {
v, err := h.GetDefault(defaultChainKey)
if err != nil {
return ids.Empty, nil, err
Expand All @@ -61,7 +61,9 @@ func (h *Handler) GetDefaultChain() (ids.ID, []string, error) {
if err != nil {
return ids.Empty, nil, err
}
utils.Outf("{{yellow}}chainID:{{/}} %s\n", chainID)
if log {
utils.Outf("{{yellow}}chainID:{{/}} %s\n", chainID)
}
return chainID, uris, nil
}

Expand Down Expand Up @@ -111,7 +113,7 @@ func (h *Handler) StoreDefaultKey(pk ed25519.PublicKey) error {
return h.StoreDefault(defaultKeyKey, pk[:])
}

func (h *Handler) GetDefaultKey() (ed25519.PrivateKey, error) {
func (h *Handler) GetDefaultKey(log bool) (ed25519.PrivateKey, error) {
v, err := h.GetDefault(defaultKeyKey)
if err != nil {
return ed25519.EmptyPrivateKey, err
Expand All @@ -124,7 +126,9 @@ func (h *Handler) GetDefaultKey() (ed25519.PrivateKey, error) {
if err != nil {
return ed25519.EmptyPrivateKey, err
}
utils.Outf("{{yellow}}address:{{/}} %s\n", h.c.Address(publicKey))
if log {
utils.Outf("{{yellow}}address:{{/}} %s\n", h.c.Address(publicKey))
}
return priv, nil
}

Expand Down
4 changes: 4 additions & 0 deletions codec/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func BytesLen(msg []byte) int {
return consts.IntLen + len(msg)
}

func BytesLenSize(msgSize int) int {
return consts.IntLen + msgSize
}

func StringLen(msg string) int {
return consts.IntLen + len(msg)
}
1 change: 1 addition & 0 deletions consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
IDLen = 32
NodeIDLen = 20
IntLen = 4
Uint8Len = 1
Uint16Len = 2
Uint32Len = 4
Uint64Len = 8
Expand Down
1 change: 0 additions & 1 deletion crypto/ed25519/ed25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ func ParseAddress(hrp, saddr string) (PublicKey, error) {
}

// GeneratePrivateKey returns a Ed25519 PrivateKey.
// It uses the crypto/ed25519 go package to generate the key.
func GeneratePrivateKey() (PrivateKey, error) {
_, k, err := ed25519.GenerateKey(nil)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions examples/morpheusvm/cmd/morpheus-cli/cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package cmd
import (
"context"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/hypersdk/examples/morpheusvm/actions"
"github.com/ava-labs/hypersdk/examples/morpheusvm/consts"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -40,7 +40,7 @@ var transferCmd = &cobra.Command{
}

// Select amount
amount, err := handler.Root().PromptAmount("amount", ids.Empty, balance, nil)
amount, err := handler.Root().PromptAmount("amount", consts.Decimals, balance, nil)
if err != nil {
return err
}
Expand Down
10 changes: 7 additions & 3 deletions examples/morpheusvm/cmd/morpheus-cli/cmd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ func (h *Handler) DefaultActor() (
ids.ID, ed25519.PrivateKey, *auth.ED25519Factory,
*rpc.JSONRPCClient, *brpc.JSONRPCClient, error,
) {
priv, err := h.h.GetDefaultKey()
priv, err := h.h.GetDefaultKey(true)
if err != nil {
return ids.Empty, ed25519.EmptyPrivateKey, nil, nil, nil, err
}
chainID, uris, err := h.h.GetDefaultChain()
chainID, uris, err := h.h.GetDefaultChain(true)
if err != nil {
return ids.Empty, ed25519.EmptyPrivateKey, nil, nil, nil, err
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func (*Handler) GetBalance(
}
hutils.Outf(
"{{yellow}}balance:{{/}} %s %s\n",
hutils.FormatBalance(balance),
hutils.FormatBalance(balance, consts.Decimals),
consts.Symbol,
)
return balance, nil
Expand All @@ -99,6 +99,10 @@ func (*Controller) Symbol() string {
return consts.Symbol
}

func (*Controller) Decimals() uint8 {
return consts.Decimals
}

func (*Controller) Address(pk ed25519.PublicKey) string {
return utils.Address(pk)
}
Expand Down
9 changes: 5 additions & 4 deletions examples/morpheusvm/cmd/morpheus-cli/cmd/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/hypersdk/crypto/ed25519"
"github.com/ava-labs/hypersdk/examples/morpheusvm/consts"
brpc "github.com/ava-labs/hypersdk/examples/morpheusvm/rpc"
hutils "github.com/ava-labs/hypersdk/utils"
"github.com/ava-labs/hypersdk/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -47,12 +48,12 @@ func lookupSetKeyBalance(choice int, address string, uri string, networkID uint3
if err != nil {
return err
}
hutils.Outf(
utils.Outf(
"%d) {{cyan}}address:{{/}} %s {{cyan}}balance:{{/}} %s %s\n",
choice,
address,
handler.Root().ValueString(ids.Empty, balance),
handler.Root().AssetString(ids.Empty),
utils.FormatBalance(balance, consts.Decimals),
consts.Symbol,
)
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions examples/morpheusvm/cmd/morpheus-cli/cmd/resolutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func handleTx(tx *chain.Transaction, result *chain.Result) {
status = "✅"
switch action := tx.Action.(type) { //nolint:gocritic
case *actions.Transfer:
summaryStr = fmt.Sprintf("%s %s -> %s", utils.FormatBalance(action.Value), consts.Symbol, tutils.Address(action.To))
summaryStr = fmt.Sprintf("%s %s -> %s", utils.FormatBalance(action.Value, consts.Decimals), consts.Symbol, tutils.Address(action.To))
}
}
utils.Outf(
Expand All @@ -66,8 +66,8 @@ func handleTx(tx *chain.Transaction, result *chain.Result) {
reflect.TypeOf(tx.Action),
summaryStr,
float64(result.Fee)/float64(tx.Base.MaxFee)*100,
handler.Root().ValueString(ids.Empty, result.Fee),
handler.Root().AssetString(ids.Empty),
utils.FormatBalance(result.Fee, consts.Decimals),
consts.Symbol,
cli.ParseDimensions(result.Consumed),
)
}
9 changes: 5 additions & 4 deletions examples/morpheusvm/cmd/morpheus-cli/cmd/spam.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import (
"github.com/ava-labs/hypersdk/crypto/ed25519"
"github.com/ava-labs/hypersdk/examples/morpheusvm/actions"
"github.com/ava-labs/hypersdk/examples/morpheusvm/auth"
"github.com/ava-labs/hypersdk/examples/morpheusvm/consts"
brpc "github.com/ava-labs/hypersdk/examples/morpheusvm/rpc"
"github.com/ava-labs/hypersdk/rpc"
hutils "github.com/ava-labs/hypersdk/utils"
"github.com/ava-labs/hypersdk/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -45,12 +46,12 @@ var runSpamCmd = &cobra.Command{
if err != nil {
return 0, err
}
hutils.Outf(
utils.Outf(
"%d) {{cyan}}address:{{/}} %s {{cyan}}balance:{{/}} %s %s\n",
choice,
address,
handler.Root().ValueString(ids.Empty, balance),
handler.Root().AssetString(ids.Empty),
utils.FormatBalance(balance, consts.Decimals),
consts.Symbol,
)
return balance, err
},
Expand Down
7 changes: 4 additions & 3 deletions examples/morpheusvm/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
)

const (
HRP = "morpheus"
Name = "morpheusvm"
Symbol = "RED"
HRP = "morpheus"
Name = "morpheusvm"
Symbol = "RED"
Decimals = 9
)

var ID ids.ID
Expand Down
2 changes: 1 addition & 1 deletion examples/morpheusvm/rpc/jsonrpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (cli *JSONRPCClient) WaitForBalance(
if !shouldExit {
utils.Outf(
"{{yellow}}waiting for %s balance: %s{{/}}\n",
utils.FormatBalance(min),
utils.FormatBalance(min, consts.Decimals),
addr,
)
}
Expand Down
Loading

0 comments on commit 838307c

Please sign in to comment.