Skip to content

Commit

Permalink
working version again with terminal UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ardan-bkennedy committed Jan 21, 2024
1 parent 1c0e7b8 commit 2b1d32e
Show file tree
Hide file tree
Showing 3,268 changed files with 829,489 additions and 48,082 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion app/cli/liars/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type Args struct {
// the defaults.
func Parse() (Flags, Args, error) {
const (
engine = "http://engine-service.liars-system.svc.cluster.local:3000"
engine = "http://localhost:3000"
accountID = "0x0070742ff6003c3e809e78d524f0fe5dcc5ba7f7"
)

Expand Down
40 changes: 24 additions & 16 deletions app/services/engine/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"syscall"
"time"

"github.com/ethereum/go-ethereum/crypto"

"github.com/ardanlabs/conf/v3"
"github.com/ardanlabs/ethereum"
"github.com/ardanlabs/ethereum/currency"
Expand All @@ -23,9 +21,10 @@ import (
"github.com/ardanlabs/liarsdice/business/core/bank"
"github.com/ardanlabs/liarsdice/business/web/auth"
"github.com/ardanlabs/liarsdice/foundation/events"
"github.com/ardanlabs/liarsdice/foundation/keystore"
"github.com/ardanlabs/liarsdice/foundation/logger"
"github.com/ardanlabs/liarsdice/foundation/vault"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"go.uber.org/automaxprocs/maxprocs"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -98,14 +97,17 @@ func run(log *zap.SugaredLogger) error {
Token string `conf:"default:mytoken,mask"`
}
Auth struct {
ActiveKID string `conf:"default:54bb2165-71e1-41a6-af3e-7da4a0e1e2c1"`
KeysFolder string `conf:"default:zarf/keys/"`
ActiveKID string `conf:"default:54bb2165-71e1-41a6-af3e-7da4a0e1e2c1"`
}
Game struct {
ContractID string `conf:"default:0x0"`
AnteUSD float64 `conf:"default:5"`
ConnectTimeout time.Duration `conf:"default:60s"`
}
Bank struct {
KeysFolder string `conf:"default:zarf/ethereum/keystore/"`
PassPhrase string `conf:"default:123,noprint"`
KeyID string `conf:"default:6327a38415c53ffb36c11db55ea74cc9cb4976fd"`
Network string `conf:"default:http://geth-service.liars-system.svc.cluster.local:8545"`
Timeout time.Duration `conf:"default:10s"`
Expand Down Expand Up @@ -143,22 +145,28 @@ func run(log *zap.SugaredLogger) error {
expvar.NewString("build").Set(build)

// =========================================================================
// Initialize authentication support
// Initialize keystore

log.Infow("startup", "status", "initializing authentication support")
log.Infow("startup", "status", "initializing keystore")

vaultClient, err := vault.New(vault.Config{
Address: cfg.Vault.Address,
Token: cfg.Vault.Token,
MountPath: cfg.Vault.MountPath,
})
if err != nil {
return fmt.Errorf("constructing vaultConfig: %w", err)
ks := keystore.New(log)

if err := ks.LoadAuthKeys(cfg.Auth.KeysFolder); err != nil {
return fmt.Errorf("reading keys: %w", err)
}

if err := ks.LoadBankKeys(cfg.Bank.KeysFolder, cfg.Bank.PassPhrase); err != nil {
return fmt.Errorf("reading keys: %w", err)
}

// =========================================================================
// Initialize authentication support

log.Infow("startup", "status", "initializing authentication support")

authCfg := auth.Config{
Log: log,
KeyLookup: vaultClient,
KeyLookup: ks,
}

authClient, err := auth.New(authCfg)
Expand Down Expand Up @@ -193,12 +201,12 @@ func run(log *zap.SugaredLogger) error {
}
defer backend.Close()

privateKey, err := vaultClient.PrivateKeyPEM(cfg.Bank.KeyID)
privateKeyPEM, err := ks.PrivateKey(cfg.Bank.KeyID)
if err != nil {
return fmt.Errorf("capture private key: %w", err)
}

block, _ := pem.Decode([]byte(privateKey))
block, _ := pem.Decode([]byte(privateKeyPEM))
ecdsaKey, err := crypto.ToECDSA(block.Bytes)
if err != nil {
return fmt.Errorf("error converting PEM to ECDSA: %w", err)
Expand Down
11 changes: 7 additions & 4 deletions app/tooling/admin/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package cmd
import (
"context"
"fmt"
"math/big"
"os"
"time"

"github.com/ardanlabs/ethereum"
"github.com/ardanlabs/ethereum/currency"
scBank "github.com/ardanlabs/liarsdice/business/contract/go/bank"
"github.com/ethereum/go-ethereum/log"
"github.com/spf13/cobra"
"math/big"
"time"
)

// keyCmd represents the key command
Expand Down Expand Up @@ -52,7 +54,7 @@ func deploy(ctx context.Context, converter *currency.Converter, ethClient *ether

const gasLimit = 1700000
const valueGwei = 0.0
tranOpts, err := ethClient.NewTransactOpts(ctx, gasLimit, big.NewFloat(valueGwei))
tranOpts, err := ethClient.NewTransactOpts(ctx, gasLimit, big.NewInt(0), big.NewFloat(valueGwei))
if err != nil {
return err
}
Expand All @@ -74,7 +76,8 @@ func deploy(ctx context.Context, converter *currency.Converter, ethClient *ether

fmt.Println("\nWaiting Logs")
fmt.Println("----------------------------------------------------")
log.Root().SetHandler(log.StdoutHandler)

log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stdout, log.LevelInfo, true)))

receipt, err := ethClient.WaitMined(ctx, tx)
if err != nil {
Expand Down
58 changes: 0 additions & 58 deletions app/tooling/admin/cmd/vault.go

This file was deleted.

167 changes: 0 additions & 167 deletions app/tooling/admin/cmd/vault_addkeys.go

This file was deleted.

Loading

0 comments on commit 2b1d32e

Please sign in to comment.